ensembl.vep.config.parser package#
Readers for each configuration source.
Submodules#
ensembl.vep.config.parser.cli module#
Build an argparse surface from the section declarations.
Each action uses default=argparse.SUPPRESS so omitted flags stay absent from the parsed
namespace. That keeps them distinct from values read from a file or the environment.
- ensembl.vep.config.parser.cli.add_section_arguments(parser, section_type)[source]#
Add every option a section declares to a parser, as its own argument group.
- ensembl.vep.config.parser.cli.build_parser(prog, description, section_types)[source]#
Return a parser exposing exactly the options the given sections declare.
- Raises:
ValueError – If two of the sections declare the same flag.
- Return type:
ArgumentParser
- ensembl.vep.config.parser.cli.check_no_flag_collisions(section_types)[source]#
Raise if two of the given sections declare the same flag.
output_filemeans the annotation output torun, the report tostatsand the explanation toexplain; that only matters when one command reads two such sections. Reported here because argparse’s own message names neither section.- Raises:
ValueError – If a flag is declared by more than one of them.
- ensembl.vep.config.parser.cli.destination(section_name, field_name)[source]#
Return the parsed-namespace key one section’s option is read back from.
Namespaced by section because two sections of one command may declare the same field name –
formatis the input format tosourceand the report format tostats– and a bare field name would land one value in both.- Return type:
str
- ensembl.vep.config.parser.cli.parse_args(parser, argv, section_types)[source]#
Parse command-line arguments into a sparse section -> field -> value mapping.
- Returns:
- Only the options actually present on the command line, so a caller can
distinguish “not given” from “given the default value”.
- Return type:
dict[str,dict[str,object]]
ensembl.vep.config.parser.common module#
Helpers shared by the command-line, environment and file readers.
- ensembl.vep.config.parser.common.flag_for(field_name, spec)[source]#
Return the long flag spelling for one option, without the leading dashes.
Flags keep underscores, so
--input_filematches legacy VEP and a legacy config file needs no key translation.- Return type:
str
- ensembl.vep.config.parser.common.option_spellings(field_name, spec)[source]#
Return every long spelling that sets one option: its field name, flag and synonyms.
- Return type:
tuple[str,...]
- ensembl.vep.config.parser.common.resolve_option(key, value, section_types)[source]#
Resolve a flat key and its value to the section, field and value they set.
A key naming one of an option’s constants (
--vcffor--output_format vcf) sets that constant, whatever value came with it: the flag carries the value, so a config file writingvcf 1means the same asvcf.- Parameters:
key (
str) – The key as written, with or without leading dashes.value (
object) – The value given with it, ignored for a constant flag.section_types (
tuple[type[ConfigSection],...]) – The sections in play.
- Returns:
- (section name, field name, value), or None if no section
declares the key.
- Return type:
tuple[str,str,object] |None
- ensembl.vep.config.parser.common.resolve_option_key(key, section_types)[source]#
Resolve a flat option key to the section and field that declare it.
- Parameters:
key (
str) – The key as written, with or without leading dashes.section_types (
tuple[type[ConfigSection],...]) – The sections in play.
- Returns:
(section name, field name), or None if no section declares it.
- Return type:
tuple[str,str] |None
ensembl.vep.config.parser.config module#
Reading configuration from a file.
TOML is the native format and its tables map onto section names. A file with no TOML table is read
as a Perl VEP config file, the way Perl VEP’s own read_config_from_file reads it, so a config
file from an existing VEP install works unchanged. Legacy keys are flat, and are resolved to
sections by looking up which one declares each option.
- ensembl.vep.config.parser.config.read_config_file(path, section_types)[source]#
Read a configuration file, as TOML if it is TOML-shaped and as legacy config otherwise.
A file is TOML if it has a
[table]header or parses as TOML with at least one table. A syntax error in such a file is an error, not a cue to reread it as legacy config.- Parameters:
path (
Path) – The file to read.section_types (
tuple[type[ConfigSection],...]) – The sections in play.
- Returns:
The options the file sets, coerced to their declared types.
- Return type:
dict[str,dict[str,object]]- Raises:
FileNotFoundError – If
pathdoes not exist.ValueError – If a TOML file has a syntax error, or a value is invalid for its option.
- ensembl.vep.config.parser.config.read_legacy_config_file(path, section_types)[source]#
Read a Perl VEP config file as Perl VEP’s
read_config_from_filedoes.A line is a comment only if it starts with
#. The key and value are separated by any run of whitespace, a leading dash on the key is dropped, and quotes are removed from the value with the spaces inside them kept. The first occurrence of a repeated key wins, except for an option declaredrepeatable(Perl’scustomandplugin), which accumulates one item per line.option = valueis accepted as well.- Parameters:
path (
Path) – The file to read.section_types (
tuple[type[ConfigSection],...]) – The sections in play.
- Returns:
- The options the file sets, grouped by section and coerced. Unrecognised keys
are ignored: a legacy config carries options this implementation has not grown yet.
- Return type:
dict[str,dict[str,object]]- Raises:
ValueError – If a value is of the wrong type or not one of the option’s choices.
ensembl.vep.config.parser.env module#
Reading configuration from the environment.
- ensembl.vep.config.parser.env.default_env_name(section, field_name)[source]#
Return the environment variable an option is read from, e.g. ENSEMBL_VEP_CORPUS_FUZZ.
- Return type:
str
- ensembl.vep.config.parser.env.read_environment(section_types, environ=None)[source]#
Read whatever the environment sets, for the given sections.
- Parameters:
section_types (
tuple[type[ConfigSection],...]) – The sections in play.environ (
dict[str,str] |None, default:None) – Environment to read, or None foros.environ.
- Returns:
The options the environment sets, coerced to their declared types.
- Return type:
dict[str,dict[str,object]]- Raises:
ValueError – If a value is not of its declared type or not one of its choices.