Show More
@@ -227,10 +227,14 b' def _demandimport(name, globals=None, lo' | |||||
227 | # recurse down the module chain, and return the leaf module |
|
227 | # recurse down the module chain, and return the leaf module | |
228 | mod = rootmod |
|
228 | mod = rootmod | |
229 | for comp in modname.split('.')[1:]: |
|
229 | for comp in modname.split('.')[1:]: | |
230 |
|
|
230 | obj = getattr(mod, comp, nothing) | |
231 | setattr(mod, comp, _demandmod(comp, mod.__dict__, |
|
231 | if obj is nothing: | |
232 |
|
|
232 | obj = _demandmod(comp, mod.__dict__, mod.__dict__, level=1) | |
233 |
|
|
233 | setattr(mod, comp, obj) | |
|
234 | elif mod.__name__ + '.' + comp in sys.modules: | |||
|
235 | # prefer loaded module over attribute (issue5617) | |||
|
236 | obj = sys.modules[mod.__name__ + '.' + comp] | |||
|
237 | mod = obj | |||
234 | return mod |
|
238 | return mod | |
235 |
|
239 | |||
236 | if level >= 0: |
|
240 | if level >= 0: |
@@ -337,6 +337,23 b' importing with "absolute_import" feature' | |||||
337 | > from .legacy import detail as legacydetail |
|
337 | > from .legacy import detail as legacydetail | |
338 | > EOF |
|
338 | > EOF | |
339 |
|
339 | |||
|
340 | Setup package that re-exports an attribute of its submodule as the same | |||
|
341 | name. This leaves 'shadowing.used' pointing to 'used.detail', but still | |||
|
342 | the submodule 'used' should be somehow accessible. (issue5617) | |||
|
343 | ||||
|
344 | $ mkdir -p $TESTTMP/extlibroot/shadowing | |||
|
345 | $ cat > $TESTTMP/extlibroot/shadowing/used.py <<EOF | |||
|
346 | > detail = "this is extlibroot.shadowing.used" | |||
|
347 | > EOF | |||
|
348 | $ cat > $TESTTMP/extlibroot/shadowing/proxied.py <<EOF | |||
|
349 | > from __future__ import absolute_import | |||
|
350 | > from extlibroot.shadowing.used import detail | |||
|
351 | > EOF | |||
|
352 | $ cat > $TESTTMP/extlibroot/shadowing/__init__.py <<EOF | |||
|
353 | > from __future__ import absolute_import | |||
|
354 | > from .used import detail as used | |||
|
355 | > EOF | |||
|
356 | ||||
340 | Setup extension local modules to be imported with "absolute_import" |
|
357 | Setup extension local modules to be imported with "absolute_import" | |
341 | feature. |
|
358 | feature. | |
342 |
|
359 | |||
@@ -429,6 +446,7 b' Setup main procedure of extension.' | |||||
429 | > from extlibroot.lsub1.lsub2 import used as lused, unused as lunused |
|
446 | > from extlibroot.lsub1.lsub2 import used as lused, unused as lunused | |
430 | > from extlibroot.lsub1.lsub2.called import func as lfunc |
|
447 | > from extlibroot.lsub1.lsub2.called import func as lfunc | |
431 | > from extlibroot.recursedown import absdetail, legacydetail |
|
448 | > from extlibroot.recursedown import absdetail, legacydetail | |
|
449 | > from extlibroot.shadowing import proxied | |||
432 | > |
|
450 | > | |
433 | > def uisetup(ui): |
|
451 | > def uisetup(ui): | |
434 | > result = [] |
|
452 | > result = [] | |
@@ -436,6 +454,7 b' Setup main procedure of extension.' | |||||
436 | > result.append(lfunc()) |
|
454 | > result.append(lfunc()) | |
437 | > result.append(absdetail) |
|
455 | > result.append(absdetail) | |
438 | > result.append(legacydetail) |
|
456 | > result.append(legacydetail) | |
|
457 | > result.append(proxied.detail) | |||
439 | > ui.write('LIB: %s\n' % '\nLIB: '.join(result)) |
|
458 | > ui.write('LIB: %s\n' % '\nLIB: '.join(result)) | |
440 | > EOF |
|
459 | > EOF | |
441 |
|
460 | |||
@@ -446,6 +465,7 b' Examine module importing.' | |||||
446 | LIB: this is extlibroot.lsub1.lsub2.called.func() |
|
465 | LIB: this is extlibroot.lsub1.lsub2.called.func() | |
447 | LIB: this is extlibroot.recursedown.abs.used |
|
466 | LIB: this is extlibroot.recursedown.abs.used | |
448 | LIB: this is extlibroot.recursedown.legacy.used |
|
467 | LIB: this is extlibroot.recursedown.legacy.used | |
|
468 | LIB: this is extlibroot.shadowing.used | |||
449 | ABS: this is absextroot.xsub1.xsub2.used |
|
469 | ABS: this is absextroot.xsub1.xsub2.used | |
450 | ABS: this is absextroot.xsub1.xsub2.called.func() |
|
470 | ABS: this is absextroot.xsub1.xsub2.called.func() | |
451 |
|
471 | |||
@@ -454,6 +474,7 b' Examine module importing.' | |||||
454 | LIB: this is extlibroot.lsub1.lsub2.called.func() |
|
474 | LIB: this is extlibroot.lsub1.lsub2.called.func() | |
455 | LIB: this is extlibroot.recursedown.abs.used |
|
475 | LIB: this is extlibroot.recursedown.abs.used | |
456 | LIB: this is extlibroot.recursedown.legacy.used |
|
476 | LIB: this is extlibroot.recursedown.legacy.used | |
|
477 | LIB: this is extlibroot.shadowing.used | |||
457 | REL: this is absextroot.xsub1.xsub2.used |
|
478 | REL: this is absextroot.xsub1.xsub2.used | |
458 | REL: this is absextroot.xsub1.xsub2.called.func() |
|
479 | REL: this is absextroot.xsub1.xsub2.called.func() | |
459 | REL: this relimporter imports 'this is absextroot.relimportee' |
|
480 | REL: this relimporter imports 'this is absextroot.relimportee' |
General Comments 0
You need to be logged in to leave comments.
Login now