From 170a626c76efd5c0f86fe442dc92d0c7f3175600 Mon Sep 17 00:00:00 2001 From: Sebastien Bourdeauducq Date: Tue, 17 Feb 2015 16:13:00 -0700 Subject: [PATCH] tools/file_import: support import of modules importing from their directory --- artiq/tools.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/artiq/tools.py b/artiq/tools.py index 7b313d2a9..6a44e59ef 100644 --- a/artiq/tools.py +++ b/artiq/tools.py @@ -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