Utilities

The galactic module.

It defines helper classes.

class Factory

The Factory class is used to register classes.

__init__() None

Initialise a Factory instance.

register(name: str, cls: type) None

Register a new class.

Parameters:
  • name (str) – The registered name

  • cls – The class

get(name: str) type

Get a class from its name.

Parameters:

name (str) – The registered name

Return type:

The class

create(name: str, *args: Any, **kwargs: Any) Any

Create an instance of a class given its registered name.

Parameters:
  • name (str) – The registered name

  • args (tuple) – Tuple of arguments

Keyword Arguments:

kwargs (dict <python:dict>) – Dictionary of named arguments

Return type:

A requested instance.

property classes: Dict[str, type]

Get the registered classes.

Returns:

A dictionary of (identifier, type) couple.

Return type:

Dict[str, type]

class Resource(label: str = '', explanation: str = '')

The Resource class represents informationn given by the data analyst.

It is designed to be mutable until the hash() function has been applied.

New in version 0.5.0.

__init__(label: str = '', explanation: str = '') None

Initialize a Resource instance.

Keyword Arguments:
  • label (str, optional) – An optional label.

  • explanation (str, optional) – An optional explanation in markdown text. The text will be sanitized by keeping only strong and emphasis markup.

property explanation: str

Get the explanation.

Returns:

The explanation.

Return type:

str

property label: str

Get the label.

Returns:

The label.

Return type:

str

detect_plugins(group: str = 'py_galactic_extension', name: Optional[str] = None) None

Detect plugins.

Keyword Arguments:
  • group (str) – The plugin group

  • name (str, optional) – The plugin name

add_yaml_class(tag: str, cls: Any, arguments: Optional[str] = None, params: Optional[List[str]] = None) None

Add a YAML class.

This function calls the add_yaml_constructor() function and the add_yaml_representer() function.

Parameters:
  • tag (str) – The YAML tag

  • cls (type) – The class

Keyword Arguments:
  • arguments (str, optional) – The name of the field that will be used to generate the list of unnamed arguments

  • params (List[str], optional) – The list of names of the keyword arguments

Deprecated since version 0.5.0: Use the galactic.yaml.YamlObject class

add_yaml_constructor(tag: str, cls: Any) None

Add a YAML constructor.

Parameters:
  • tag (str) – The YAML tag

  • cls (type) – The constructor

Deprecated since version 0.5.0: Use the galactic.yaml.YamlObject class

add_yaml_representer(tag: str, cls: Any, arguments: Optional[str] = None, params: Optional[List[str]] = None) None

Add a YAML representer.

Parameters:
  • tag (str) – The YAML tag

  • cls (type) – The class

Keyword Arguments:
  • arguments (str, optional) – The name of the field that will be used to generate the list of unnamed arguments

  • params (str, optional) – The list of names of the keyword arguments

Deprecated since version 0.5.0: Use the galactic.yaml.YamlObject class

extend(cls: type) Callable[[type], None]

Enable a class to be extended by another class.

Parameters:

cls (type) – The class to be extended.

New in version 0.5.0.

hash_iterable(iterable: Iterable[Hashable]) int

Hash an iterable of hashable values.

Parameters:

iterable (Iterable[Hashable]) – An iterable of hashable values.

Returns:

The hashed value of the iterable.

Return type:

int

New in version 0.5.0.