mirror of
https://github.com/m-labs/artiq.git
synced 2024-12-25 03:08:27 +08:00
worker,environment: support scanning of arguments with no default
This commit is contained in:
parent
9ed4dcd7d1
commit
7de56666e3
@ -10,12 +10,20 @@ class NoDefault:
|
||||
pass
|
||||
|
||||
|
||||
class DefaultMissing(Exception):
|
||||
"""Raised by the ``default`` method of argument processors when no default
|
||||
value is available."""
|
||||
pass
|
||||
|
||||
|
||||
class FreeValue:
|
||||
def __init__(self, default=NoDefault):
|
||||
if default is not NoDefault:
|
||||
self.default_value = default
|
||||
|
||||
def default(self):
|
||||
if not hasattr(self, "default_value"):
|
||||
raise DefaultMissing
|
||||
return self.default_value
|
||||
|
||||
def process(self, x):
|
||||
@ -32,13 +40,14 @@ class HasEnvironment:
|
||||
"""Provides methods to manage the environment of an experiment (devices,
|
||||
parameters, results, arguments)."""
|
||||
def __init__(self, dmgr=None, pdb=None, rdb=None, *,
|
||||
param_override=dict(), **kwargs):
|
||||
param_override=dict(), default_arg_none=False, **kwargs):
|
||||
self.requested_args = dict()
|
||||
|
||||
self.__dmgr = dmgr
|
||||
self.__pdb = pdb
|
||||
self.__rdb = rdb
|
||||
self.__param_override = param_override
|
||||
self.__default_arg_none = default_arg_none
|
||||
|
||||
self.__kwargs = kwargs
|
||||
self.__in_build = True
|
||||
@ -65,7 +74,13 @@ class HasEnvironment:
|
||||
try:
|
||||
argval = self.__kwargs[key]
|
||||
except KeyError:
|
||||
return processor.default()
|
||||
try:
|
||||
return processor.default()
|
||||
except DefaultMissing:
|
||||
if self.__default_arg_none:
|
||||
return None
|
||||
else:
|
||||
raise
|
||||
return processor.process(argval)
|
||||
|
||||
def attr_argument(self, key, processor=None):
|
||||
|
@ -126,7 +126,7 @@ def examine(dmgr, pdb, rdb, file):
|
||||
name = exp_class.__doc__.splitlines()[0].strip()
|
||||
if name[-1] == ".":
|
||||
name = name[:-1]
|
||||
exp_inst = exp_class(dmgr, pdb, rdb)
|
||||
exp_inst = exp_class(dmgr, pdb, rdb, default_arg_none=True)
|
||||
arguments = {k: v.describe()
|
||||
for k, v in exp_inst.requested_args.items()}
|
||||
register_experiment(class_name, name, arguments)
|
||||
|
Loading…
Reference in New Issue
Block a user