tools/file_import: make sure sys.path is always restored

pull/319/head
Sebastien Bourdeauducq 2016-01-31 20:33:17 +01:00
parent 0d18942869
commit cf465dae0c
1 changed files with 5 additions and 5 deletions

View File

@ -85,11 +85,11 @@ def file_import(filename, prefix="file_import_"):
path = os.path.dirname(os.path.realpath(filename))
sys.path.insert(0, path)
loader = importlib.machinery.SourceFileLoader(modname, filename)
module = loader.load_module()
sys.path.remove(path)
try:
loader = importlib.machinery.SourceFileLoader(modname, filename)
module = loader.load_module()
finally:
sys.path.remove(path)
return module