sierra.plugins.expdef.json.plugin#
Plugin for parsing and manipulating template input files in JSON format.
Classes#
Read, write, and modify parsed JSON files into experiment definitions. |
Functions#
|
Unickle all JSON modifications from the pickle file at the path. |
Module Contents#
- class sierra.plugins.expdef.json.plugin.ExpDef(input_fpath: pathlib.Path, write_config: sierra.core.experiment.definition.WriterConfig | None = None)[source]#

Read, write, and modify parsed JSON files into experiment definitions.
- attr_add(path: str, attr: str, value: str | int | float, noprint: bool = False) bool[source]#
Add the specified attribute to the element matching the specified path.
Only the FIRST element matching the specified path searching from the tree root is modified.
- Parameters:
path -- An expression uniquely identifying the element containing the attribute to add. The element must exist or an error will be raised.
attr -- An expression uniquely identifying the attribute to change within the enclosing element.
value -- The value to set the attribute to.
- attr_change(path: str, attr: str, value: str | int | float, noprint: bool = False) bool[source]#
Change the specified attribute of the element at the specified path.
Only the attribute of the FIRST element matching the specified path is changed.
- Parameters:
path -- An expression uniquely identifying the element containing the attribute to change. The element must exist or an error will be raised.
attr -- An expression uniquely identify the attribute to change within the enclosing element.
value -- The value to set the attribute to.
- attr_get(path: str, attr: str) str | int | float | None[source]#
Retrieve the specified attribute of the element at the specified path.
If it does not exist, None is returned.
- element_add(path: str, tag: str, attr: sierra.core.types.StrDict | None = None, allow_dup: bool = True, noprint: bool = False) bool[source]#
Add tag name as a child element of enclosing parent.
- abstract element_change(path: str, tag: str, value: str) bool[source]#
Change the specified tag of the element matching the specified path.
- Parameters:
path -- An expression uniquely identifying the element containing the tag to change. The element must exist or an error will be raised.
tag -- An expression uniquely identifying the tag to change within the enclosing element.
value -- The value to set the tag to.
- element_remove(path: str, tag: str, noprint: bool = False) bool[source]#
Remove the specified child
tagin the enclosing parent.If more than one tag matches, only one is removed. If the path does not exist, nothing is done.
- Parameters:
path -- An expression uniquely identifying the element containing the tag to remove. The element must exist or an error will be raised.
tag -- An expression uniquely identifying the tag to remove within the enclosing element.
- element_remove_all(path: str, tag: str, noprint: bool = False) bool[source]#
Remove the specified child tag(s) in the enclosing parent.
If more than one tag matches in the parent, all matching child tags are removed.
- Parameters:
path -- An expression uniquely identifying the element containing the tag(s) to remove. The element must exist or an error will be raised.
tag -- An expression uniquely identifying the tag to remove within the enclosing element.
- flatten(keys: list[str]) None[source]#
Flatten a nested JSON structure.
Recursively searches for each of the supplies keys, and replaces the values of all matching keys with the corresponding config files. The paths to the nested config files are assumed to be specified relative to the root/main config file, and to reside in subdirs/adjacent dirs to it.
- has_attr(path: str, attr: str) bool[source]#
Determine if the attribute uniquely identified by
pathexists.
- write(base_opath: pathlib.Path) None[source]#
Write the definition stored in the object to the filesystem.
- write_config_set(config: sierra.core.experiment.definition.WriterConfig) None[source]#
Set the write config for the object.
Provided for cases in which the configuration is dependent on whether or not certain tags are present in the input file.
- sierra.plugins.expdef.json.plugin.unpickle(fpath: pathlib.Path) sierra.core.experiment.definition.AttrChangeSet | sierra.core.experiment.definition.ElementAddList | None[source]#
Unickle all JSON modifications from the pickle file at the path.
You don't know how many there are, so go until you get an exception.