Configuration converter¶
Parse and generate user script’s configuration¶
Defines and instantiates a converter for configuration file types.
Given a file path infer which configuration file parser/emitter it corresponds to.
Define BaseConverter
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_extensionslist 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.
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
- abstract generate(filepath, data)[source]¶
Create a configuration file at filepath using dictionary data.
- 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 thisBaseConverter
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.
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 substituting ‘{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
- filepathstr
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.
parse
(filepath)Read dictionary out of the configuration file.