path/testing/fscommon.py - line 240
|
|
def test__getpymodule_c(self): |
otherdir = self.root.join('otherdir') |
-> mod = otherdir.join('c.py')._getpymodule() |
assert mod.value == "got it" | |
path/common.py - line 387
| 373 |
| 374 |
| 375 |
| 376 |
| 377 |
| 378 |
| 379 |
| 380 |
| 381 |
| 382 |
| 383 |
| 384 |
| 385 |
| 386 |
| 387 |
| 388 |
| 389 |
| 390 |
| 391 | |
def _getpymodule(self): |
"""resolve this path to a module python object. """ |
modname = str(self) |
modname = modname.replace('.', self.sep) |
try: |
return sys.modules[modname] |
except KeyError: |
co = self._getpycodeobj() |
mod = py.std.new.module(modname) |
mod.__file__ = PathStr(self) |
if self.basename == '__init__.py': |
mod.__path__ = [str(self.dirpath())] |
sys.modules[modname] = mod |
try: |
-> exec co in mod.__dict__ |
except: |
del sys.modules[modname] |
raise |
return mod | |
None</build/buildd/codespeak-lib-0.9.1/py/code/source.py:213> - line 2
|
|
import py; py.magic.autopath() | |
path/common.py - line 442
| 434 |
| 435 |
| 436 |
| 437 |
| 438 |
| 439 |
| 440 |
| 441 |
| 442 |
| 443 |
| 444 |
| 445 |
| 446 |
| 447 |
| 448 |
| 449 |
| 450 |
| 451 |
| 452 |
| 453 |
| 454 |
| 455 |
| 456 |
| 457 |
| 458 |
| 459 |
| 460 | |
def custom_import_hook(name, glob=None, loc=None, fromlist=None): |
__tracebackhide__ = False |
__file__ = glob and glob.get('__file__') |
if isinstance(__file__, PathStr): |
|
|
modules = None |
if hasattr(__file__.__path__, 'pkgdir'): |
-> modules = relativeimport(__file__.__path__.pkgdir, name) |
if not modules: |
modules = relativeimport(__file__.__path__, name) |
if modules: |
if fromlist: |
submodule = modules[-1] |
|
|
p = submodule.__file__.__path__ |
if p.check(basename='__init__.py'): |
for name in fromlist: |
relativeimport(p, name, parent=submodule) |
|
return submodule |
else: |
return modules[0] |
|
__tracebackhide__ = True |
return old_import_hook(name, glob, loc, fromlist) | |
path/common.py - line 419
| 408 |
| 409 |
| 410 |
| 411 |
| 412 |
| 413 |
| 414 |
| 415 |
| 416 |
| 417 |
| 418 |
| 419 |
| 420 |
| 421 |
| 422 |
| 423 |
| 424 |
| 425 |
| 426 |
| 427 |
| 428 |
| 429 | |
def relativeimport(p, name, parent=None): |
names = name.split('.') |
last_list = [False] * (len(names)-1) + [True] |
modules = [] |
for name, is_last in zip(names, last_list): |
if hasattr(parent, name): |
|
|
submodule = getattr(parent, name) |
else: |
if is_last and p.new(basename=name+'.py').check(): |
-> p = p.new(basename=name+'.py') |
else: |
p = p.new(basename=name).join('__init__.py') |
if not p.check(): |
return None |
submodule = p._getpymodule() |
if parent is not None: |
setattr(parent, name, submodule) |
modules.append(submodule) |
parent = submodule |
return modules | |