def importModule(self, name):
test_dir1 = os.path.join(gSrcDir, 'path1')
test_dir2 = os.path.join(gSrcDir, 'path2')
if '.' in name:
script = textwrap.dedent("""\
import site
site.addsitedir(%r)
site.addsitedir(%r)
try:
import %s
except ImportError:
import %s
print (%s.__name__)
""") %(test_dir1, test_dir2, name, name.rsplit('.', 1)[0], name)
else:
script = textwrap.dedent("""\
import site
site.addsitedir(%r)
site.addsitedir(%r)
import %s
print (%s.__name__)
""") %(test_dir1, test_dir2, name, name)
p = subprocess.Popen([sys.executable, '-c', script],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
cwd=os.path.join(
os.path.dirname(os.path.abspath(__file__)),
'testpkg-relimport'),
)
data = p.communicate()[0]
if sys.version_info[0] != 2:
data = data.decode('UTF-8')
data = data.strip()
if data.endswith(' refs]'):
data = data.rsplit('\n', 1)[0].strip()
sts = p.wait()
if sts != 0:
raise ImportError(name)
return data
test_pep420_nspkg.py 文件源码
python
阅读 26
收藏 0
点赞 0
评论 0
评论列表
文章目录