Configuration converter¶
orion.core.worker.convert
– Parse and generate user script’s configuration¶
Given a file path infer which configuration file parser/emitter it corresponds to. Define Converter classes with a common interface for many popular configuration file types.
- Currently supported:
- YAML
- JSON
- See below, for configuration agnostic parsing
A GenericConverter is provided that tries and parses configuration files, regardless of their type, according to predefined Oríon’s markers.
-
class
orion.core.io.convert.
BaseConverter
[source]¶ Base class for configuration parsers/generators.
Attributes: - file_extensions : list of strings
Strings starting with ‘.’ which identify usually a file type as a common convention. For instance,
['.yml', '.yaml']
for YAML files.
Methods
generate
(filepath, data)Create a configuration file at filepath using dictionary data. get_state_dict
()Give state dict that can be used to reconstruct the converter parse
(filepath)Read dictionary out of the configuration file. set_state_dict
(state)Reset the converter based on previous state
-
class
orion.core.io.convert.
Converter
[source]¶ Class used to inject dependency on a configuration file parser/generator.
See also
Factory
metaclass andBaseConverter
interface.Methods
generate
(filepath, data)Create a configuration file at filepath using dictionary data. get_state_dict
()Give state dict that can be used to reconstruct the converter parse
(filepath)Read dictionary out of the configuration file. set_state_dict
(state)Reset the converter based on previous state
-
class
orion.core.io.convert.
GenericConverter
(regex='([\/]?[\w|\/|-]+)~([\+]?.*\)|\-|\>[A-Za-z_]\w*)', expression_prefix='')[source]¶ Generic converter for any configuration file type.
For each parameter dimension declared here, one must necessarily provide a
name
keyword inside the Dimension building expression.Implementation details: As this class is supposed to provide with a generic text parser, semantics are going to be tied to their consequent usage. A template document is going to be created on
parse
and filled with values on read. This template document consists the state of thisConverter
object.Dimension should be defined for instance as:
meaningful_name~uniform(0, 4)
Methods
generate
(filepath, data)Create a configuration file at filepath using dictionary data. get_state_dict
()Give state dict that can be used to reconstruct the converter parse
(filepath)Read dictionary out of the configuration file. set_state_dict
(state)Reset the converter based on previous state -
parse
(filepath)[source]¶ Read dictionary out of the configuration file.
Create a template for Python 3 string format and save it as this object’s state, by substituing ‘{1}’ wherever the pattern was matched. By default, the first matched group (1) corresponds with a dimension’s namespace.
Note
Namespace in substitution templates does not contain the first ‘/’.
Parameters: - filepath : str
Full path to the original user script’s configuration.
-
-
class
orion.core.io.convert.
JSONConverter
[source]¶ Converter for JSON files.
Methods
generate
(filepath, data)Create a configuration file at filepath using dictionary data. get_state_dict
()Give state dict that can be used to reconstruct the converter parse
(filepath)Read dictionary out of the configuration file. set_state_dict
(state)Reset the converter based on previous state
-
class
orion.core.io.convert.
YAMLConverter
[source]¶ Converter for YAML files.
Methods
generate
(filepath, data)Create a configuration file at filepath using dictionary data. get_state_dict
()Give state dict that can be used to reconstruct the converter parse
(filepath)Read dictionary out of the configuration file. set_state_dict
(state)Reset the converter based on previous state