scd.config

This module contains all routines, related to scd’s configuration.

class scd.config.Config(configpath, version_scheme, config, extra_context)

Wrapper over parsed configuration data.

This wrapper provides methods for internal scd’s implementation.

You want to use this class to access configuration data.

Parameters:
  • configpath (str) – Path to the configuration file (can be relative).
  • or None version_scheme (str) – Explicit version scheme to use.
  • config (dict) – Parsed configuration.
  • str] extra_context (dict[str,) – Additional context to use in templates.
Raises:

ValueError – if configuration is not valid to schema.

project_directory

Absolute path to the directory with config file.

Returns:Absolute path to the directory.
Return type:str
static validate_schema(config)

Validate parsed content to comply with JSON Schema.

Parameters:config (dict) – Parsed configuration.
Returns:A list of errors, found during verification. If list is empty, everyting is valid.
Return type:list[str]
class scd.config.Parser(name, func)
func

Alias for field number 1

name

Alias for field number 0

class scd.config.V1Config(configpath, version_scheme, config, extra_context)

Implementation of Config for config version 1.

defaults

A mapping of default search/replace patterns from config file.

Returns:Raw mapping, as is.
Return type:dict[str, str]
files

A list of files defines in config file.

Returns:List of file instances
Return type:list[scd.files.File]
filter_files(required_groups, required_files)

Filter and return only those files which are required.

This uses groups and required_files parameter filtering.

Parameters:
  • required_groups (list[str]) – A list of mandatory groups
  • required_files (list[str]) – A list of mandatory files
Returns:

A list of files after filtering.

Return type:

list[scd.files.File]

groups

A list of groups defined in config file.

Returns:List of group names
Return type:list[str, str]
replacement_patterns

A mapping of replacement patterns (name/repl) from config file.

Returns:Raw mapping, as is.
Return type:dict[str, str]
search_patterns

A mapping of search patterns (name/pattern) from config file.

Returns:Raw mapping, as is.
Return type:dict[str, str]
version

Instance of scd.version.Version.

This instance is created based on data from config file.

Returns:Version
Return type:scd.version.Version
version_number

Base version number from config file.

Returns:Literal number from config
Return type:str
version_scheme

Scheme of the versioning from config file.

For example, it can be git_pep440.

Returns:Version scheme
Return type:str
scd.config.get_json_parser()

Function which detects what parser should be used for parsing JSONs.

It uses following logic: if simplejson is available, it would be used, otherwise default json will work.

Returns:JSON parser
Return type:Parser
scd.config.get_parsers()

Function to detect locally available parsers.

Returns:A list of available parsers for config files.
Return type:list[Parser]
scd.config.get_toml_parser()

Function which detects what parser should be used for parsing TOMLs.

It uses following logic: if toml is available, it would be used, otherwise None is returned.

Returns:TOML parser or None if nothing found.
Return type:Parser or None
scd.config.get_yaml_parser()

Function which detects what parser should be used for parsing YAMLs.

It uses following logic: if PyYAML is available, it would be used, otherwise it will try for ruamel.yaml.

Returns:YAML parser or None if nothing found.
Return type:Parser or None
scd.config.make_config(filename, version_scheme, content, extra_context)

Function to generate config based on incoming parameters.

This function does validation of config version.

Parameters:
  • filename (str) – Path to the configuration file (can be relative).
  • or None version_scheme (str) – Explicit version scheme to use.
  • content (dict) – Parsed configuration.
  • str] extra_context (dict[str,) – Additional context to use in templates.
Raises:

ValueError – if config version is not supported.

scd.config.parse(fileobj, version_scheme, extra_context)

Function which parses given file-like object with config data.

Parameters:
  • fileobj (file-like object) – Open file object for parsing.
  • or None version_scheme (str) – Explicit version scheme to use.
  • str] extra_context (dict[str,) – Additional context to use in templates.
Returns:

Parsed config

Return type:

Config

Raises:

ValueError – if not possible to parse config in any way.