demandimport error - AttributeError: 'module' object has no attribute 'ModuleType'
Mercurial fails to load the extension:
$ hg --traceback status *** failed to import extension mercurial_keyring: 'module' object has no attribute 'ModuleType' Traceback (most recent call last): File "/usr/lib/python2.7/site-packages/mercurial/extensions.py", line 92, in loadall load(ui, name, path) File "/usr/lib/python2.7/site-packages/mercurial/extensions.py", line 79, in load mod = importh(name) File "/usr/lib/python2.7/site-packages/mercurial/extensions.py", line 69, in importh mod = __import__(name) File "/usr/lib/python2.7/site-packages/mercurial/demandimport.py", line 95, in _demandimport return _import(name, globals, locals, fromlist, level) File "/home/simon/.local/lib/python2.7/site-packages/mercurial_keyring.py", line 61, in <module> import keyring File "/usr/lib/python2.7/site-packages/mercurial/demandimport.py", line 95, in _demandimport return _import(name, globals, locals, fromlist, level) File "/home/simon/.local/lib/python2.7/site-packages/keyring/__init__.py", line 9, in <module> from core import (set_keyring, get_keyring, set_password, get_password, File "/usr/lib/python2.7/site-packages/mercurial/demandimport.py", line 114, in _demandimport mod = _origimport(name, globals, locals) File "/home/simon/.local/lib/python2.7/site-packages/keyring/core.py", line 166, in <module> init_backend() File "/home/simon/.local/lib/python2.7/site-packages/keyring/core.py", line 65, in init_backend keyrings.sort(key = lambda x: -x.supported()) File "/home/simon/.local/lib/python2.7/site-packages/keyring/core.py", line 65, in <lambda> keyrings.sort(key = lambda x: -x.supported()) File "/home/simon/.local/lib/python2.7/site-packages/keyring/backends/Gnome.py", line 15, in supported from gi.repository import GnomeKeyring File "/usr/lib/python2.7/site-packages/mercurial/demandimport.py", line 95, in _demandimport return _import(name, globals, locals, fromlist, level) File "/usr/lib/python2.7/site-packages/gi/repository/__init__.py", line 25, in <module> from ..importer import DynamicImporter File "/usr/lib/python2.7/site-packages/mercurial/demandimport.py", line 112, in _demandimport return _origimport(name, globals, locals, fromlist, level) File "/usr/lib/python2.7/site-packages/gi/importer.py", line 28, in <module> from .module import DynamicModule File "/usr/lib/python2.7/site-packages/mercurial/demandimport.py", line 112, in _demandimport return _origimport(name, globals, locals, fromlist, level) File "/usr/lib/python2.7/site-packages/gi/module.py", line 273, in <module> class DynamicModule(types.ModuleType): File "/usr/lib/python2.7/site-packages/mercurial/demandimport.py", line 87, in __getattribute__ return getattr(self._module, attr) AttributeError: 'module' object has no attribute 'ModuleType'
Fiddling with demandimport.py shows that types
in types.ModuleType
is the gi.types
module instead of the stdlib’s types
. The from __future__ import absolute_import
line in the same file does not seem to take effect.
On the same system, python2 -c 'import mercurial_keyring'
runs without an exception.
I though this would reproduce the issue outside of Mercurial, but it didn’t:
python2 -c 'import mercurial.demandimport as d; d.enable(); import mercurial_keyring'
GObject 3.8.2 Python 2.7.5 Mercurial 2.6.2 mercurial_keyring 0.5.5
Comments (12)
-
-
same here: arch linux python 2.7.5, mercurial 2.6.2, mercurial_keyring 0.5.5
tried python-keyring 1.4 and 1.5 both do not work
-
I really hate this demandimport idea, eh....
With mercurial 2.6.1 on Ubuntu 13.04 things seem to work for me. I wil check whether upgrading let me reproduce the problem.
-
Update:
I have no problem running a Kubuntu 12.04 installation with GObject 3.2.0, Python 2.7.3, Mercurial 2.0.2 and mercurial_keyring 0.5.5
The Ubuntu 13.04 installation above is running GObject 3.8.0
-
The following command reproduces the error on my Ubuntu 13.04 and reports no error on my Kubuntu 12.04:
python2 -c 'import mercurial.demandimport as d; d.enable(); import mercurial_keyring; from mercurial_keyring import PasswordStore'
-
Confirmed on Archlinux, Frederik’s code reproduces the bug.
-
On my Ubuntu 13.04 I don't observe the problem. It may be dependant on some modules installed/uninstalled/...
I just pushed the code which may help (https://bitbucket.org/Mekk/mercurial_keyring/commits/a317abcaeaf3e6eced7efbdbaa1fcff6f4d9dd8c). Could anybody who experiences the problem test the fix and provide info whether it helps? (just grab mercurial_keyring.py from sources, or clone the repo and python setup.py install)
In case it does not help, most likely it requires more items on demandimport ignore list, (maybe "gi.types", maybe "types"). It is not difficult to experiment (and adding too many items won't harm unless they clash with mercurial file names)
-
Hello, tried your fix, but it did not solve the issue. However I added "types" to the ignore list (and removed your additions of "gi.repository" and "gi"). That solved the issue for me.
-
OK, I fixed this this way, will make the release soon.
-
- changed status to resolved
Released as 0.5.6
-
I still get this error, mercurial_keyring 0.6.0
-
- Log in to comment
I have the same issue here. Running Ubuntu 13.04, Python 2.7.4, Mercurial 2.2.2 and mercurial_keyring 0.5.5