LSSTApplications
17.0+124,17.0+14,17.0+73,18.0.0+37,18.0.0+80,18.0.0-4-g68ffd23+4,18.1.0-1-g0001055+12,18.1.0-1-g03d53ef+5,18.1.0-1-g1349e88+55,18.1.0-1-g2505f39+44,18.1.0-1-g5315e5e+4,18.1.0-1-g5e4b7ea+14,18.1.0-1-g7e8fceb+4,18.1.0-1-g85f8cd4+48,18.1.0-1-g8ff0b9f+4,18.1.0-1-ga2c679d+1,18.1.0-1-gd55f500+35,18.1.0-10-gb58edde+2,18.1.0-11-g0997b02+4,18.1.0-13-gfe4edf0b+12,18.1.0-14-g259bd21+21,18.1.0-19-gdb69f3f+2,18.1.0-2-g5f9922c+24,18.1.0-2-gd3b74e5+11,18.1.0-2-gfbf3545+32,18.1.0-26-g728bddb4+5,18.1.0-27-g6ff7ca9+2,18.1.0-3-g52aa583+25,18.1.0-3-g8ea57af+9,18.1.0-3-gb69f684+42,18.1.0-3-gfcaddf3+6,18.1.0-32-gd8786685a,18.1.0-4-gf3f9b77+6,18.1.0-5-g1dd662b+2,18.1.0-5-g6dbcb01+41,18.1.0-6-gae77429+3,18.1.0-7-g9d75d83+9,18.1.0-7-gae09a6d+30,18.1.0-9-gc381ef5+4,w.2019.45
LSSTDataManagementBasePackage
|
Functions | |
def | makeConfigClass (ctrl, name=None, base=Config, doc=None, module=None, cls=None) |
def | wrap (ctrl) |
Variables | |
Control | |
makeControl | |
readControl | |
setDefaults | |
validate | |
def pex.config.wrap.makeConfigClass | ( | ctrl, | |
name = None , |
|||
base = Config , |
|||
doc = None , |
|||
module = None , |
|||
cls = None |
|||
) |
Create a `~lsst.pex.config.Config` class that matches a C++ control object class. See the `wrap` decorator as a convenient interface to ``makeConfigClass``. Parameters ---------- ctrl : class C++ control class to wrap. name : `str`, optional Name of the new config class; defaults to the ``__name__`` of the control class with ``'Control'`` replaced with ``'Config'``. base : `lsst.pex.config.Config`-type, optional Base class for the config class. doc : `str`, optional Docstring for the config class. module : object, `str`, `int`, or `None` optional Either a module object, a string specifying the name of the module, or an integer specifying how far back in the stack to look for the module to use: 0 is the immediate caller of `~lsst.pex.config.wrap`. This will be used to set ``__module__`` for the new config class, and the class will also be added to the module. Ignored if `None` or if ``cls`` is not `None`. Defaults to None in which case module is looked up from the module of ctrl. cls : class An existing config class to use instead of creating a new one; name, base doc, and module will be ignored if this is not `None`. Notes ----- To use ``makeConfigClass``, write a control object in C++ using the ``LSST_CONTROL_FIELD`` macro in ``lsst/pex/config.h`` (note that it must have sensible default constructor): .. code-block:: cpp // myHeader.h struct InnerControl { LSST_CONTROL_FIELD(wim, std::string, "documentation for field 'wim'"); }; struct FooControl { LSST_CONTROL_FIELD(bar, int, "documentation for field 'bar'"); LSST_CONTROL_FIELD(baz, double, "documentation for field 'baz'"); LSST_NESTED_CONTROL_FIELD(zot, myWrappedLib, InnerControl, "documentation for field 'zot'"); FooControl() : bar(0), baz(0.0) {} }; You can use ``LSST_NESTED_CONTROL_FIELD`` to nest control objects. Wrap those control objects as you would any other C++ class, but make sure you include ``lsst/pex/config.h`` before including the header file where the control object class is defined. Next, in Python: .. code-block:: py import lsst.pex.config import myWrappedLib InnerConfig = lsst.pex.config.makeConfigClass(myWrappedLib.InnerControl) FooConfig = lsst.pex.config.makeConfigClass(myWrappedLib.FooControl) This does the following things: - Adds ``bar``, ``baz``, and ``zot`` fields to ``FooConfig``. - Set ``FooConfig.Control`` to ``FooControl``. - Adds ``makeControl`` and ``readControl`` methods to create a ``FooControl`` and set the ``FooConfig`` from the ``FooControl``, respectively. - If ``FooControl`` has a ``validate()`` member function, a custom ``validate()`` method will be added to ``FooConfig`` that uses it. All of the above are done for ``InnerConfig`` as well. Any field that would be injected that would clash with an existing attribute of the class is be silently ignored. This allows you to customize fields and inherit them from wrapped control classes. However, these names are still be processed when converting between config and control classes, so they should generally be present as base class fields or other instance attributes or descriptors. While ``LSST_CONTROL_FIELD`` will work for any C++ type, automatic `~lsst.pex.config.Config` generation only supports ``bool``, ``int``, ``std::int64_t``, ``double``, and ``std::string`` fields, along with ``std::list`` and ``std::vectors`` of those types. See also -------- wrap
Definition at line 56 of file wrap.py.
def pex.config.wrap.wrap | ( | ctrl | ) |
Decorator that adds fields from a C++ control class to a `lsst.pex.config.Config` class. Parameters ---------- ctrl : object The C++ control class. Notes ----- See `makeConfigClass` for more information. This `wrap` decorator is equivalent to calling `makeConfigClass` with the decorated class as the ``cls`` argument. Examples -------- Use `wrap` like this:: @wrap(MyControlClass) class MyConfigClass(Config): pass See also -------- makeConfigClass
Definition at line 302 of file wrap.py.