mirror of
https://github.com/m-labs/artiq.git
synced 2024-12-26 03:38:25 +08:00
tools/file_import: restore sys.modules. Closes #976
This commit is contained in:
parent
84e1f05559
commit
b48e782dd6
@ -6,6 +6,7 @@ import collections
|
|||||||
import atexit
|
import atexit
|
||||||
import string
|
import string
|
||||||
import os
|
import os
|
||||||
|
from copy import copy
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
@ -84,8 +85,12 @@ 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:
|
try:
|
||||||
loader = importlib.machinery.SourceFileLoader(modname, filename)
|
previous_modules = copy(sys.modules)
|
||||||
module = loader.load_module()
|
try:
|
||||||
|
loader = importlib.machinery.SourceFileLoader(modname, filename)
|
||||||
|
module = loader.load_module()
|
||||||
|
finally:
|
||||||
|
sys.modules = previous_modules
|
||||||
finally:
|
finally:
|
||||||
sys.path.remove(path)
|
sys.path.remove(path)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user