Mercurial > hg
comparison mercurial/demandimport.py @ 25936:f90bb2002bcf
demandimport: support keyword arguments on _hgextimport
__import__ supports keyword arguments since Python 2.5. This
proxy should too.
An upcoming patch will use this feature.
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Sat, 08 Aug 2015 17:07:34 -0700 |
parents | 49dd4fd3f283 |
children | 4f1144c3c72b |
comparison
equal
deleted
inserted
replaced
25935:49dd4fd3f283 | 25936:f90bb2002bcf |
---|---|
41 level = -1 | 41 level = -1 |
42 if sys.version_info[0] >= 3: | 42 if sys.version_info[0] >= 3: |
43 level = 0 | 43 level = 0 |
44 _import = _origimport | 44 _import = _origimport |
45 | 45 |
46 def _hgextimport(importfunc, name, globals, *args): | 46 def _hgextimport(importfunc, name, globals, *args, **kwargs): |
47 try: | 47 try: |
48 return importfunc(name, globals, *args) | 48 return importfunc(name, globals, *args, **kwargs) |
49 except ImportError: | 49 except ImportError: |
50 if not globals: | 50 if not globals: |
51 raise | 51 raise |
52 # extensions are loaded with "hgext_" prefix | 52 # extensions are loaded with "hgext_" prefix |
53 hgextname = 'hgext_%s' % name | 53 hgextname = 'hgext_%s' % name |
54 nameroot = hgextname.split('.', 1)[0] | 54 nameroot = hgextname.split('.', 1)[0] |
55 contextroot = globals.get('__name__', '').split('.', 1)[0] | 55 contextroot = globals.get('__name__', '').split('.', 1)[0] |
56 if nameroot != contextroot: | 56 if nameroot != contextroot: |
57 raise | 57 raise |
58 # retry to import with "hgext_" prefix | 58 # retry to import with "hgext_" prefix |
59 return importfunc(hgextname, globals, *args) | 59 return importfunc(hgextname, globals, *args, **kwargs) |
60 | 60 |
61 class _demandmod(object): | 61 class _demandmod(object): |
62 """module demand-loader and proxy""" | 62 """module demand-loader and proxy""" |
63 def __init__(self, name, globals, locals, level=level): | 63 def __init__(self, name, globals, locals, level=level): |
64 if '.' in name: | 64 if '.' in name: |