forked from M-Labs/artiq
tools/file_import: make sure sys.path is always restored
This commit is contained in:
parent
0d18942869
commit
cf465dae0c
|
@ -85,10 +85,10 @@ def file_import(filename, prefix="file_import_"):
|
||||||
|
|
||||||
path = os.path.dirname(os.path.realpath(filename))
|
path = os.path.dirname(os.path.realpath(filename))
|
||||||
sys.path.insert(0, path)
|
sys.path.insert(0, path)
|
||||||
|
try:
|
||||||
loader = importlib.machinery.SourceFileLoader(modname, filename)
|
loader = importlib.machinery.SourceFileLoader(modname, filename)
|
||||||
module = loader.load_module()
|
module = loader.load_module()
|
||||||
|
finally:
|
||||||
sys.path.remove(path)
|
sys.path.remove(path)
|
||||||
|
|
||||||
return module
|
return module
|
||||||
|
|
Loading…
Reference in New Issue