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_file means the annotation output to run, the report to stats and the explanation to explain; 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 – format is the input format to source and the report format to stats – 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_file matches 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 (--vcf for --output_format vcf) sets that constant, whatever value came with it: the flag carries the value, so a config file writing vcf 1 means the same as vcf.

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 path does 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_file does.

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 declared repeatable (Perl’s custom and plugin), which accumulates one item per line. option = value is 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 for os.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.