def get_env(self):
"""Computes an env from various settings: `requester.env_string`,
`requester.file`, `requester.env_file` settings. Returns a tuple
containing an env dictionary and a combined env string.
http://stackoverflow.com/questions/67631/how-to-import-a-module-given-the-full-path
"""
env_strings = []
packages_path = self.config.get('packages_path', '')
if packages_path and packages_path not in sys.path: # makes it possible to import any Python package in env
sys.path.append(packages_path)
env_strings.append(self.view.settings().get('requester.env_string', None))
if not self.view.settings().get('requester.env_block_parsed', None):
# if env block was already parsed don't parse it again
file = self.view.settings().get('requester.file', None)
if file:
try:
with open(file, 'r', encoding='utf-8') as f:
text = f.read()
except Exception as e:
self.add_error_status_bar(str(e))
else:
env_strings.append(self.parse_env_block(text))
env_file = self.view.settings().get('requester.env_file', None)
if env_file:
try:
with open(env_file, 'r') as f:
env_strings.append(f.read())
except Exception as e:
self.add_error_status_bar(str(e))
env_string = '\n\n'.join(s for s in env_strings if s)
return self.get_env_dict_from_string(env_string), env_string
评论列表
文章目录