Composer#

class project_composer.compose.Composer(manifest, processors=[])[source]#

Bases: LoggerBase

Composer base implements everything about application module discovering and manifest loading.

Parameters:
  • manifest (string or pathlib.Path or dict or Manifest) –

    The Manifest source to load. It can be either:

    • A Manifest object, it will just be returned as it without any validation. You are responsible of its correctness;

    • A string for the file path to load in JSON or TOML format;

    • A Path object to the file to load in JSON or TOML format;

    • A Dictionnary which respect the manifest structure;

    Source file format are guessed from their file extension such as JSON for .json or TOML for .toml.

  • processors (list) – List of available composition processors classes.

_APPLICATION_MODULE_PYTHONPATH#

A template string to build the full Python path of founded class. It expected two variables parent and name, respectively the module path and the class name.

Type:

string

get_manifest(manifest)[source]#

Return loaded manifest object.

Parameters:

manifest (string or pathlib.Path or dict or Manifest) – The Manifest source to load.

Returns:

The manifest object loaded from given source.

Return type:

Manifest

set_syspaths(paths)[source]#

Append each item path to sys.path.

This won’t never append a same path twice.

Parameters:

paths (list) – A list of path to append.

get_application_base_module_path(name)[source]#

Return the Python path to the application base module.

Commonly this should be the __init__.py file from application directory.

Parameters:

name (string) – Module name.

Returns:

Module name prefixed with repository path if it is not empty else returns just the module name.

Return type:

string

get_module_path(name)[source]#

Return a Python path for a module name.

Parameters:

name (string) – Module name.

Returns:

Module name prefixed with repository path if it is not empty else returns just the module name.

Return type:

string

find_app_module(name)[source]#

Find a module (by its pythonpath) from application.

Parameters:

name (string) – Module pythonpath.

Returns:

Module object if found else None.

Return type:

object

_is_elligible_class(obj)[source]#

Find if given object is an enabled class for composition.

Criterias for eligibility are in order:

  • Object is a class;

  • Class is not named EnabledApplicationMarker;

  • Class got attribute _ENABLED_COMPOSABLE_APPLICATION which value is not None;

Parameters:

obj (object) – Object to check for eligibility.

Returns:

True if object is eligibile to criterias else False.

Return type:

boolean

_get_elligible_module_classes(path, module)[source]#

Get all elligible classes from a module.

Parameters:
  • path (string) – The Python path to a module used for reporting and logging messages.

  • module (object) – The module object where to find elligible classes.

Returns:

List of elligible classes objects.

Return type:

list

_scan_app_module(name)[source]#

Load an application module to get its options.

Parameters:

path (string) – The Python path to a module to check for.

Returns:

Application payload (name, dependencies and push_end options).

Return type:

dict

call_processor(name, method, **kwargs)[source]#

Execute a processor method.

Parameters:
  • name (string) – Processor name in registry.

  • method (string) – Processor method to execute.

  • **kwargs – Keyword arguments to pass to method if any.

Returns:

Content type depend from what processor method returns.

Return type:

object

resolve_collection(lazy=True)[source]#

Resolve collection with AppStore.

Keyword Arguments:

lazy (boolean) – If True, there won’t be any dependency order resolving and the application list will just be the collection with AppNode objects instead of name strings. If False, the resolving will be processed. Default is True.

Returns:

List of AppNode objects.

Return type:

list

check(lazy=True, printer=None)[source]#

Output some informations about given manifest, app resolving and processors.

It is strongly recommended that every checking is directly outputted. It means you should not build a list of messages to output at the end, instead each job should directly output what it has checked.

This is to ensure the debugging won’t hide what have been done before a critical error. Remember this method should be almost safe since it is for debugging.

Keyword Arguments:
  • lazy (boolean) – Wheither to use the lazy mode or not with composer resolver.

  • printer (callable) – A callable to use to output debugging informations. Default to builtin function utils.tree_printer.TreePrinter to benefit from the tree alike display.