LSST Applications g04c3c9f7ca+2075667efa,g1e125bf412+5f448d5fcf,g2079a07aa2+3e9fd84d81,g2305ad1205+b635cf1488,g2bbee38e9b+6c6beb4891,g337abbeb29+6c6beb4891,g33d1c0ed96+6c6beb4891,g3a166c0a6a+6c6beb4891,g50ff169b8f+96c6868917,g52b1c1532d+585e252eca,g591dd9f2cf+42f171e1e6,g5c3423f6d4+d536b04327,g607f77f49a+d536b04327,g6f43f06aed+ca1339dc19,g858d7b2824+d536b04327,g8ee334c5b4+d7f9608c2f,g9963eaa53e+b3dc1655d3,g998f4353bf+d536b04327,g99cad8db69+8ef2408349,g9ddcbc5298+9a081db1e4,ga1e77700b3+2cbb763275,gadfd92a7e4+aec2f3b930,gae0086650b+585e252eca,gb0e22166c9+0e73c8378f,gb3b7280ab2+cb5fdb229e,gbb8dafda3b+a327199e22,gc120e1dc64+88074880ea,gc28159a63d+6c6beb4891,gcdd4ae20e8+bd241b2308,gcde1bda545+903e937d91,gcf0d15dbbd+bd241b2308,gdaeeff99f8+f9a426f77a,gddc38dedce+585e252eca,ge79ae78c31+6c6beb4891,gfbcc870c63+b310236976,w.2024.23
LSST Data Management Base Package
Loading...
Searching...
No Matches
Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | Static Protected Attributes | List of all members
lsst.pex.config.configurableActions._configurableActionStructField.ConfigurableActionStruct Class Reference
Inheritance diagram for lsst.pex.config.configurableActions._configurableActionStructField.ConfigurableActionStruct:

Public Member Functions

 __init__ (self, Config config, ConfigurableActionStructField field, Mapping[str, ConfigurableAction] value, Any at, str label)
 
list[tuple] history (self)
 
Iterable[str] fieldNames (self)
 
None __setattr__ (self, str attr, ActionTypeVar|type[ActionTypeVar] value, at=None, label="setattr", setHistory=False)
 
Any __getattr__ (self, attr)
 
 __delattr__ (self, name)
 
Iterator[ActionTypeVar] __iter__ (self)
 
Iterable[tuple[str, ActionTypeVar]] items (self)
 
bool __bool__ (self)
 

Static Public Attributes

 update = ConfigurableActionStructUpdater()
 
 remove = ConfigurableActionStructRemover()
 

Protected Member Functions

Config _config (self)
 

Protected Attributes

 _config
 
 _field
 
 _attrs
 

Static Protected Attributes

weakref _config_ .ref
 
dict _attrs [str, ActionTypeVar]
 
ConfigurableActionStructField _field
 
list _history [tuple]
 

Detailed Description

A ConfigurableActionStruct is the storage backend class that supports
the ConfigurableActionStructField. This class should not be created
directly.

This class allows managing a collection of `ConfigurableAction` with a
struct like interface, that is to say in an attribute like notation.

Parameters
----------
config : `~lsst.pex.config.Config`
    Config to use.
field : `ConfigurableActionStructField`
    Field to use.
value : `~collections.abc.Mapping` [`str`, `ConfigurableAction`]
    Value to assign.
at : `list` of `~lsst.pex.config.callStack.StackFrame` or `None`, optional
    Stack frames to use for history recording.
label : `str`, optional
    Label to use for history recording.

Notes
-----
Attributes can be dynamically added or removed as such:

.. code-block:: python

    ConfigurableActionStructInstance.variable1 = a_configurable_action
    del ConfigurableActionStructInstance.variable1

Each action is then available to be individually configured as a normal
`lsst.pex.config.Config` object.

`ConfigurableActionStruct` supports two special convenience attributes.

The first is ``update``. You may assign a dict of `ConfigurableAction` or a
`ConfigurableActionStruct` to this attribute which will update the
`ConfigurableActionStruct` on which the attribute is invoked such that it
will be updated to contain the entries specified by the structure on the
right hand side of the equals sign.

The second convenience attribute is named ``remove``. You may assign an
iterable of strings which correspond to attribute names on the
`ConfigurableActionStruct`. All of the corresponding attributes will then
be removed. If any attribute does not exist, an `AttributeError` will be
raised. Any attributes in the Iterable prior to the name which raises will
have been removed from the `ConfigurableActionStruct`

Definition at line 96 of file _configurableActionStructField.py.

Constructor & Destructor Documentation

◆ __init__()

lsst.pex.config.configurableActions._configurableActionStructField.ConfigurableActionStruct.__init__ ( self,
Config config,
ConfigurableActionStructField field,
Mapping[str, ConfigurableAction] value,
Any at,
str label )

Definition at line 155 of file _configurableActionStructField.py.

162 ):
163 object.__setattr__(self, "_config_", weakref.ref(config))
164 object.__setattr__(self, "_attrs", {})
165 object.__setattr__(self, "_field", field)
166 object.__setattr__(self, "_history", [])
167
168 self.history.append(("Struct initialized", at, label))
169
170 if value is not None:
171 for k, v in value.items():
172 setattr(self, k, v)
173

Member Function Documentation

◆ __bool__()

bool lsst.pex.config.configurableActions._configurableActionStructField.ConfigurableActionStruct.__bool__ ( self)

Definition at line 242 of file _configurableActionStructField.py.

242 def __bool__(self) -> bool:
243 return bool(self._attrs)
244
245

◆ __delattr__()

lsst.pex.config.configurableActions._configurableActionStructField.ConfigurableActionStruct.__delattr__ ( self,
name )

Definition at line 228 of file _configurableActionStructField.py.

228 def __delattr__(self, name):
229 if name in self._attrs:
230 del self._attrs[name]
231 else:
232 super().__delattr__(name)
233

◆ __getattr__()

Any lsst.pex.config.configurableActions._configurableActionStructField.ConfigurableActionStruct.__getattr__ ( self,
attr )

Definition at line 220 of file _configurableActionStructField.py.

220 def __getattr__(self, attr) -> Any:
221 if attr in object.__getattribute__(self, "_attrs"):
222 result = self._attrs[attr]
223 result.identity = attr
224 return result
225 else:
226 super().__getattribute__(attr)
227

◆ __iter__()

Iterator[ActionTypeVar] lsst.pex.config.configurableActions._configurableActionStructField.ConfigurableActionStruct.__iter__ ( self)

Definition at line 234 of file _configurableActionStructField.py.

234 def __iter__(self) -> Iterator[ActionTypeVar]:
235 for name in self.fieldNames:
236 yield getattr(self, name)
237

◆ __setattr__()

None lsst.pex.config.configurableActions._configurableActionStructField.ConfigurableActionStruct.__setattr__ ( self,
str attr,
ActionTypeVar | type[ActionTypeVar] value,
at = None,
label = "setattr",
setHistory = False )

Definition at line 190 of file _configurableActionStructField.py.

197 ) -> None:
198 if hasattr(self._config, "_frozen") and self._config._frozen:
199 msg = "Cannot modify a frozen Config. " f"Attempting to set item {attr} to value {value}"
200 raise FieldValidationError(self._field, self._config, msg)
201
202 # verify that someone has not passed a string with a space or leading
203 # number or something through the dict assignment update interface
204 if not attr.isidentifier():
205 raise ValueError("Names used in ConfigurableStructs must be valid as python variable names")
206
207 if attr not in (self.__dict__.keys() | type(self).__dict__.keys()):
208 base_name = _joinNamePath(self._config._name, self._field.name)
209 name = _joinNamePath(base_name, attr)
210 if at is None:
211 at = getCallStack()
212 if isinstance(value, ConfigurableAction):
213 valueInst = type(value)(__name=name, __at=at, __label=label, **value._storage)
214 else:
215 valueInst = value(__name=name, __at=at, __label=label)
216 self._attrs[attr] = valueInst
217 else:
218 super().__setattr__(attr, value)
219

◆ _config()

Config lsst.pex.config.configurableActions._configurableActionStructField.ConfigurableActionStruct._config ( self)
protected

Definition at line 175 of file _configurableActionStructField.py.

175 def _config(self) -> Config:
176 # Config Fields should never outlive their config class instance
177 # assert that as such here
178 value = self._config_()
179 assert value is not None
180 return value
181

◆ fieldNames()

Iterable[str] lsst.pex.config.configurableActions._configurableActionStructField.ConfigurableActionStruct.fieldNames ( self)

Definition at line 187 of file _configurableActionStructField.py.

187 def fieldNames(self) -> Iterable[str]:
188 return self._attrs.keys()
189

◆ history()

list[tuple] lsst.pex.config.configurableActions._configurableActionStructField.ConfigurableActionStruct.history ( self)

Definition at line 183 of file _configurableActionStructField.py.

183 def history(self) -> list[tuple]:
184 return self._history
185

◆ items()

Iterable[tuple[str, ActionTypeVar]] lsst.pex.config.configurableActions._configurableActionStructField.ConfigurableActionStruct.items ( self)

Definition at line 238 of file _configurableActionStructField.py.

238 def items(self) -> Iterable[tuple[str, ActionTypeVar]]:
239 for name in self.fieldNames:
240 yield name, getattr(self, name)
241
std::vector< SchemaItem< Flag > > * items

Member Data Documentation

◆ _attrs [1/2]

dict lsst.pex.config.configurableActions._configurableActionStructField.ConfigurableActionStruct._attrs [str, ActionTypeVar]
staticprotected

Definition at line 147 of file _configurableActionStructField.py.

◆ _attrs [2/2]

lsst.pex.config.configurableActions._configurableActionStructField.ConfigurableActionStruct._attrs
protected

Definition at line 243 of file _configurableActionStructField.py.

◆ _config

lsst.pex.config.configurableActions._configurableActionStructField.ConfigurableActionStruct._config
protected

Definition at line 198 of file _configurableActionStructField.py.

◆ _config_

weakref lsst.pex.config.configurableActions._configurableActionStructField.ConfigurableActionStruct._config_ .ref
staticprotected

Definition at line 146 of file _configurableActionStructField.py.

◆ _field [1/2]

ConfigurableActionStructField lsst.pex.config.configurableActions._configurableActionStructField.ConfigurableActionStruct._field
staticprotected

Definition at line 148 of file _configurableActionStructField.py.

◆ _field [2/2]

lsst.pex.config.configurableActions._configurableActionStructField.ConfigurableActionStruct._field
protected

Definition at line 200 of file _configurableActionStructField.py.

◆ _history

list lsst.pex.config.configurableActions._configurableActionStructField.ConfigurableActionStruct._history [tuple]
staticprotected

Definition at line 149 of file _configurableActionStructField.py.

◆ remove

lsst.pex.config.configurableActions._configurableActionStructField.ConfigurableActionStruct.remove = ConfigurableActionStructRemover()
static

Definition at line 153 of file _configurableActionStructField.py.

◆ update

lsst.pex.config.configurableActions._configurableActionStructField.ConfigurableActionStruct.update = ConfigurableActionStructUpdater()
static

Definition at line 152 of file _configurableActionStructField.py.


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