2
0
mirror of https://github.com/m-labs/artiq.git synced 2024-12-25 03:08:27 +08:00

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

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