From d1119d77472eba9b05b4a63670765059dda00212 Mon Sep 17 00:00:00 2001 From: Robert Jordens Date: Mon, 25 Jan 2016 18:04:06 -0700 Subject: [PATCH] artiq_dir: move out of tools to unlink dependencies --- artiq/__init__.py | 4 ++++ artiq/coredevice/core.py | 4 +++- artiq/coredevice/exceptions.py | 4 ++-- artiq/coredevice/runtime.py | 6 ++++-- artiq/frontend/artiq_flash.py | 3 ++- artiq/frontend/artiq_gui.py | 1 + artiq/gateware/targets/kc705.py | 2 +- artiq/gateware/targets/pipistrello.py | 2 +- artiq/tools.py | 4 +--- 9 files changed, 19 insertions(+), 11 deletions(-) diff --git a/artiq/__init__.py b/artiq/__init__.py index e44e9d156..6bbf35eec 100644 --- a/artiq/__init__.py +++ b/artiq/__init__.py @@ -1,3 +1,7 @@ from ._version import get_versions __version__ = get_versions()['version'] del get_versions + +import os +__artiq_dir__ = os.path.dirname(os.path.abspath(__file__)) +del os diff --git a/artiq/coredevice/core.py b/artiq/coredevice/core.py index aa1bb8560..0cf49b27c 100644 --- a/artiq/coredevice/core.py +++ b/artiq/coredevice/core.py @@ -2,6 +2,8 @@ import os, sys from pythonparser import diagnostic +from artiq import __artiq_dir__ as artiq_dir + from artiq.language.core import * from artiq.language.types import * from artiq.language.units import * @@ -16,7 +18,7 @@ from artiq.coredevice import exceptions def _render_diagnostic(diagnostic, colored): def shorten_path(path): - return path.replace(os.path.normpath(os.path.join(__file__, "..", "..")), "") + return path.replace(artiq_dir, "") lines = [shorten_path(path) for path in diagnostic.render(colored)] return "\n".join(lines) diff --git a/artiq/coredevice/exceptions.py b/artiq/coredevice/exceptions.py index 0576b2610..62d4c147a 100644 --- a/artiq/coredevice/exceptions.py +++ b/artiq/coredevice/exceptions.py @@ -3,6 +3,7 @@ import linecache import re import os +from artiq import __artiq_dir__ as artiq_dir from artiq.coredevice.runtime import source_loader @@ -36,8 +37,7 @@ class CoreException: else: formatted_address = " (RA=0x{:x})".format(address) - filename = filename.replace(os.path.normpath(os.path.join(os.path.dirname(__file__), - "..")), "") + filename = filename.replace(artiq_dir, "") if column == -1: lines.append(" File \"{file}\", line {line}, in {function}{address}". format(file=filename, line=line, function=function, diff --git a/artiq/coredevice/runtime.py b/artiq/coredevice/runtime.py index 96df51e0e..4d65e86d8 100644 --- a/artiq/coredevice/runtime.py +++ b/artiq/coredevice/runtime.py @@ -1,5 +1,8 @@ import os +from artiq import __artiq_dir__ as artiq_dir + + class SourceLoader: def __init__(self, runtime_root): self.runtime_root = runtime_root @@ -8,5 +11,4 @@ class SourceLoader: with open(os.path.join(self.runtime_root, filename)) as f: return f.read() -artiq_root = os.path.join(os.path.dirname(__file__), "..", "..") -source_loader = SourceLoader(os.path.join(artiq_root, "soc", "runtime")) +source_loader = SourceLoader(os.path.join(artiq_dir, "soc", "runtime")) diff --git a/artiq/frontend/artiq_flash.py b/artiq/frontend/artiq_flash.py index df3b330a0..8d484cc41 100755 --- a/artiq/frontend/artiq_flash.py +++ b/artiq/frontend/artiq_flash.py @@ -7,6 +7,7 @@ import subprocess import tempfile import artiq +from artiq import __artiq_dir__ as artiq_dir from artiq.frontend.bit2bin import bit2bin @@ -70,7 +71,7 @@ def main(): }[opts.target] if opts.dir is None: - opts.dir = os.path.join(os.path.dirname(artiq.__file__), "binaries", + opts.dir = os.path.join(artiq_dir, "binaries", "{}-{}".format(opts.target, opts.adapter)) conv = False diff --git a/artiq/frontend/artiq_gui.py b/artiq/frontend/artiq_gui.py index 9ce3aa151..615b503fb 100755 --- a/artiq/frontend/artiq_gui.py +++ b/artiq/frontend/artiq_gui.py @@ -10,6 +10,7 @@ import os from quamash import QEventLoop, QtGui, QtCore from pyqtgraph import dockarea +from artiq import __artiq_dir__ as artiq_dir from artiq.tools import * from artiq.protocols.pc_rpc import AsyncioClient from artiq.gui.models import ModelSubscriber diff --git a/artiq/gateware/targets/kc705.py b/artiq/gateware/targets/kc705.py index e288dde71..fda69e95b 100755 --- a/artiq/gateware/targets/kc705.py +++ b/artiq/gateware/targets/kc705.py @@ -20,7 +20,7 @@ from misoc.targets.kc705 import MiniSoC, soc_kc705_args, soc_kc705_argdict from artiq.gateware.soc import AMPSoC from artiq.gateware import rtio, nist_qc1, nist_clock, nist_qc2 from artiq.gateware.rtio.phy import ttl_simple, ttl_serdes_7series, dds -from artiq.tools import artiq_dir +from artiq import __artiq_dir__ as artiq_dir from artiq import __version__ as artiq_version diff --git a/artiq/gateware/targets/pipistrello.py b/artiq/gateware/targets/pipistrello.py index c6290d2ac..288a7b3c8 100755 --- a/artiq/gateware/targets/pipistrello.py +++ b/artiq/gateware/targets/pipistrello.py @@ -20,7 +20,7 @@ from misoc.targets.pipistrello import * from artiq.gateware.soc import AMPSoC from artiq.gateware import rtio, nist_qc1 from artiq.gateware.rtio.phy import ttl_simple, ttl_serdes_spartan6, dds -from artiq.tools import artiq_dir +from artiq import __artiq_dir__ as artiq_dir from artiq import __version__ as artiq_version diff --git a/artiq/tools.py b/artiq/tools.py index d589afadf..addd5d55c 100644 --- a/artiq/tools.py +++ b/artiq/tools.py @@ -16,7 +16,7 @@ from artiq.language.environment import is_experiment from artiq.protocols import pyon -__all__ = ["artiq_dir", "parse_arguments", "elide", "short_format", "file_import", +__all__ = ["parse_arguments", "elide", "short_format", "file_import", "get_experiment", "verbosity_args", "simple_network_args", "init_logger", "bind_address_from_args", "atexit_register_coroutine", "exc_to_warning", "asyncio_wait_or_cancel", @@ -25,8 +25,6 @@ __all__ = ["artiq_dir", "parse_arguments", "elide", "short_format", "file_import logger = logging.getLogger(__name__) -artiq_dir = os.path.join(os.path.abspath(os.path.dirname(__file__))) - def parse_arguments(arguments): d = {}