id_translation.toml.meta#

TOML configuration metadata types.

Classes

BaseMetadata([versions, created])

Base implementation for Metadata types.

ConfigMetadata(main, extra_fetchers, clazz, ...)

Metadata pertaining to how a Translator instance was initialized from TOML configuration.

EnvConf([allow_interpolation, allow_blank, ...])

Control environment-variable interpolation.

EquivalenceConf([python_version, extra_packages])

Determines how equivalence between configuration files is determined.

Metaconf([env, equivalence])

Python representation of metaconf.toml file.

class BaseMetadata(versions=None, created=None)[source]#

Bases: ABC

Base implementation for Metadata types.

Parameters:
  • versions – Versions, e.g. {'python': '3.11.11'`, 'your-package': '1.0.0'}.

  • created – The time at which the metadata was originally created.

classmethod from_json(s)[source]#

Create BaseMetadata from a JSON string s.

classmethod get_package_versions(extra_packages)[source]#

Extract package versions using importlib.metadata.

is_equivalent(other)[source]#

Compute equivalency with other.

Parameters:

other – Another metadata instance.

Returns:

A string reason_not_equivalent or an empty string.

to_dict()[source]#

Get a dict representation of this BaseMetadata.

to_json()[source]#

Get a dict representation of this BaseMetadata.

use_cached(metadata_path, max_age)[source]#

Check status of stored metadata config based a desired configuration self.

Parameters:
  • metadata_path – Path of stored metadata.

  • max_age – Maximum age of stored metadata. Pass zero to force recreation. Smaller than zero = never expire.

Returns:

A tuple (True, expires_at, None) or (False, reason, reason_type).

class ConfigMetadata(main, extra_fetchers, clazz, metaconf, **kwargs)[source]#

Bases: BaseMetadata

Metadata pertaining to how a Translator instance was initialized from TOML configuration.

Equivalence:

Configs are equivalent if and only if…

  • They have the same top-level dependency versions, and

  • Use the same fully qualified class name, and

  • The main configuration is equal after parsing, and

  • They have the same number of auxiliary (“extra”) fetcher configurations, and

  • All auxiliary fetcher configurations are equal after parsing.

The Metaconf is not explicitly included in the equivalence check, but changing it will invalidate cached instances. Environment variable changes may also invalidate the cache if EnvConf.allow_interpolation is set and interpolations such as ${VAR} are present.

Parameters:
  • main – Absolute path and fingerprint of the main translation configuration.”

  • extra_fetchers – Absolute path and fingerprint of configuration files for auxiliary fetchers.

  • clazz – String representation of the class type.

  • metaconf – A Metaconf instance that determines, among other things, how other config paths are processed.

  • kwargs – Forwarded to base class.

static from_toml_paths(path, extra_fetchers, clazz)[source]#

Convenience function for creating ConfigMetadata instances.

class EnvConf(allow_interpolation=True, allow_blank=False, allow_nested=False)[source]#

Bases: object

Control environment-variable interpolation.

All keys are forwarded to load_toml_file().

allow_blank = False#
allow_interpolation = True#
allow_nested = False#
classmethod from_dict(config)[source]#

Construct environment interpolation configuration object from a dict.

Parameters:

config – Dict representation of a EnvConf to consume.

Returns:

A new EnvConf instance.

class EquivalenceConf(python_version='{v.major}.{v.minor}.{v.micro}', extra_packages=<factory>)[source]#

Bases: object

Determines how equivalence between configuration files is determined.

extra_packages#

Additional package whose versions are used to determine ConfigMetadata equivalence.

classmethod from_dict(config)[source]#

Construct equivalence configuration object from a dict.

Parameters:

config – Dict representation of an EquivalenceConf to consume.

Returns:

A new EquivalenceConf instance.

python_version = '{v.major}.{v.minor}.{v.micro}'#

Used to format the 'python_version' version using v=sys.version_info.

class Metaconf(env=<factory>, equivalence=<factory>)[source]#

Bases: object

Python representation of metaconf.toml file.

The metaconf.toml file always lives next to the main configuration file. It determines how other configuration files are read and validated.

[env]
allow_interpolation = true
allow_nested = true
allow_blank = false

[equivalence]
# python_version = "{v.major}.{v.minor}"  # Uncomment to allow any patch version
extra_packages = ["bci-id-translation"]

The sample above comes from the rsundqvist/id-translation-project demo.

as_dict()[source]#

Return a dict representation of self.

env#

Controls how and if variable substitution (on the form ${VAR}) is performed. See EnvConf.

equivalence#

Controls how equivalence checks are performed. See EquivalenceConf.

classmethod from_dict(config)[source]#

Construct meta configuration object from a dict.

Parameters:

config – Dict representation of a Metaconf to consume.

Returns:

A new Metaconf instance.

classmethod from_path_or_default(path)[source]#

Read TOML configuration or return default configuration.