|
def | __iter__ (self) |
|
def | keys (self) |
|
def | values (self) |
|
def | items (self) |
|
def | iteritems (self) |
|
def | itervalues (self) |
|
def | iterkeys (self) |
|
def | __contains__ (self, name) |
| Return True if the specified field exists in this config. More...
|
|
def | __new__ (cls, args, kw) |
|
def | __reduce__ (self) |
|
def | setDefaults (self) |
|
def | update (self, kw) |
|
def | load (self, filename, root="config") |
|
def | loadFromStream (self, stream, root="config", filename=None) |
|
def | save (self, filename, root="config") |
|
def | saveToStream (self, outfile, root="config") |
|
def | freeze (self) |
|
def | toDict (self) |
|
def | names (self) |
|
def | validate (self) |
|
def | formatHistory (self, name, kwargs) |
|
def | __setattr__ (self, attr, value, at=None, label="assignment") |
|
def | __delattr__ (self, attr, at=None, label="deletion") |
|
def | __eq__ (self, other) |
|
def | __ne__ (self, other) |
|
def | __str__ (self) |
|
def | __repr__ (self) |
|
def | compare (self, other, shortcut=True, rtol=1E-8, atol=1E-8, output=None) |
|
def | __setattr__ (cls, name, value) |
|
Base class for configuration (*config*) objects.
Notes
-----
A ``Config`` object will usually have several `~lsst.pex.config.Field`
instances as class attributes. These are used to define most of the base
class behavior.
``Config`` implements a mapping API that provides many `dict`-like methods,
such as `keys`, `values`, `items`, `iteritems`, `iterkeys`, and
`itervalues`. ``Config`` instances also support the ``in`` operator to
test if a field is in the config. Unlike a `dict`, ``Config`` classes are
not subscriptable. Instead, access individual fields as attributes of the
configuration instance.
Examples
--------
Config classes are subclasses of ``Config`` that have
`~lsst.pex.config.Field` instances (or instances of
`~lsst.pex.config.Field` subclasses) as class attributes:
>>> from lsst.pex.config import Config, Field, ListField
>>> class DemoConfig(Config):
... intField = Field(doc="An integer field", dtype=int, default=42)
... listField = ListField(doc="List of favorite beverages.", dtype=str,
... default=['coffee', 'green tea', 'water'])
...
>>> config = DemoConfig()
Configs support many `dict`-like APIs:
>>> config.keys()
['intField', 'listField']
>>> 'intField' in config
True
Individual fields can be accessed as attributes of the configuration:
>>> config.intField
42
>>> config.listField.append('earl grey tea')
>>> print(config.listField)
['coffee', 'green tea', 'water', 'earl grey tea']
Definition at line 674 of file config.py.
def lsst.pex.config.config.Config.compare |
( |
|
self, |
|
|
|
other, |
|
|
|
shortcut = True , |
|
|
|
rtol = 1E-8 , |
|
|
|
atol = 1E-8 , |
|
|
|
output = None |
|
) |
| |
Compare this configuration to another `~lsst.pex.config.Config` for
equality.
Parameters
----------
other : `lsst.pex.config.Config`
Other `~lsst.pex.config.Config` object to compare against this
config.
shortcut : `bool`, optional
If `True`, return as soon as an inequality is found. Default is
`True`.
rtol : `float`, optional
Relative tolerance for floating point comparisons.
atol : `float`, optional
Absolute tolerance for floating point comparisons.
output : callable, optional
A callable that takes a string, used (possibly repeatedly) to
report inequalities.
Returns
-------
isEqual : `bool`
`True` when the two `lsst.pex.config.Config` instances are equal.
`False` if there is an inequality.
See also
--------
lsst.pex.config.compareConfigs
Notes
-----
Unselected targets of `~lsst.pex.config.RegistryField` fields and
unselected choices of `~lsst.pex.config.ConfigChoiceField` fields
are not considered by this method.
Floating point comparisons are performed by `numpy.allclose`.
Definition at line 1324 of file config.py.
def lsst.pex.config.config.Config.loadFromStream |
( |
|
self, |
|
|
|
stream, |
|
|
|
root = "config" , |
|
|
|
filename = None |
|
) |
| |
Modify this Config in place by executing the Python code in the
provided stream.
Parameters
----------
stream : file-like object, `str`, or compiled string
Stream containing configuration override code.
root : `str`, optional
Name of the variable in file that refers to the config being
overridden.
For example, the value of root is ``"config"`` and the file
contains::
config.myField = 5
Then this config's field ``myField`` is set to ``5``.
**Deprecated:** For backwards compatibility, older config files
that use ``root="root"`` instead of ``root="config"`` will be
loaded with a warning printed to `sys.stderr`. This feature will be
removed at some point.
filename : `str`, optional
Name of the configuration file, or `None` if unknown or contained
in the stream. Used for error reporting.
See also
--------
lsst.pex.config.Config.load
lsst.pex.config.Config.save
lsst.pex.config.Config.saveFromStream
Definition at line 975 of file config.py.
def lsst.pex.config.config.Config.update |
( |
|
self, |
|
|
|
kw |
|
) |
| |
Update values of fields specified by the keyword arguments.
Parameters
----------
kw
Keywords are configuration field names. Values are configuration
field values.
Notes
-----
The ``__at`` and ``__label`` keyword arguments are special internal
keywords. They are used to strip out any internal steps from the
history tracebacks of the config. Do not modify these keywords to
subvert a `~lsst.pex.config.Config` instance's history.
Examples
--------
This is a config with three fields:
>>> from lsst.pex.config import Config, Field
>>> class DemoConfig(Config):
... fieldA = Field(doc='Field A', dtype=int, default=42)
... fieldB = Field(doc='Field B', dtype=bool, default=True)
... fieldC = Field(doc='Field C', dtype=str, default='Hello world')
...
>>> config = DemoConfig()
These are the default values of each field:
>>> for name, value in config.iteritems():
... print(f"{name}: {value}")
...
fieldA: 42
fieldB: True
fieldC: 'Hello world'
Using this method to update ``fieldA`` and ``fieldC``:
>>> config.update(fieldA=13, fieldC='Updated!')
Now the values of each field are:
>>> for name, value in config.iteritems():
... print(f"{name}: {value}")
...
fieldA: 13
fieldB: True
fieldC: 'Updated!'
Definition at line 880 of file config.py.