babelizer.metadata module

class babelizer.metadata.BabelMetadata(library=None, build=None, package=None, info=None, plugin=None, ci=None)

Bases: object

LOADERS = {'toml': <function parse>, 'yaml': <function safe_load>}
__init__(library=None, build=None, package=None, info=None, plugin=None, ci=None)

Metadata used by the babelizer to wrap a library.

Parameters
  • library (dict, optional) – Information about the library being babelized. Defaults to None.

  • build (dict, optional) – User-specified compiler flags. Defaults to None.

  • package (dict, optional) – Name and requirements to build the babelized library. Defaults to None.

  • info (dict, optional) – Descriptive information about the package. Defaults to None.

  • plugin (dict, optional) – Deprecated, use package. Defaults to None.

  • ci (dict, optional) – Information about how to set up continuous integration. Defaults to None.

as_cookiecutter_context()

Format metadata in cookiecutter context.

Returns

Metadata in cookiecutter context.

Return type

dict

dump(fp, fmt='yaml')

Write serialized metadata to a file.

Parameters
  • fp (file object) – File object for output.

  • fmt (str, optional) – [description]. Defaults to “yaml”.

format(fmt='yaml')

Serialize metadata to output format

Parameters

fmt (str, optional) – Output format. Defaults to “yaml”.

Returns

Serialized metadata.

format_toml()

Serialize metadata as TOML.

Returns

Serialized metadata as a TOML-formatted string

Return type

str

format_yaml()

Serialize metadata as YAML.

Returns

Serialized metadata as a YAML-formatted string

Return type

str

classmethod from_path(filepath)

Create an instance of BabelMetadata from a path-like object.

Parameters

filepath (str) – Path to a babelizer configuration file.

Returns

A BabelMetadata instance.

classmethod from_stream(stream, fmt='yaml')

Create an instance of BabelMetadata from a file-like object.

Parameters
  • stream (file object) – File object with a babelizer configuration

  • fmt (str, optional) – File format. Defaults to “yaml”.

Returns

A BabelMetadata instance.

get(section, value)

Get a metadata value from the given section.

Parameters
  • section (str) – Section name.

  • value (str) – Key name.

Returns

Metadata value.

static norm(config)

Ensure current style metadata are used in babelizer configuration.

Parameters

config (dict) – Metadata to babelize a library.

Returns

A dict of babelizer configuration metadata.

static parse_entry_point(specifier)

Parse an entry point specifier into its parts.

Parameters

specifier (str) – An entry-point specifier.

Returns

The parts of the entry point as (name, module, class).

Return type

tuple of str

Raises

ValidationError – If the entry point cannot be parsed.

Examples

>>> from babelizer.metadata import BabelMetadata
>>> BabelMetadata.parse_entry_point("Foo=bar:Baz")
('Foo', 'bar', 'Baz')
>>> BabelMetadata.parse_entry_point("bar:Baz")
Traceback (most recent call last):
,,,
babelizer.errors.ValidationError: bad entry point specifier (bar:Baz). specifier must be of the form name=module:class
static validate(config)

Ensure babelizer configuration metadata are valid.

Parameters

config (dict) – Metadata to babelize a library.

Raises

ValidationError – if metadata are not valid.

babelizer.metadata.validate_dict(meta, required=None, optional=None)

Validate babelizer configuration metadata.

Parameters
  • meta (dict) – Configuration metadata

  • required (dict, optional) – Required keys in configuration. Defaults to None.

  • optional (dict, optional) – Optional keys in configuration. Defaults to None.

Raises

ValidationError – Raised for invalid metadata