File directory added to sys.path on every changeSee original GitHub issue
This seem to not happen when there is no import.
import sys print (sys.path) from something import *
Python 3.6.7 OS: nixos 18.09.1789.11c9922a7d5 (Jellyfish)
- Created 4 years ago
- Comments:6 (5 by maintainers)
Top GitHub Comments
Fixed. I just need a try/finally around the yield in script_path
it’s a problem with the script_path function in the backend. It inserts into the path each execution.
@contextmanager def script_path(script_dir): """ Context manager for adding a dir to the sys path and restoring it afterwards. This trick allows relative imports to work on the target script. if script_dir is empty function will do nothing Slightly modified from wolf's script_path (see https://github.com/Duroktar/Wolf) """ if script_dir is None or script_dir == "": yield else: original_cwd = os.getcwd() os.chdir(script_dir) path.insert(1, script_dir) yield os.chdir(original_cwd) path.remove(script_dir) # useage: with script_path(os.path.dirname(filePath)): try: start = time() exec(codeToExec, evalLocals)