From 2674ed1d2df66923d1c8c1a62fc0cc40c4f75cd1 Mon Sep 17 00:00:00 2001 From: Robert Jordens Date: Mon, 29 Jun 2015 12:36:20 -0600 Subject: [PATCH] use __all__ to structure the namespace --- artiq/__init__.py | 3 +++ artiq/language/__init__.py | 9 ++++++++- artiq/language/core.py | 31 ++++++++++++++++++------------- artiq/language/db.py | 3 +++ artiq/language/experiment.py | 2 ++ artiq/language/units.py | 3 +++ 6 files changed, 37 insertions(+), 14 deletions(-) diff --git a/artiq/__init__.py b/artiq/__init__.py index 7e6404c1e..ae6a8f96b 100644 --- a/artiq/__init__.py +++ b/artiq/__init__.py @@ -1,2 +1,5 @@ from artiq import language from artiq.language import * + +__all__ = [] +__all__.extend(language.__all__) diff --git a/artiq/language/__init__.py b/artiq/language/__init__.py index ebdb62601..ad51894b5 100644 --- a/artiq/language/__init__.py +++ b/artiq/language/__init__.py @@ -1,4 +1,11 @@ +from artiq.language import core, experiment, db, units from artiq.language.core import * -from artiq.language.experiment import Experiment +from artiq.language.experiment import * from artiq.language.db import * from artiq.language.units import * + +__all__ = [] +__all__.extend(core.__all__) +__all__.extend(experiment.__all__) +__all__.extend(db.__all__) +__all__.extend(units.__all__) diff --git a/artiq/language/core.py b/artiq/language/core.py index 340ea2374..051ef64c1 100644 --- a/artiq/language/core.py +++ b/artiq/language/core.py @@ -2,8 +2,20 @@ Core ARTIQ extensions to the Python language. """ -from collections import namedtuple as _namedtuple -from functools import wraps as _wraps +from collections import namedtuple +from functools import wraps + + +__all__ = ["int64", "round64", "kernel", "portable", + "set_time_manager", "set_syscall_manager", "set_watchdog_factory", + "RuntimeException"] + +# global namespace for kernels +kernel_globals = ("sequential", "parallel", + "delay_mu", "now_mu", "at_mu", "delay", + "seconds_to_mu", "mu_to_seconds", + "syscall", "watchdog") +__all__.extend(kernel_globals) class int64(int): @@ -65,7 +77,7 @@ def round64(x): return int64(round(x)) -_KernelFunctionInfo = _namedtuple("_KernelFunctionInfo", "core_name k_function") +_KernelFunctionInfo = namedtuple("_KernelFunctionInfo", "core_name k_function") def kernel(arg): @@ -89,16 +101,16 @@ def kernel(arg): """ if isinstance(arg, str): def real_decorator(k_function): - @_wraps(k_function) + @wraps(k_function) def run_on_core(exp, *k_args, **k_kwargs): - return getattr(exp, arg).run(k_function, + return getattr(exp, arg).run(k_function, ((exp,) + k_args), k_kwargs) run_on_core.k_function_info = _KernelFunctionInfo( core_name=arg, k_function=k_function) return run_on_core return real_decorator else: - @_wraps(arg) + @wraps(arg) def run_on_core(exp, *k_args, **k_kwargs): return exp.core.run(arg, ((exp,) + k_args), k_kwargs) run_on_core.k_function_info = _KernelFunctionInfo( @@ -160,13 +172,6 @@ def set_syscall_manager(syscall_manager): global _syscall_manager _syscall_manager = syscall_manager -# global namespace for kernels - -kernel_globals = ("sequential", "parallel", - "delay_mu", "now_mu", "at_mu", "delay", - "seconds_to_mu", "mu_to_seconds", - "syscall", "watchdog") - class _Sequential: """In a sequential block, statements are executed one after another, with diff --git a/artiq/language/db.py b/artiq/language/db.py index 025dc22d2..d5f055603 100644 --- a/artiq/language/db.py +++ b/artiq/language/db.py @@ -2,6 +2,9 @@ Connection to device, parameter and result database. """ +__all__ = ["Device", "NoDefault", "Parameter", "Argument", "Result", "AutoDB"] + + class _AttributeKind: pass diff --git a/artiq/language/experiment.py b/artiq/language/experiment.py index 3473dcba3..c7fce7a55 100644 --- a/artiq/language/experiment.py +++ b/artiq/language/experiment.py @@ -1,5 +1,7 @@ from inspect import isclass +__all__ = ["Experiment", "has_analyze", "is_experiment"] + class Experiment: """Base class for experiments. diff --git a/artiq/language/units.py b/artiq/language/units.py index b3af0ebc3..83f1133a8 100644 --- a/artiq/language/units.py +++ b/artiq/language/units.py @@ -1,3 +1,5 @@ +__all__ = [] + _prefixes_str = "pnum_kMG" _smallest_prefix_exp = -12 @@ -8,6 +10,7 @@ def _register_unit(unit, prefixes): if prefix in prefixes: full_name = prefix + unit if prefix != "_" else unit globals()[full_name] = 10.**exponent + __all__.append(full_name) exponent += 3