Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use __all__ to structure the namespace
Browse files Browse the repository at this point in the history
jordens committed Jun 29, 2015
1 parent d1c4cf0 commit 0abea0c
Showing 6 changed files with 36 additions and 13 deletions.
3 changes: 3 additions & 0 deletions artiq/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
from artiq import language
from artiq.language import *

__all__ = []
__all__.extend(language.__all__)
9 changes: 8 additions & 1 deletion artiq/language/__init__.py
Original file line number Diff line number Diff line change
@@ -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__)
29 changes: 17 additions & 12 deletions artiq/language/core.py
Original file line number Diff line number Diff line change
@@ -2,8 +2,19 @@
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", "now", "at", "time_to_cycles", "cycles_to_time",
"syscall", "watchdog")
__all__.extend(kernel_globals)


class int64(int):
@@ -67,7 +78,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):
@@ -92,16 +103,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(
@@ -165,12 +176,6 @@ def set_syscall_manager(syscall_manager):
global _syscall_manager
_syscall_manager = syscall_manager

# global namespace for kernels

kernel_globals = ("sequential", "parallel",
"delay", "now", "at", "time_to_cycles", "cycles_to_time",
"syscall", "watchdog")


class _Sequential:
"""In a sequential block, statements are executed one after another, with
3 changes: 3 additions & 0 deletions artiq/language/db.py
Original file line number Diff line number Diff line change
@@ -2,6 +2,9 @@
Connection to device, parameter and result database.
"""

__all__ = ["Device", "NoDefault", "Parameter", "Argument", "Result", "AutoDB"]


class _AttributeKind:
pass

2 changes: 2 additions & 0 deletions artiq/language/experiment.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from inspect import isclass

__all__ = ["Experiment", "has_analyze", "is_experiment"]


class Experiment:
"""Base class for experiments.
3 changes: 3 additions & 0 deletions artiq/language/units.py
Original file line number Diff line number Diff line change
@@ -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


0 comments on commit 0abea0c

Please sign in to comment.