forked from M-Labs/artiq
1
0
Fork 0

tools/file_import: restore sys.modules. Closes #976

This commit is contained in:
Sebastien Bourdeauducq 2018-05-01 22:15:19 +08:00
parent 84e1f05559
commit b48e782dd6
1 changed files with 7 additions and 2 deletions

View File

@ -6,6 +6,7 @@ import collections
import atexit
import string
import os
from copy import copy
import numpy as np
@ -83,9 +84,13 @@ def file_import(filename, prefix="file_import_"):
path = os.path.dirname(os.path.realpath(filename))
sys.path.insert(0, path)
try:
previous_modules = copy(sys.modules)
try:
loader = importlib.machinery.SourceFileLoader(modname, filename)
module = loader.load_module()
finally:
sys.modules = previous_modules
finally:
sys.path.remove(path)