##// END OF EJS Templates
demandimport: add support for PyPy...
Bryan O'Sullivan -
r27536:f7d890bc default
parent child Browse files
Show More
@@ -133,6 +133,8 b' class _demandmod(object):'
133 self._load()
133 self._load()
134 setattr(self._module, attr, val)
134 setattr(self._module, attr, val)
135
135
136 _pypy = '__pypy__' in sys.builtin_module_names
137
136 def _demandimport(name, globals=None, locals=None, fromlist=None, level=level):
138 def _demandimport(name, globals=None, locals=None, fromlist=None, level=level):
137 if not locals or name in ignore or fromlist == ('*',):
139 if not locals or name in ignore or fromlist == ('*',):
138 # these cases we can't really delay
140 # these cases we can't really delay
@@ -191,7 +193,21 b' def _demandimport(name, globals=None, lo'
191 return _hgextimport(_origimport, name, globals, locals,
193 return _hgextimport(_origimport, name, globals, locals,
192 fromlist, level)
194 fromlist, level)
193
195
194 mod = _hgextimport(_origimport, name, globals, locals, level=level)
196 if _pypy:
197 # PyPy's __import__ throws an exception if invoked
198 # with an empty name and no fromlist. Recreate the
199 # desired behaviour by hand.
200 mn = globalname
201 mod = sys.modules[mn]
202 if getattr(mod, '__path__', nothing) is nothing:
203 mn = mn.rsplit('.', 1)[0]
204 mod = sys.modules[mn]
205 if level > 1:
206 mn = mn.rsplit('.', level - 1)[0]
207 mod = sys.modules[mn]
208 else:
209 mod = _hgextimport(_origimport, name, globals, locals,
210 level=level)
195
211
196 for x in fromlist:
212 for x in fromlist:
197 processfromitem(mod, x)
213 processfromitem(mod, x)
@@ -245,10 +261,6 b' def isenabled():'
245
261
246 def enable():
262 def enable():
247 "enable global demand-loading of modules"
263 "enable global demand-loading of modules"
248 # PyPy doesn't work with demand import.
249 if '__pypy__' in sys.builtin_module_names:
250 return
251
252 if os.environ.get('HGDEMANDIMPORT') != 'disable':
264 if os.environ.get('HGDEMANDIMPORT') != 'disable':
253 builtins.__import__ = _demandimport
265 builtins.__import__ = _demandimport
254
266
General Comments 0
You need to be logged in to leave comments. Login now