[Python-apps-team] Bug#476885: mercurial-common: The inotify import error breaks tailor's git->hg support

Edward Welbourne eddy at opera.com
Mon Jun 9 18:00:05 UTC 2008


Package: mercurial-common
Version: 1.0.1-1
Followup-For: Bug #476885


The initially reported bug can be reduced to: <quote>

Python 2.5.2 (r252:60911, May 28 2008, 08:35:32) 
[GCC 4.2.4 (Debian 4.2.4-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import hgext.inotify
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/var/lib/python-support/python2.5/hgext/inotify/__init__.py", line 16, in <module>
    import client, errno, os, server, socket
  File "/var/lib/python-support/python2.5/hgext/inotify/server.py", line 15, in <module>
    import hgext.inotify.linux as inotify
AttributeError: 'module' object has no attribute 'inotify'

</quote> i.e. hgext's inotify sub-package fails to import, making it
unusable.

This has nothing to do with help per se, although it has the downside
of breaking help (and it's a pity other things do the same).  I met it
because this error also shows up in tailor's broken handling of git ->
hg repository transformation.

The problem is that __init__.py says to import server; but server says
to import linux from inotify (i.e. from __init__) whose import hasn't
yet completed, so hgext doesn't yet have a .inotify attribute on which
to look for a .linux attribute to import as inotify.

However, this can be avoided: the reason __init__.py imports client
and server (they'd appear in the package namespace naturally anyway,
so it's not so as to put them there) is so that serve and reposetup
can use them.  Fortunately, there's a way round that ...

<patch>

diff -bu /usr/share/python-support/mercurial-common/hgext/inotify/__init__.py\~ /usr/share/python-support/mercurial-common/hgext/inotify/__init__.py
--- /usr/share/python-support/mercurial-common/hgext/inotify/__init__.py~	2008-05-22 22:48:40.000000000 +0200
+++ /usr/share/python-support/mercurial-common/hgext/inotify/__init__.py	2008-06-09 19:49:40.000000000 +0200
@@ -13,7 +13,7 @@
 
 from mercurial.i18n import gettext as _
 from mercurial import cmdutil, util
-import client, errno, os, server, socket
+import errno, os, socket
 from weakref import proxy
 
 def serve(ui, repo, **opts):
@@ -23,8 +23,10 @@
         timeout = float(timeout) * 1e3
 
     class service:
-        def init(self):
+        import server
+        def init(self, server=server):
             self.master = server.Master(ui, repo, timeout)
+        del server
 
         def run(self):
             try:
@@ -47,8 +49,9 @@
         # to recurse.
         inotifyserver = False
 
+        import client, server
         def status(self, files, match, list_ignored, list_clean,
-                   list_unknown=True):
+                   list_unknown=True, client=client, server=server):
             try:
                 if not list_ignored and not self.inotifyserver:
                     result = client.query(ui, repo, files, match, False,
@@ -91,6 +94,8 @@
                 files, match or util.always, list_ignored, list_clean,
                 list_unknown)
 
+        del client, server
+
     repo.dirstate.__class__ = inotifydirstate
 
 cmdtable = {

Diff finished.  Mon Jun  9 19:50:09 2008

</patch>

... since client and server are only actually needed when the
functions get called, which happens after the package has been loaded.

-- System Information:
Debian Release: lenny/sid
  APT prefers testing
  APT policy: (500, 'testing'), (500, 'stable')
Architecture: i386 (i686)

Kernel: Linux 2.6.24-1-686 (SMP w/2 CPU cores)
Locale: LANG=en_GB.ISO-8859-15, LC_CTYPE=en_GB.ISO-8859-15 (charmap=ISO-8859-15)
Shell: /bin/sh linked to /bin/bash

Versions of packages mercurial-common depends on:
ii  python                        2.5.2-1    An interactive high-level object-o
ii  python-support                0.8.1      automated rebuilding support for P

Versions of packages mercurial-common recommends:
ii  mercurial                     1.0-4      Scalable distributed version contr

-- no debconf information





More information about the Python-apps-team mailing list