Skip to content

Commit 2674ed1

Browse files
committedJul 3, 2015
use __all__ to structure the namespace
1 parent 0a9f909 commit 2674ed1

File tree

6 files changed

+37
-14
lines changed

6 files changed

+37
-14
lines changed
 

‎artiq/__init__.py

+3
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
from artiq import language
22
from artiq.language import *
3+
4+
__all__ = []
5+
__all__.extend(language.__all__)

‎artiq/language/__init__.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1+
from artiq.language import core, experiment, db, units
12
from artiq.language.core import *
2-
from artiq.language.experiment import Experiment
3+
from artiq.language.experiment import *
34
from artiq.language.db import *
45
from artiq.language.units import *
6+
7+
__all__ = []
8+
__all__.extend(core.__all__)
9+
__all__.extend(experiment.__all__)
10+
__all__.extend(db.__all__)
11+
__all__.extend(units.__all__)

‎artiq/language/core.py

+18-13
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,20 @@
22
Core ARTIQ extensions to the Python language.
33
"""
44

5-
from collections import namedtuple as _namedtuple
6-
from functools import wraps as _wraps
5+
from collections import namedtuple
6+
from functools import wraps
7+
8+
9+
__all__ = ["int64", "round64", "kernel", "portable",
10+
"set_time_manager", "set_syscall_manager", "set_watchdog_factory",
11+
"RuntimeException"]
12+
13+
# global namespace for kernels
14+
kernel_globals = ("sequential", "parallel",
15+
"delay_mu", "now_mu", "at_mu", "delay",
16+
"seconds_to_mu", "mu_to_seconds",
17+
"syscall", "watchdog")
18+
__all__.extend(kernel_globals)
719

820

921
class int64(int):
@@ -65,7 +77,7 @@ def round64(x):
6577
return int64(round(x))
6678

6779

68-
_KernelFunctionInfo = _namedtuple("_KernelFunctionInfo", "core_name k_function")
80+
_KernelFunctionInfo = namedtuple("_KernelFunctionInfo", "core_name k_function")
6981

7082

7183
def kernel(arg):
@@ -89,16 +101,16 @@ def kernel(arg):
89101
"""
90102
if isinstance(arg, str):
91103
def real_decorator(k_function):
92-
@_wraps(k_function)
104+
@wraps(k_function)
93105
def run_on_core(exp, *k_args, **k_kwargs):
94-
return getattr(exp, arg).run(k_function,
106+
return getattr(exp, arg).run(k_function,
95107
((exp,) + k_args), k_kwargs)
96108
run_on_core.k_function_info = _KernelFunctionInfo(
97109
core_name=arg, k_function=k_function)
98110
return run_on_core
99111
return real_decorator
100112
else:
101-
@_wraps(arg)
113+
@wraps(arg)
102114
def run_on_core(exp, *k_args, **k_kwargs):
103115
return exp.core.run(arg, ((exp,) + k_args), k_kwargs)
104116
run_on_core.k_function_info = _KernelFunctionInfo(
@@ -160,13 +172,6 @@ def set_syscall_manager(syscall_manager):
160172
global _syscall_manager
161173
_syscall_manager = syscall_manager
162174

163-
# global namespace for kernels
164-
165-
kernel_globals = ("sequential", "parallel",
166-
"delay_mu", "now_mu", "at_mu", "delay",
167-
"seconds_to_mu", "mu_to_seconds",
168-
"syscall", "watchdog")
169-
170175

171176
class _Sequential:
172177
"""In a sequential block, statements are executed one after another, with

‎artiq/language/db.py

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
Connection to device, parameter and result database.
33
"""
44

5+
__all__ = ["Device", "NoDefault", "Parameter", "Argument", "Result", "AutoDB"]
6+
7+
58
class _AttributeKind:
69
pass
710

‎artiq/language/experiment.py

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
from inspect import isclass
22

3+
__all__ = ["Experiment", "has_analyze", "is_experiment"]
4+
35

46
class Experiment:
57
"""Base class for experiments.

‎artiq/language/units.py

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
__all__ = []
2+
13
_prefixes_str = "pnum_kMG"
24
_smallest_prefix_exp = -12
35

@@ -8,6 +10,7 @@ def _register_unit(unit, prefixes):
810
if prefix in prefixes:
911
full_name = prefix + unit if prefix != "_" else unit
1012
globals()[full_name] = 10.**exponent
13+
__all__.append(full_name)
1114
exponent += 3
1215

1316

0 commit comments

Comments
 (0)
Please sign in to comment.