forked from M-Labs/artiq
1
0
Fork 0

tools/file_import: support import of modules importing from their directory

This commit is contained in:
Sebastien Bourdeauducq 2015-02-17 16:13:00 -07:00
parent 656099a331
commit 170a626c76
1 changed files with 7 additions and 0 deletions

View File

@ -3,6 +3,7 @@ import sys
import importlib.machinery
import linecache
import logging
import os.path
def format_run_arguments(arguments):
@ -27,9 +28,15 @@ def file_import(filename):
modname = modname[:i]
modname = "file_import_" + modname
path = os.path.dirname(os.path.realpath(filename))
sys.path.insert(0, path)
loader = importlib.machinery.SourceFileLoader(modname, filename)
module = type(sys)(modname)
loader.exec_module(module)
sys.path.remove(path)
return module