def include(self, incfile: str):
old = self.current_path
self.current_path = os.path.join(old, os.path.dirname(incfile))
path = os.path.join(self.current_path, os.path.basename(incfile))
sys.path.append(self.current_path)
try:
content = open(path, "rb").read()
os.chdir(self.current_path) # set the current working directory, for open() etc.
exec(compile(content, path, 'exec'), self.user_functions)
except Exception as err:
print("An exception occured while building: ", file=sys.stderr)
lines = traceback.format_exc(None, err).splitlines()
print(" " + lines[-1], file=sys.stderr)
for l in lines[3:-1]:
print(l, file=sys.stderr)
exit(1)
sys.path.remove(self.current_path)
os.chdir(old)
self.current_path = old
评论列表
文章目录