[PATCH stable draft] py24: fix thg compatibility with python 2.4 and CentOS 5

214 views
Skip to first unread message

Gilles Moris

unread,
Apr 20, 2011, 2:25:06 AM4/20/11
to thg...@googlegroups.com
# HG changeset patch
# User Gilles Moris <gilles...@free.fr>
# Date 1303280263 -7200
# Branch stable
# Node ID a1d82d5eb04047170ef32e7e322024b6b6edef41
# Parent d5cd872f61fde0c1d1b279af4f3b90ff6ade3161
py24: fix thg compatibility with python 2.4 and CentOS 5

First I have replaced control statement that are invalid in py24:
- try ... except ... finally only appears in py25
- yield is forbidden inside a try ... finally

Then the RPM spec file has been modified so that:
- the mandatory --vendor option is a nil operation as it use the same
name as the prefix
- egg-info is not generated on older platform (typically py2.4)

diff -r d5cd872f61fd -r a1d82d5eb040 contrib/tortoisehg.spec
--- a/contrib/tortoisehg.spec Fri Apr 01 13:50:10 2011 -0500
+++ b/contrib/tortoisehg.spec Wed Apr 20 08:17:43 2011 +0200
@@ -67,7 +67,7 @@
install contrib/mergetools.rc $RPM_BUILD_ROOT%{_sysconfdir}/mercurial/hgrc.d/thgmergetools.rc

ln -s tortoisehg/icons/svg/thg_logo.svg %{buildroot}%{_datadir}/pixmaps/%{name}_logo.svg
-desktop-file-install --dir=%{buildroot}%{_datadir}/applications contrib/%{name}.desktop
+desktop-file-install --dir=%{buildroot}%{_datadir}/applications contrib/%{name}.desktop --vendor %{name}

%find_lang %{name}

@@ -80,7 +80,9 @@
%doc COPYING.txt doc/build/html/
%{_bindir}/thg
%{python_sitelib}/tortoisehg/
+%if "%{?pythonver}" > "2.4"
%{python_sitelib}/tortoisehg-*.egg-info
+%endif
%{_datadir}/pixmaps/tortoisehg/
%{_datadir}/pixmaps/%{name}_logo.svg
%{_datadir}/applications/%{name}.desktop
diff -r d5cd872f61fd -r a1d82d5eb040 tortoisehg/hgqt/annotate.py
--- a/tortoisehg/hgqt/annotate.py Fri Apr 01 13:50:10 2011 -0500
+++ b/tortoisehg/hgqt/annotate.py Wed Apr 20 08:17:43 2011 +0200
@@ -344,12 +344,13 @@
assert self.currentThread() != qApp.thread()
self._threadid = self.currentThreadId()
try:
- data = []
- for (fctx, line), _text in self._fctx.annotate(True, True):
- data.append((fctx, line))
- self.data = data
- except KeyboardInterrupt:
- pass
+ try:
+ data = []
+ for (fctx, line), _text in self._fctx.annotate(True, True):
+ data.append((fctx, line))
+ self.data = data
+ except KeyboardInterrupt:
+ pass
finally:
self._threadid = None
del self._fctx
diff -r d5cd872f61fd -r a1d82d5eb040 tortoisehg/hgqt/repotreeitem.py
--- a/tortoisehg/hgqt/repotreeitem.py Fri Apr 01 13:50:10 2011 -0500
+++ b/tortoisehg/hgqt/repotreeitem.py Wed Apr 20 08:17:43 2011 +0200
@@ -210,12 +210,13 @@

def startSettings(self, parent):
try:
- dlg = SettingsDialog(configrepo=True, focus='web.name', parent=parent,
- root=self._root)
- self.ensureRepoLoaded()
- dlg.exec_()
- except error.RepoError:
- pass
+ try:
+ dlg = SettingsDialog(configrepo=True, focus='web.name', parent=parent,
+ root=self._root)
+ self.ensureRepoLoaded()
+ dlg.exec_()
+ except error.RepoError:
+ pass
finally:
dlg.deleteLater()

diff -r d5cd872f61fd -r a1d82d5eb040 tortoisehg/hgqt/run.py
--- a/tortoisehg/hgqt/run.py Fri Apr 01 13:50:10 2011 -0500
+++ b/tortoisehg/hgqt/run.py Wed Apr 20 08:17:43 2011 +0200
@@ -397,12 +397,13 @@
def excepthandler(self):
'Display exception info; run in main (GUI) thread'
try:
- self._showexceptiondialog()
- except:
- # make sure to quit mainloop first, so that it never leave
- # zombie process.
- self._mainapp.exit(1)
- self._printexception()
+ try:
+ self._showexceptiondialog()
+ except:
+ # make sure to quit mainloop first, so that it never leave
+ # zombie process.
+ self._mainapp.exit(1)
+ self._printexception()
finally:
self.errors = []

diff -r d5cd872f61fd -r a1d82d5eb040 tortoisehg/hgqt/serve.py
--- a/tortoisehg/hgqt/serve.py Fri Apr 01 13:50:10 2011 -0500
+++ b/tortoisehg/hgqt/serve.py Wed Apr 20 08:17:43 2011 +0200
@@ -133,11 +133,12 @@
origtimeout = socket.getdefaulttimeout()
socket.setdefaulttimeout(TIMEOUT)
try:
- conn.request('GET', '/')
- res = conn.getresponse()
- res.read()
- except (socket.error, httplib.HTTPException):
- pass
+ try:
+ conn.request('GET', '/')
+ res = conn.getresponse()
+ res.read()
+ except (socket.error, httplib.HTTPException):
+ pass
finally:
socket.setdefaulttimeout(origtimeout)
conn.close()
diff -r d5cd872f61fd -r a1d82d5eb040 tortoisehg/hgqt/sync.py
--- a/tortoisehg/hgqt/sync.py Fri Apr 01 13:50:10 2011 -0500
+++ b/tortoisehg/hgqt/sync.py Wed Apr 20 08:17:43 2011 +0200
@@ -506,11 +506,12 @@
if shell:
cwd = os.getcwd()
try:
- os.chdir(folder)
- QProcess.startDetached(shell)
- except EnvironmentError, e:
- qtlib.InfoMsgBox(_('Repository not found'),
- hglib.tounicode(str(e)))
+ try:
+ os.chdir(folder)
+ QProcess.startDetached(shell)
+ except EnvironmentError, e:
+ qtlib.InfoMsgBox(_('Repository not found'),
+ hglib.tounicode(str(e)))
finally:
os.chdir(cwd)
else:
diff -r d5cd872f61fd -r a1d82d5eb040 tortoisehg/hgqt/thgrepo.py
--- a/tortoisehg/hgqt/thgrepo.py Fri Apr 01 13:50:10 2011 -0500
+++ b/tortoisehg/hgqt/thgrepo.py Wed Apr 20 08:17:43 2011 +0200
@@ -611,5 +611,8 @@
for e in repotreemodel.iterRepoItemFromXml(f):
if e.basenode() == repoid:
yield e.rootpath(), e.shortname()
- finally:
+ except:
f.close()
+ raise
+ else:
+ f.close()

Steve Borho

unread,
Apr 20, 2011, 12:19:00 PM4/20/11
to thg...@googlegroups.com
On Wed, Apr 20, 2011 at 1:25 AM, Gilles Moris <gilles...@free.fr> wrote:
> # HG changeset patch
> # User Gilles Moris <gilles...@free.fr>
> # Date 1303280263 -7200
> # Branch stable
> # Node ID a1d82d5eb04047170ef32e7e322024b6b6edef41
> # Parent  d5cd872f61fde0c1d1b279af4f3b90ff6ade3161
> py24: fix thg compatibility with python 2.4 and CentOS 5
>
> First I have replaced control statement that are invalid in py24:
> - try ... except ... finally only appears in py25
> - yield is forbidden inside a try ... finally
>
> Then the RPM spec file has been modified so that:
> - the mandatory --vendor option is a nil operation as it use the same
>  name as the prefix
> - egg-info is not generated on older platform (typically py2.4)

Looks good, pushed to stable. Care to give the default branch a quick
test to see if there are any remaining problems there?

--
Steve Borho

Gilles Moris

unread,
Apr 21, 2011, 2:42:37 AM4/21/11
to thg...@googlegroups.com
On default, it seems to work except I've got this traceback:

{{{
#!python
** Mercurial version (1.8.2).  TortoiseHg version (2.0.3+159-87fbc0d06adf)
** Command:
** CWD: /root/tortoisebuild/thg
** Extensions loaded: purge, mq, patchbomb
** Python version: 2.4.3 (#1, Mar  5 2011, 21:26:05) [GCC 4.1.2 20080704 (Red Hat 4.1.2-50)]
** Qt-4.7.2 PyQt-4.8.3
Traceback (most recent call last):
  File "/root/tortoisebuild/thg/tortoisehg/hgqt/run.py", line 49, in dispatch
    return _runcatch(u, args)
  File "/root/tortoisebuild/thg/tortoisehg/hgqt/run.py", line 235, in _runcatch
    return runcommand(ui, args)
  File "/root/tortoisebuild/thg/tortoisehg/hgqt/run.py", line 305, in runcommand
    return _runcommand(lui, options, cmd, d)
  File "/root/tortoisebuild/thg/tortoisehg/hgqt/run.py", line 356, in _runcommand
    return checkargs()
  File "/root/tortoisebuild/thg/tortoisehg/hgqt/run.py", line 310, in checkargs
    return cmdfunc()
  File "/root/tortoisebuild/thg/tortoisehg/hgqt/run.py", line 304, in <lambda>
    d = lambda: util.checksignature(func)(ui, *args, **cmdoptions)
  File "/usr/lib64/python2.4/site-packages/mercurial/util.py", line 433, in check
    return func(*args, **kwargs)
  File "/root/tortoisebuild/thg/tortoisehg/hgqt/run.py", line 678, in log
    return qtrun(run, ui, *pats, **opts)
  File "/root/tortoisebuild/thg/tortoisehg/hgqt/run.py", line 452, in __call__
    portable_fork(ui, opts)
  File "/root/tortoisebuild/thg/tortoisehg/hgqt/run.py", line 99, in portable_fork
    sys.exit(0)
SystemExit: 0

}}}

Any way, the workbench opens up.
Started locally with
% ./thg

No traceback if I'm starting with:
% ./thg --nofork


Regards.
Gilles.

Gilles Moris

unread,
Apr 21, 2011, 3:02:03 AM4/21/11
to thg...@googlegroups.com

By the way many revisions have this message:
'ascii' codec can't decode character u'\u2026' in position xxx: ordinal not in range(128)

See also the attached screen shot from the thg repo.
Looking at the export does not show any non ascii character:
% hg export 5a8c15e64db452a13a24e19290a55496a0a998a8 | od -c -Ad
0000000   #       H   G       c   h   a   n   g   e   s   e   t       p
0000016   a   t   c   h  \n   #       U   s   e   r       p   a   t   r
0000032   i   c   e   .   l   a   c   o   u   t   u   r   e   @   g   m
0000048   a   i   l   .   c   o   m  \n   #       D   a   t   e       1
0000064   3   0   2   9   8   7   0   3   4       -   7   2   0   0  \n
0000080   #       N   o   d   e       I   D       5   a   8   c   1   5
0000096   e   6   4   d   b   4   5   2   a   1   3   a   2   4   e   1
0000112   9   2   9   0   a   5   5   4   9   6   a   0   a   9   9   8
0000128   a   8  \n   #       P   a   r   e   n   t           f   d   7
0000144   e   0   0   5   4   9   6   6   9   b   0   3   e   c   1   a
0000160   6   9   b   5   1   e   4   b   4   a   1   4   4   2   4   1
0000176   3   1   0   e   f  \n   r   e   v   d   e   t   a   i   l   s
0000192   :       a   l   w   a   y   s       s   h   o   w       s   e
0000208   l   e   c   t   e   d       f   i   l   e       i   n       n
0000224   a   v   i   g   a   t   e       d   i   a   l   o   g  \n  \n
0000240   W   i   t   h       m   u   l   t   i   p   l   e       f   i
0000256   l   e       s   e   l   e   c   t   i   o   n   ,       i   t
0000272   '   s       p   o   s   s   i   b   l   e       t   o       h
0000288   a   v   e       a       D   E   S   E   L   E   C   T   E   D
0000304       c   u   r   r   e   n   t  \n   i   t   e   m   !       O
0000320   p   e   n   i   n   g       n   a   v   i   g   a   t   e   
0000336   d   i   a   l   o   g       f   o   r       t   h   e       c
0000352   u   r   r   e   n   t       i   t   e   m       i   s       c
0000368   o   n   f   u   s   i   n   g       b   e   c   a   u   s   e
0000384       o   t   h   e   r  \n   a   c   t   i   o   n   s       o
0000400   p   e   r   a   t   e       o   n       t   h   e       s   e
0000416   l   e   c   t   e   d       i   t   e   m   s       r   e   g
0000432   a   r   d   l   e   s   s       t   h   e       c   u   r   r
0000448   e   n   t       i   t   e   m   .       T   h   i   s       p
0000464   a   t   c   h  \n   a   l   i   g   n   s       t   h   e   
0000480   F   i   l   e       H   i   s   t   o   r   y       a   n   d
0000496       C   o   m   p   a   r   e       f   i   l   e       r   e
0000512   v   i   s   i   o   n   s       a   c   t   i   o   n   s   
0000528   w   i   t   h       t   h   e       o   t   h   e   r  \n   m
0000544   e   n   u       e   n   t   r   i   e   s       b   e   h   a
0000560   v   i   o   u   r   .  \n  \n   d   i   f   f       -   r   
0000576   f   d   7   e   0   0   5   4   9   6   6   9       -   r   
0000592   5   a   8   c   1   5   e   6   4   d   b   4       t   o   r
0000608   t   o   i   s   e   h   g   /   h   g   q   t   /   r   e   v
0000624   d   e   t   a   i   l   s   .   p   y  \n   -   -   -       a
0000640   /   t   o   r   t   o   i   s   e   h   g   /   h   g   q   t
0000656   /   r   e   v   d   e   t   a   i   l   s   .   p   y  \t   S
0000672   a   t       A   p   r       1   6       2   2   :   3   5   :
0000688   4   9       2   0   1   1       +   0   2   0   0  \n   +   +
0000704   +       b   /   t   o   r   t   o   i   s   e   h   g   /   h
0000720   g   q   t   /   r   e   v   d   e   t   a   i   l   s   .   p
0000736   y  \t   S   a   t       A   p   r       1   6       2   2   :
0000752   5   0   :   3   4       2   0   1   1       +   0   2   0   0
0000768  \n   @   @       -   3   4   2   ,   7       +   3   4   2   ,
0000784   7       @   @  \n      \n                       d   e   f   
0000800   _   n   a   v   i   g   a   t   e   (   s   e   l   f   ,   
0000816   f   i   l   e   n   a   m   e   ,       d   l   g   c   l   a
0000832   s   s   ,       d   l   g   d   i   c   t   )   :  \n       
0000848                               i   f       n   o   t       f   i
0000864   l   e   n   a   m   e   :  \n   -                           
0000880                       f   i   l   e   n   a   m   e       =   
0000896   s   e   l   f   .   f   i   l   e   l   i   s   t   .   c   u
0000912   r   r   e   n   t   F   i   l   e   (   )  \n   +           
0000928                                       f   i   l   e   n   a   m
0000944   e       =       s   e   l   f   .   f   i   l   e   l   i   s
0000960   t   .   g   e   t   S   e   l   e   c   t   e   d   F   i   l
0000976   e   s   (   )   [   0   ]  \n                               
0000992       i   f       f   i   l   e   n   a   m   e       i   s   
0001008   n   o   t       N   o   n   e       a   n   d       l   e   n
0001024   (   s   e   l   f   .   r   e   p   o   .   f   i   l   e   (
0001040   f   i   l   e   n   a   m   e   )   )   >   0   :  \n       
0001056                                               i   f       f   i
0001072   l   e   n   a   m   e       n   o   t       i   n       d   l
0001088   g   d   i   c   t   :  \n                                   
0001104                                   d   l   g       =       d   l
0001120   g   c   l   a   s   s   (   s   e   l   f   .   r   e   p   o
0001136   ,       f   i   l   e   n   a   m   e   ,  \n
0001148

% echo $LANG
en_US.UTF-8
But same thing with LANG=C though.

Any idea what goes wrong ?

Regards.
Gilles.
Screenshot-thg - TortoiseHg Workbench.png

Steve Borho

unread,
Apr 21, 2011, 11:04:06 AM4/21/11
to thg...@googlegroups.com

Does this patch to thg resolve it?

@@ -68,5 +68,8 @@
qtrun(run, ui, **opts)
sys.exit(1)

-ret = tortoisehg.hgqt.run.dispatch(sys.argv[1:])
+try:
+ ret = tortoisehg.hgqt.run.dispatch(sys.argv[1:])
+except SystemExit, e:
+ ret = e.code
sys.exit(ret)


--
Steve Borho

Steve Borho

unread,
Apr 21, 2011, 11:12:29 AM4/21/11
to thg...@googlegroups.com

That's the ellipsis added by the longsummary() method in thgrepo.py

But I have no idea why it's causing that problem. You may have to add
some debugging to repomodel to figure out where the exception is
coming from (see the rawdata() method)

--
Steve Borho

Gilles Moris

unread,
Apr 21, 2011, 4:44:25 PM4/21/11
to thg...@googlegroups.com
Nope, the traceback popup still apears, so I suspect the issue is a little deeper in the stack, otherwise it would have displayed on the console.

Regards.
Gilles.

Steve Borho

unread,
Apr 21, 2011, 4:59:22 PM4/21/11
to thg...@googlegroups.com

Yeah, I saw in the docs that in 2.5 that exception was changed to
derive from a different base exception. So with 2.4 it is being
picked up in our generic exception handler in run.py. I'll see if I
can make a better patch.

--
Steve Borho

Gilles Moris

unread,
Apr 22, 2011, 2:33:47 AM4/22/11
to thg...@googlegroups.com

On Thu, Apr 21, 2011 at 5:12 PM, Steve Borho <st...@borho.org> wrote:

That's the ellipsis added by the longsummary() method in thgrepo.py

But I have no idea why it's causing that problem.  You may have to add
some debugging to repomodel to figure out where the exception is
coming from (see the rawdata() method)

--
Steve Borho

I think I mostly understand the problem. The returned string in the markup function of qtlib.py is not promoted to unicode as it should. It does not seem to detect that the msg QString returns unicode. I don't know if this is strictly linked to Py24 or to my build of PyQt. May be Py24, as I know that the string class hierarchy might be different.

Python 2.4.3 (#1, Mar  5 2011, 21:26:05)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-50)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> print 'this is an ellipsis: "%s"' % u'\u2026'
this is an ellipsis: "…"
>>> import PyQt4.QtCore
>>> print 'this is an ellipsis: "%s"' % PyQt4.QtCore.QString(u'\u2026')

Traceback (most recent call last):
  File "<stdin>", line 1, in ?
UnicodeEncodeError: 'ascii' codec can't encode character u'\u2026' in position 0: ordinal not in range(128)

This works on a Scientific Linux 6 with Python 2.6.

So I propose:


# HG changeset patch
# User Gilles Moris <gilles...@free.fr>
# Date 1303453596 -7200
# Node ID faf2f027c28a3c6bd5691bf9d133a36ea94b984c
# Parent  87fbc0d06adf86f5a1cc2ac46bbd6e5fced11b18
qtlib: force unicode for the markup strings

diff -r 87fbc0d06adf -r faf2f027c28a tortoisehg/hgqt/qtlib.py
--- a/tortoisehg/hgqt/qtlib.py  Wed Apr 20 22:47:48 2011 -0500
+++ b/tortoisehg/hgqt/qtlib.py  Fri Apr 22 08:26:36 2011 +0200
@@ -291,7 +291,7 @@
     msg = hglib.tounicode(msg)
     msg = Qt.escape(msg)
     msg = msg.replace('\n', '<br />')
-    return '<span style="%s">%s</span>' % (style, msg)
+    return u'<span style="%s">%s</span>' % (style, msg)
 
 def descriptionhtmlizer(ui):
     """Return a function to mark up ctx.description() as an HTML


Regards.
Gilles.


Gilles Moris

unread,
Apr 22, 2011, 5:18:05 PM4/22/11
to thg...@googlegroups.com

On Fri, Apr 22, 2011 at 8:33 AM, Gilles Moris <gilles...@gmail.com> wrote:

# HG changeset patch
# User Gilles Moris <gilles...@free.fr>
# Date 1303453596 -7200
# Node ID faf2f027c28a3c6bd5691bf9d133a36ea94b984c
# Parent  87fbc0d06adf86f5a1cc2ac46bbd6e5fced11b18
qtlib: force unicode for the markup strings

diff -r 87fbc0d06adf -r faf2f027c28a tortoisehg/hgqt/qtlib.py
--- a/tortoisehg/hgqt/qtlib.py  Wed Apr 20 22:47:48 2011 -0500
+++ b/tortoisehg/hgqt/qtlib.py  Fri Apr 22 08:26:36 2011 +0200
@@ -291,7 +291,7 @@
     msg = hglib.tounicode(msg)
     msg = Qt.escape(msg)
     msg = msg.replace('\n', '<br />')
-    return '<span style="%s">%s</span>' % (style, msg)
+    return u'<span style="%s">%s</span>' % (style, msg)
 
 def descriptionhtmlizer(ui):
     """Return a function to mark up ctx.description() as an HTML


Regards.
Gilles.



Thanks for applying the patch, Steve.
Can I push it a little further to have it applied on stable as well for the next 2.0.4 ?

Thanks.
Gilles.

Steve Borho

unread,
Apr 22, 2011, 5:23:27 PM4/22/11
to thg...@googlegroups.com

Sure, done.

--
Steve Borho

Gilles Moris

unread,
Apr 22, 2011, 5:29:09 PM4/22/11
to thg...@googlegroups.com
Thanks. Now works like a charm on CentOS 5.6.
I'll try to post how I've installed the packages.

Regards.
Gilles.
Reply all
Reply to author
Forward
0 new messages