def _patch_pyimport(fspath, **kwargs):
ext_suffix = sysconfig.get_config_var("EXT_SUFFIX")
# XXX EXT_SUFFIX is None for pypy (python2.7)
if ext_suffix is None and '.pypy' not in fspath.basename:
return fspath.pyimport(**kwargs)
else:
# XXX EXT_SUFFIX is None for pypy (python2.7)
if '.pypy' in fspath.basename:
ext_suffix = fspath.ext
basename = fspath.basename.split('.')[0]
fspath = fspath.new(purebasename=basename, ext=fspath.ext)
pkgroot = fspath.dirpath()
fspath._ensuresyspath(True, pkgroot)
names = fspath.relto(pkgroot).split(fspath.sep)
modname = ".".join(names).replace(ext_suffix, "")
__import__(modname)
return sys.modules[modname]
评论列表
文章目录