Config¶
- class lsst.daf.butler.Config(other: str | ParseResult | ResourcePath | Path | Config | Mapping[str, Any] | None = None)¶
- Bases: - MutableMapping- Implements a datatype that is used by - Butlerfor configuration.- It is essentially a - dictwith key/value pairs, including nested dicts (as values). In fact, it can be initialized with a- dict. This is explained next:- Config extends the - dictapi so that hierarchical values may be accessed with delimited notation or as a tuple. If a string is given the delimiter is picked up from the first character in that string. For example,- foo.getValue(".a.b.c"),- foo["a"]["b"]["c"],- foo["a", "b", "c"],- foo[".a.b.c"], and- foo["/a/b/c"]all achieve the same outcome. If the first character is alphanumeric, no delimiter will be used.- foo["a.b.c"]will be a single key- a.b.cas will- foo[":a.b.c"]. Unicode characters can be used as the delimiter for distinctiveness if required.- If a key in the hierarchy starts with a non-alphanumeric character care should be used to ensure that either the tuple interface is used or a distinct delimiter is always given in string form. - Finally, the delimiter can be escaped if it is part of a key and also has to be used as a delimiter. For example, - foo[r".a.b\.c"]results in a two element hierarchy of- aand- b.c. For hard-coded strings it is always better to use a different delimiter in these cases.- Note that adding a multi-level key implicitly creates any nesting levels that do not exist, but removing multi-level keys does not automatically remove empty nesting levels. As a result: - >>> c = Config() >>> c[".a.b"] = 1 >>> del c[".a.b"] >>> c["a"] Config({'a': {}}) - Storage formats supported: - yaml: read and write is supported. 
- json: read and write is supported but no - !includedirective.
 - Parameters:
- otherlsst.resources.ResourcePathorConfigordict
- Other source of configuration, can be: 
 
- other
 - Attributes Summary - Key used to indicate that another config should be included at this part of the hierarchy. - Package to search for default configuration data. - Methods Summary - asArray(name)- Get a value as an array. - clear()- copy()- dump([output, format])- Write the config to an output stream. - dumpToUri(uri[, updateFile, ...])- Write the config to location pointed to by given URI. - fromString(string[, format])- Create a new Config instance from a serialized string. - fromYaml(string)- Create a new Config instance from a YAML string. - get(k[,d])- items()- keys()- merge(other)- Merge another Config into this one. - nameTuples([topLevelOnly])- Get tuples representing the name hierarchies of all keys. - names([topLevelOnly, delimiter])- Get a delimited name of all the keys in the hierarchy. - pop(k[,d])- If key is not found, d is returned if given, otherwise KeyError is raised. - popitem()- as a 2-tuple; but raise KeyError if D is empty. - ppprint()- Return config as formatted readable string. - setdefault(k[,d])- toDict()- update(other)- updateParameters(configType, config, full[, ...])- Update specific config parameters. - values()- Attributes Documentation - includeKey: ClassVar[str] = 'includeConfigs'¶
- Key used to indicate that another config should be included at this part of the hierarchy. 
 - resourcesPackage: str = 'lsst.daf.butler'¶
- Package to search for default configuration data. The resources themselves will be within a - configsresource hierarchy.
 - Methods Documentation - asArray(name: str | Sequence[str]) Sequence[Any]¶
- Get a value as an array. - May contain one or more elements. - Parameters:
- namestr
- Key to use to retrieve value. 
 
- name
- Returns:
- arraycollections.abc.Sequence
- The value corresponding to name, but guaranteed to be returned as a list with at least one element. If the value is a - Sequence(and not a- str) the value itself will be returned, else the value will be the first element.
 
- array
 
 - clear() None. Remove all items from D.¶
 - dump(output: IO | None = None, format: str = 'yaml') str | None¶
- Write the config to an output stream. - Parameters:
- Returns:
 
 - dumpToUri(uri: str | ParseResult | ResourcePath | Path, updateFile: bool = True, defaultFileName: str = 'butler.yaml', overwrite: bool = True) None¶
- Write the config to location pointed to by given URI. - Currently supports ‘s3’ and ‘file’ URI schemes. - Parameters:
- uri: `lsst.resources.ResourcePathExpression`
- URI of location where the Config will be written. 
- updateFilebool, optional
- If True and uri does not end on a filename with extension, will append - defaultFileNameto the target uri. True by default.
- defaultFileNamebool, optional
- The file name that will be appended to target uri if updateFile is True and uri does not end on a file with an extension. 
- overwritebool, optional
- If True the configuration will be written even if it already exists at that location. 
 
 
 - classmethod fromString(string: str, format: str = 'yaml') Config¶
- Create a new Config instance from a serialized string. 
 - 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¶
 - merge(other: Mapping) None¶
- Merge another Config into this one. - Like - Config.update(), but will add keys & values from other that DO NOT EXIST in self.- Keys and values that already exist in self will NOT be overwritten. 
 - nameTuples(topLevelOnly: bool = False) list[tuple[str, ...]]¶
- Get tuples representing the name hierarchies of all keys. - The tuples returned from this method are guaranteed to be usable to access items in the configuration object. 
 - names(topLevelOnly: bool = False, delimiter: str | None = None) list[str]¶
- Get a delimited name of all the keys in the hierarchy. - The values returned from this method are guaranteed to be usable to access items in the configuration object. - Parameters:
- topLevelOnlybool, optional
- If False, the default, a full hierarchy of names is returned. If True, only the top level are returned. 
- delimiterstr, optional
- Delimiter to use when forming the keys. If the delimiter is present in any of the keys, it will be escaped in the returned names. If - Nonegiven a delimiter will be automatically provided. The delimiter can not be alphanumeric.
 
- topLevelOnly
- Returns:
- Raises:
- ValueError:
- The supplied delimiter is alphanumeric. 
 
 - Notes - This is different than the built-in method - dict.keys, which will return only the first level keys.
 - pop(k[, d]) v, remove specified key and return the corresponding value.¶
- If key is not found, d is returned if given, otherwise KeyError is raised. 
 - popitem() (k, v), remove and return some (key, value) pair¶
- as a 2-tuple; but raise KeyError if D is empty. 
 - ppprint() str¶
- Return config as formatted readable string. - Returns:
- sstr
- A prettyprint formatted string representing the config 
 
- s
 - Examples - use: - pdb> print(myConfigObject.ppprint())
 - setdefault(k[, d]) D.get(k,d), also set D[k]=d if k not in D¶
 - toDict() dict[str, Any]¶
- Convert a - Configto a standalone hierarchical- dict.- Returns:
 - Notes - This can be useful when passing a Config to some code that expects native Python types. 
 - update(other: Mapping[str, Any]) None¶
- Update config from other - Configor- dict.- Like - dict.update(), but will add or modify keys in nested dicts, instead of overwriting the nested dict entirely.- Examples - >>> c = Config({"a": {"b": 1}}) >>> c.update({"a": {"c": 2}}) >>> print(c) {'a': {'b': 1, 'c': 2}} - >>> foo = {"a": {"b": 1}} >>> foo.update({"a": {"c": 2}}) >>> print(foo) {'a': {'c': 2}} 
 - static updateParameters(configType: type[lsst.daf.butler.core.config.ConfigSubset], config: Config, full: Config, toUpdate: dict[str, Any] | None = None, toCopy: Sequence[str | Sequence[str]] | None = None, overwrite: bool = True, toMerge: Sequence[str | Sequence[str]] | None = None) None¶
- Update specific config parameters. - Allows for named parameters to be set to new values in bulk, and for other values to be set by copying from a reference config. - Assumes that the supplied config is compatible with - configTypeand will attach the updated values to the supplied config by looking for the related component key. It is assumed that- configand- fullare from the same part of the configuration hierarchy.- Parameters:
- configTypeConfigSubset
- Config type to use to extract relevant items from - config.
- configConfig
- A - Configto update. Only the subset understood by the supplied- ConfigSubsetwill be modified. Default values will not be inserted and the content will not be validated since mandatory keys are allowed to be missing until populated later by merging.
- fullConfig
- A complete config with all defaults expanded that can be converted to a - configType. Read-only and will not be modified by this method. Values are read from here if- toCopyis defined.- Repository-specific options that should not be obtained from defaults when Butler instances are constructed should be copied from - fullto- config.
- toUpdatedict, optional
- A - dictdefining the keys to update and the new value to use. The keys and values can be any supported by- Configassignment.
- toCopytuple, optional
- tupleof keys whose values should be copied from- fullinto- config.
- overwritebool, optional
- If - False, do not modify a value in- configif the key already exists. Default is always to overwrite.
- toMergetuple, optional
- Keys to merge content from full to config without overwriting pre-existing values. Only works if the key refers to a hierarchy. The - overwriteflag is ignored.
 
- configType
- Raises:
- ValueError
- Neither - toUpdate,- toCopynor- toMergewere defined.
 
 
 - values() an object providing a view on D's values¶