LSSTApplications  18.1.0
LSSTDataManagementBasePackage
Public Member Functions | Properties | List of all members
lsst.pex.config.configurableField.ConfigurableInstance Class Reference

Public Member Functions

def __init__ (self, config, field, at=None, label="default")
 
def apply (self, args, kw)
 
def retarget (self, target, ConfigClass=None, at=None, label="retarget")
 
def __getattr__ (self, name)
 
def __setattr__ (self, name, value, at=None, label="assignment")
 
def __delattr__ (self, name, at=None, label="delete")
 

Properties

 target = property(lambda x: x._target)
 
 ConfigClass = property(lambda x: x._ConfigClass)
 
 value = property(lambda x: x._value)
 

Detailed Description

A retargetable configuration in a `ConfigurableField` that proxies
a `~lsst.pex.config.Config`.

Notes
-----
``ConfigurableInstance`` implements ``__getattr__`` and ``__setattr__``
methods that forward to the `~lsst.pex.config.Config` it holds.
``ConfigurableInstance`` adds a `retarget` method.

The actual `~lsst.pex.config.Config` instance is accessed using the
``value`` property (e.g. to get its documentation).  The associated
configurable object (usually a `~lsst.pipe.base.Task`) is accessed
using the ``target`` property.

Definition at line 31 of file configurableField.py.

Constructor & Destructor Documentation

◆ __init__()

def lsst.pex.config.configurableField.ConfigurableInstance.__init__ (   self,
  config,
  field,
  at = None,
  label = "default" 
)

Definition at line 64 of file configurableField.py.

64  def __init__(self, config, field, at=None, label="default"):
65  object.__setattr__(self, "_config", config)
66  object.__setattr__(self, "_field", field)
67  object.__setattr__(self, "__doc__", config)
68  object.__setattr__(self, "_target", field.target)
69  object.__setattr__(self, "_ConfigClass", field.ConfigClass)
70  object.__setattr__(self, "_value", None)
71 
72  if at is None:
73  at = getCallStack()
74  at += [self._field.source]
75  self.__initValue(at, label)
76 
77  history = config._history.setdefault(field.name, [])
78  history.append(("Targeted and initialized from defaults", at, label))
79 
def getCallStack(skip=0)
Definition: callStack.py:169
def __init__(self, minimum, dataRange, Q)

Member Function Documentation

◆ __delattr__()

def lsst.pex.config.configurableField.ConfigurableInstance.__delattr__ (   self,
  name,
  at = None,
  label = "delete" 
)
Pretend to be an isntance of  ConfigClass.
Attributes defiend by ConfigurableInstance will shadow those defined in ConfigClass

Definition at line 145 of file configurableField.py.

145  def __delattr__(self, name, at=None, label="delete"):
146  """
147  Pretend to be an isntance of ConfigClass.
148  Attributes defiend by ConfigurableInstance will shadow those defined in ConfigClass
149  """
150  if self._config._frozen:
151  raise FieldValidationError(self._field, self._config, "Cannot modify a frozen Config")
152 
153  try:
154  # attribute exists in the ConfigurableInstance wrapper
155  object.__delattr__(self, name)
156  except AttributeError:
157  if at is None:
158  at = getCallStack()
159  self._value.__delattr__(name, at=at, label=label)
160 
161 
def getCallStack(skip=0)
Definition: callStack.py:169

◆ __getattr__()

def lsst.pex.config.configurableField.ConfigurableInstance.__getattr__ (   self,
  name 
)

Definition at line 126 of file configurableField.py.

126  def __getattr__(self, name):
127  return getattr(self._value, name)
128 

◆ __setattr__()

def lsst.pex.config.configurableField.ConfigurableInstance.__setattr__ (   self,
  name,
  value,
  at = None,
  label = "assignment" 
)
Pretend to be an instance of ConfigClass.

Attributes defined by ConfigurableInstance will shadow those defined in ConfigClass

Definition at line 129 of file configurableField.py.

129  def __setattr__(self, name, value, at=None, label="assignment"):
130  """Pretend to be an instance of ConfigClass.
131 
132  Attributes defined by ConfigurableInstance will shadow those defined in ConfigClass
133  """
134  if self._config._frozen:
135  raise FieldValidationError(self._field, self._config, "Cannot modify a frozen Config")
136 
137  if name in self.__dict__:
138  # attribute exists in the ConfigurableInstance wrapper
139  object.__setattr__(self, name, value)
140  else:
141  if at is None:
142  at = getCallStack()
143  self._value.__setattr__(name, value, at=at, label=label)
144 
def getCallStack(skip=0)
Definition: callStack.py:169

◆ apply()

def lsst.pex.config.configurableField.ConfigurableInstance.apply (   self,
  args,
  kw 
)
Call the configurable.

Notes
-----
In addition to the user-provided positional and keyword arguments,
the configurable is also provided a keyword argument ``config`` with
the value of `ConfigurableInstance.value`.

Definition at line 93 of file configurableField.py.

93  def apply(self, *args, **kw):
94  """Call the configurable.
95 
96  Notes
97  -----
98  In addition to the user-provided positional and keyword arguments,
99  the configurable is also provided a keyword argument ``config`` with
100  the value of `ConfigurableInstance.value`.
101  """
102  return self.target(*args, config=self.value, **kw)
103 

◆ retarget()

def lsst.pex.config.configurableField.ConfigurableInstance.retarget (   self,
  target,
  ConfigClass = None,
  at = None,
  label = "retarget" 
)
Target a new configurable and ConfigClass

Definition at line 104 of file configurableField.py.

104  def retarget(self, target, ConfigClass=None, at=None, label="retarget"):
105  """Target a new configurable and ConfigClass
106  """
107  if self._config._frozen:
108  raise FieldValidationError(self._field, self._config, "Cannot modify a frozen Config")
109 
110  try:
111  ConfigClass = self._field.validateTarget(target, ConfigClass)
112  except BaseException as e:
113  raise FieldValidationError(self._field, self._config, e.message)
114 
115  if at is None:
116  at = getCallStack()
117  object.__setattr__(self, "_target", target)
118  if ConfigClass != self.ConfigClass:
119  object.__setattr__(self, "_ConfigClass", ConfigClass)
120  self.__initValue(at, label)
121 
122  history = self._config._history.setdefault(self._field.name, [])
123  msg = "retarget(target=%s, ConfigClass=%s)" % (_typeStr(target), _typeStr(ConfigClass))
124  history.append((msg, at, label))
125 
def getCallStack(skip=0)
Definition: callStack.py:169

Property Documentation

◆ ConfigClass

lsst.pex.config.configurableField.ConfigurableInstance.ConfigClass = property(lambda x: x._ConfigClass)
static

Definition at line 84 of file configurableField.py.

◆ target

lsst.pex.config.configurableField.ConfigurableInstance.target = property(lambda x: x._target)
static

Definition at line 80 of file configurableField.py.

◆ value

lsst.pex.config.configurableField.ConfigurableInstance.value = property(lambda x: x._value)
static

Definition at line 88 of file configurableField.py.


The documentation for this class was generated from the following file: