Registry¶
- class lsst.pex.config.Registry(configBaseType=<class 'lsst.pex.config.config.Config'>)¶
- Bases: - Mapping- A base class for global registries, which map names to configurables. - A registry acts like a read-only dictionary with an additional - registermethod to add targets. Targets in the registry are configurables (see Notes).- Parameters:
- configBaseTypelsst.pex.config.Config-type
- The base class for config classes in the registry. 
 
- configBaseType
 - Notes - A configurable is a callable with call signature - (config, *args)Configurables typically create an algorithm or are themselves the algorithm. Often configurables are- lsst.pipe.base.Tasksubclasses, but this is not required.- A - Registryhas these requirements:- All configurables added to a particular registry have the same call signature. 
- All configurables in a registry typically share something important in common. For example, all configurables in - psfMatchingRegistryreturn a PSF matching class that has a- psfMatchmethod with a particular call signature.
 - Examples - This examples creates a configurable class - Fooand adds it to a registry. First, creating the configurable:- >>> from lsst.pex.config import Registry, Config >>> class FooConfig(Config): ... val = Field(dtype=int, default=3, doc="parameter for Foo") ... >>> class Foo: ... ConfigClass = FooConfig ... def __init__(self, config): ... self.config = config ... def addVal(self, num): ... return self.config.val + num ... - Next, create a - Registryinstance called- registryand register the- Fooconfigurable under the- "foo"key:- >>> registry = Registry() >>> registry.register("foo", Foo) >>> print(list(registry.keys())) ["foo"] - Now - Foois conveniently accessible from the registry itself.- Finally, use the registry to get the configurable class and create an instance of it: - >>> FooConfigurable = registry["foo"] >>> foo = FooConfigurable(FooConfigurable.ConfigClass()) >>> foo.addVal(5) 8 - Methods Summary - get(k[,d])- items()- keys()- makeField(doc[, default, optional, multi])- Create a - RegistryFieldconfiguration field from this registry.- register(name, target[, ConfigClass])- Add a new configurable target to the registry. - values()- Methods Documentation - get(k[, d]) D[k] if k in D, else d. d defaults to None.¶
 - items() a set-like object providing a view on D's items¶
 - keys() a set-like object providing a view on D's keys¶
 - makeField(doc, default=None, optional=False, multi=False)¶
- Create a - RegistryFieldconfiguration field from this registry.- Parameters:
- docstr
- A description of the field. 
- defaultobject, optional
- The default target for the field. 
- optionalbool, optional
- When - False,- lsst.pex.config.Config.validatefails if the field’s value is- None.
- multibool, optional
- A flag to allow multiple selections in the - RegistryFieldif- True.
 
- doc
- Returns:
- fieldlsst.pex.config.RegistryField
- RegistryFieldConfiguration field.
 
- field
 
 - register(name, target, ConfigClass=None)¶
- Add a new configurable target to the registry. - Parameters:
- namestr
- Name that the - targetis registered under. The target can be accessed later with- dict-like patterns using- nameas the key.
- targetobj
- A configurable type, usually a subclass of - lsst.pipe.base.Task.
- ConfigClasslsst.pex.config.Config-type, optional
- A subclass of - lsst.pex.config.Configused to configure the configurable. If- Nonethen the configurable’s- ConfigClassattribute is used.
 
- name
- Raises:
- RuntimeError
- Raised if an item with - nameis already in the registry.
- AttributeError
- Raised if - ConfigClassis- Noneand- targetdoes not have a- ConfigClassattribute.
 
 - Notes - If - ConfigClassis provided then the- targetconfigurable is wrapped in a new object that forwards function calls to it. Otherwise the original- targetis stored.
 - values() an object providing a view on D's values¶