Commit Graph

35 Commits

Author SHA1 Message Date
Simon Heimberg
ef1c701e57 demandimport: determine at load time if __import__ has level argument 2011-08-22 22:50:52 +02:00
Augie Fackler
5a1e206eb8 demandimport: use getattr instead of hasattr
We don't use util.safehasattr() here to avoid adding new dependencies
for demandimport. This change may expose previously-silenced
deprecation warnings to appear, as hasattr silently hides warnings
that occur during module import when using demandimport.
2011-07-25 21:15:48 -05:00
Augie Fackler
f8078839f5 demandimport: blacklist rfc822 and mimetools to prevent spurious warnings 2011-03-01 23:35:22 -06:00
Dan Villiom Podlaski Christiansen
312fdcf8d8 demandimport: change default for level from None to -1
The Python default for this function is -1, indicating both relative
and absolute imports should be used.[1] Previously, we relied on the
Python VM not passing level when such semantics were
requisted. This is not the case for PyPy, however, where a level of -1
is always passed to __import__.

[1] <http://docs.python.org/library/functions.html#__import__>
2010-12-01 21:46:08 +01:00
Martin Geisler
9d82b9ed1f check-code: using and/or/not as a function is bad style 2010-11-11 00:08:09 +01:00
Matt Mackall
627b247624 demandimport: back out ccffe6051751 (issue2467) 2010-10-30 11:32:04 -05:00
Steve Borho
0ef8d80996 demandimport: backout 907b6ae6f918
Using a keyword argument here breaks zipimporter for at least some
versions of Python2.6 on Windows.
2010-10-21 10:13:03 -05:00
Dan Villiom Podlaski Christiansen
4b3349db92 demandimport: fix an obscure corner-case.
Python's __import__() function has 'level' as the fourth argument, not the
third. The code path in question probably never worked.

(This was seen trying to run Mercurial in PyPy. Fixing this made it
die somewhere else...)
2010-09-14 23:00:39 +02:00
Dan Villiom Podlaski Christiansen
d8105bddb7 demandimport: store level argument on _demandmod instances
The 'level' argument to __import__ was added in Python 2.6, and is
specified for either relative or absolute imports. The fix introduced
in 5b0fda8ff209 allowed such imports to proceed without failure, but
effectively disabled demandimport for them. This is particularly
unfortunate in Python 3.x, where *all* imports are either relative or
absolute.

The solution introduced here is to store the level argument on the
demandimport instance, and propagate it to _origimport() when its
value isn't None.

Please note that this patch hasn't been tested in Python 3.x, and thus
may not be complete. I'm worried about how sub-imports are handled; I
don't know what they are, or whether the level argument should be
modified for them. I've added 'TODO' notes to these cases; hopefully,
someone more knowledgable of these issues will deal with them.
2010-08-17 17:46:10 +02:00
Dirkjan Ochtman
8ea7020d75 demandimport: blacklist _ssl (issue1964) 2010-03-09 16:03:57 +01:00
Greg Ward
b0b25f04a1 demandimport: add __main__ to the blacklist (because of setuptools) 2010-01-20 20:23:36 -05:00
Matt Mackall
595d66f424 Update license to GPLv2+ 2010-01-19 22:20:08 -06:00
Dirkjan Ochtman
8fec18223e demandimport: ignore _winreg (used in python-2.7 mimetypes) 2010-01-13 11:57:32 +01:00
Steve Borho
136a6eb1d4 demandimport: blacklist gtk
Demandimport breaks gtk.  You get a meaningless error about
'failed loading gobject\_gobject.pyd'.  Mercurial does not use gtk,
but this trips up many extension writers.
2009-09-17 17:39:43 -05:00
Dan Villiom Podlaski Christiansen
68ad384d38 dispatch: also pass level argument to __import__ for ignored modules
I wanted to check if mercurial.demandimport could speed up the loading of
PyObjC, and ran into this: the level argument for __import__, available in
Python 2.5 and later, is silently dropped when doing an 'import *'. I have no
idea what these arguments mean, but this minor change made it work.

(Oh, and because of that 'from ... import *', PyObjC still took about 2s...)
2009-08-05 17:19:37 +02:00
Martin Geisler
750183bdad updated license to be explicit about GPL version 2 2009-04-26 01:08:54 +02:00
Steve Borho
1495d07855 demandimport: blacklist pythoncom
win32com.shell would segfault at import time if pythoncom
was demand loaded.
2009-03-09 21:00:37 -05:00
Dirkjan Ochtman
309bdac20d demandimport: patch __builtin__ instead of __builtins__
This helps on implementations other than CPython, where __builtins__ isn't
necessarily defined (as it's an implementation detail for CPython).
2009-02-05 17:40:25 +01:00
Ali Gholami Rudi
bdaf736fbc demandimport: handling new relative imports
Mercurial does not work on python2.6 because __import__ takes an
additional argument called level.  This patch merely calls the
built-in __import__ when level is passed.
2008-01-16 19:14:54 +03:30
Matt Mackall
f200ad645a demandload: give better diagnostic for call of an unloaded module 2007-12-10 10:24:47 -06:00
Patrick Mezard
38b7c18bab demandimport: ignore resource module, not available under Windows. 2007-08-14 16:03:15 +02:00
Patrick Mezard
e7663b6ff8 demandimport: ignore pwd and grp.
Both are unavailable under Windows and tarfile detects them via ImportError.
2007-08-13 19:42:52 +02:00
Thomas Arendsen Hein
4d29c6dc8e Updated copyright notices and add "and others" to "hg version" 2007-06-19 08:51:34 +02:00
Matt Mackall
ab72eb680f demandimport: fix issue579 and add a test
fix suggested by Brendan
2007-06-18 19:43:26 -05:00
Lee Cantey
416c20c0e1 Fix for demandimport.py and Windows compiled version.
From Shun-ichi Goto in BTS issue 457 http://www.selenic.com/mercurial/bts/msg2780
2007-06-18 15:03:55 -07:00
Brendan Cully
464fa9a95b Add _xmlplus to the demandimport blacklist. (HGCIA was failing to load.) 2007-03-03 18:59:54 -08:00
Matt Mackall
4aa5ee68ce Add some modules to the demandimport ignore list for Windows 2006-12-17 22:16:57 -06:00
Brendan Cully
eab04761d3 demandimport: blacklist _hashlib again (imported in ImportError try block) 2006-12-17 18:45:46 -08:00
Brendan Cully
99bac46845 demandimport: handle already-loaded nested modules in subload 2006-12-17 18:34:42 -08:00
Matt Mackall
aa18646078 demandimport: fix import x.y.z as a when x.y is already imported. 2006-12-17 14:56:12 -06:00
Brendan Cully
6f4a09d3f4 Make demandimport pass all tests on python2.5. 2006-12-15 20:16:20 -08:00
Brendan Cully
8934db36d1 Merge with main 2006-12-15 11:14:55 -08:00
Matt Mackall
ec6238db65 demandimport: ignore _hashlib and email.mime
This makes things work with Python2.5. A better fix would be to fix
demandload to use __getattribute__ to be more transparent.
2006-12-15 12:38:18 -06:00
Benoit Boissinot
4bf7b440fe use parent.__setattr__ instead of __dict__ 2006-12-14 23:51:41 +01:00
Matt Mackall
f17a4e1934 Replace demandload with new demandimport 2006-12-13 13:27:09 -06:00