162 # so modern Mercurial code will have level >= 0. |
162 # so modern Mercurial code will have level >= 0. |
163 |
163 |
164 # The name of the module the import statement is located in. |
164 # The name of the module the import statement is located in. |
165 globalname = globals.get('__name__') |
165 globalname = globals.get('__name__') |
166 |
166 |
167 def processfromitem(mod, attr, **kwargs): |
167 def processfromitem(mod, attr): |
168 """Process an imported symbol in the import statement. |
168 """Process an imported symbol in the import statement. |
169 |
169 |
170 If the symbol doesn't exist in the parent module, it must be a |
170 If the symbol doesn't exist in the parent module, it must be a |
171 module. We set missing modules up as _demandmod instances. |
171 module. We set missing modules up as _demandmod instances. |
172 """ |
172 """ |
173 symbol = getattr(mod, attr, nothing) |
173 symbol = getattr(mod, attr, nothing) |
174 if symbol is nothing: |
174 if symbol is nothing: |
175 symbol = _demandmod(attr, mod.__dict__, locals, **kwargs) |
175 symbol = _demandmod(attr, mod.__dict__, locals, level=1) |
176 setattr(mod, attr, symbol) |
176 setattr(mod, attr, symbol) |
177 |
177 |
178 # Record the importing module references this symbol so we can |
178 # Record the importing module references this symbol so we can |
179 # replace the symbol with the actual module instance at load |
179 # replace the symbol with the actual module instance at load |
180 # time. |
180 # time. |
192 fromlist, level) |
192 fromlist, level) |
193 |
193 |
194 mod = _hgextimport(_origimport, name, globals, locals, level=level) |
194 mod = _hgextimport(_origimport, name, globals, locals, level=level) |
195 |
195 |
196 for x in fromlist: |
196 for x in fromlist: |
197 processfromitem(mod, x, level=level) |
197 processfromitem(mod, x) |
198 |
198 |
199 return mod |
199 return mod |
200 |
200 |
201 # But, we still need to support lazy loading of standard library and 3rd |
201 # But, we still need to support lazy loading of standard library and 3rd |
202 # party modules. So handle level == -1. |
202 # party modules. So handle level == -1. |