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
generate(filepath, data)[source]

Create a configuration file at filepath using dictionary data.

get_state_dict()[source]

Give state dict that can be used to reconstruct the converter

parse(filepath)[source]

Read dictionary out of the configuration file.

Parameters:
filepath : str

Full path to the original user script’s configuration.

set_state_dict(state)[source]

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 and BaseConverter 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 this Converter 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
generate(filepath, data)[source]

Create a configuration file at filepath using dictionary data.

get_state_dict()[source]

Give state dict that can be used to reconstruct the converter

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.

set_state_dict(state)[source]

Reset the converter based on previous state

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
generate(filepath, data)[source]

Create a configuration file at filepath using dictionary data.

parse(filepath)[source]

Read dictionary out of the configuration file.

Parameters:
file : str

Full path to the original user script’s configuration.

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
generate(filepath, data)[source]

Create a configuration file at filepath using dictionary data.

parse(filepath)[source]

Read dictionary out of the configuration file.

Parameters:
file : str

Full path to the original user script’s configuration.

orion.core.io.convert.infer_converter_from_file_type(config_path, regex=None, default_keyword='')[source]

Use filetype extension to infer and build the correct configuration file converter.