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