micropy.project.modules

Project Modules.

Classes

DevPackagesModule(path, **kwargs)

Project Module for Dev Packages.

PackagesModule(path, **kwargs)

Project Module for handling requirements.

ProjectModule([parent, log])

Abstract Base Class for Project Modules.

StubsModule(stub_manager[, stubs])

Project module for handling Stubs.

TemplatesModule([templates, run_checks])

Project Templates Module.

HookProxy(name)

Proxy for Project Hooks.

class micropy.project.modules.TemplatesModule(templates=None, run_checks=True, **kwargs)

Bases: micropy.project.modules.modules.ProjectModule

Project Templates Module.

Generates and manages project files using the Projects context.

Parameters
  • templates (List[str]) – List of templates to use.

  • run_checks (bool, optional) – Whether to execute checks or not. Defaults to True.

property config

Template config.

Returns

Current configuration

Return type

dict

create()

Generates project files.

Returns

Project context

Return type

dict

load(**kwargs)

Loads project templates.

update()

Updates project files.

Returns

Project context

Return type

dict

class micropy.project.modules.PackagesModule(path, **kwargs)

Bases: micropy.project.modules.modules.ProjectModule

Project Module for handling requirements.

Parameters
  • path (str) – Path to create requirements file at.

  • packages (dict, optional) – Initial packages to use. Defaults to None.

add_from_file(path=None, dev=False, **kwargs)

Loads all requirements from file.

Parameters
  • path (Optional[Path]) – Path to file. Defaults to self.path.

  • dev (bool) – If dev requirements should be loaded. Defaults to False.

Return type

dict

add_package(package, dev=False, **kwargs)

Add requirement to project.

Parameters
  • package (str) – package name/spec

  • dev (bool, optional) – If dev requirements should be loaded. Defaults to False.

Returns

Dictionary of packages

Return type

dict

property cache

Project Cache.

Return type

Config

Returns

Project wide cache

property config

Config values specific to component.

Return type

Config

Returns

Component config.

property context

Context values specific to component.

Return type

Config

Returns

Context values.

create()

Create project files.

load(fetch=True, **kwargs)

Retrieves and stubs project requirements.

property path

Path to requirements file.

Returns

Path to file

Return type

Path

property pkg_path

Path to package data folder.

Returns

Path to folder.

Return type

Path

update()

Dumps packages to file at path.

class micropy.project.modules.StubsModule(stub_manager, stubs=None, **kwargs)

Bases: micropy.project.modules.modules.ProjectModule

Project module for handling Stubs.

Parameters
  • stub_manager (StubManager) – StubManager instance.

  • stubs (List[Type[Stub]], optional) – Initial Stubs to use.

add_stub(stub, **kwargs)

Add stub to project.

Parameters

stub (Stub) – Stub object to add

Returns

Project Stubs

Return type

[Stubs]

property config

Component specific config values.

Returns

Current config.

Return type

dict

property context

Component stub context.

create()

Create stub project files.

get_stub_tree(stubs)

Retrieve and order paths to base stubs and any stubs they depend on.

Parameters

stubs – List of Stub Items

Return type

Sequence[Path]

Returns

Paths to all stubs project depends on.

load(**kwargs)

Loads stubs from info file.

Parameters

stub_list (dict) – Dict of Stubs

property stubs

Component stubs.

Returns

List of stubs used in project.

Return type

List[micropy.stubs.Stub]

update()

Update current project stubs.

class micropy.project.modules.ProjectModule(parent=None, log=None)

Bases: object

Abstract Base Class for Project Modules.

add(component, *args, **kwargs)

Adds component.

Parameters

component (Any) – Component to add.

Return type

Any

abstract property config

Config values specific to component.

Return type

Union[dict, Config]

abstract create(*args, **kwargs)

Method to create component.

Return type

Any

classmethod hook(*args, **kwargs)

Decorator for creating a Project Hook.

Allows decorated method to be called from parent container.

Returns

Decorated function.

Return type

Callable

abstract load()

Method to load component.

property parent

Component Parent.

remove(component)

Removes component.

Parameters

component (Any) – Component to remove.

Return type

Any

resolve_hook(name)

Resolves appropriate hook for attribute name.

Parameters

name (str) – Attribute name to resolve hook for.

Returns

Callable Proxy for ProjectHook. NoneType: Name could not be resolved.

Return type

Optional[HookProxy]

abstract update()

Method to update component.

class micropy.project.modules.DevPackagesModule(path, **kwargs)

Bases: micropy.project.modules.packages.PackagesModule

Project Module for Dev Packages.

add_from_file(path=None, **kwargs)

Adds packages from file.

add_package(package, **kwargs)

Adds package.

create()

Creates component.

load(*args, **kwargs)

Load component.

class micropy.project.modules.HookProxy(name)

Bases: object

Proxy for Project Hooks.

Allows multiple project hooks with the same name by creating individual hooks for any defined permutations of kwargs.

This is accomplished by creating a unique name for each permutation proxying the original attribute name to the appropriate method determined from the provided kwargs.

Parameters

name (str) – Name of Proxy

add_instance(inst)

Add instance to Proxy.

Parameters

inst (Any) – Instance to add.

Return type

Any

add_method(func, **kwargs)

Adds method to Proxy.

Any kwargs provided will be used to generate the unique hook name.

Parameters

func (Callable) – Method to add

Example

>>> def test_func(arg1, kwarg1=False):
        pass
>>> self.add_method(test_func, {'kwarg1': False})
(test_func, '_hook__test_func__kwarg1_False')
Returns

Tuple containing method and unique hook name.

Return type

Tuple[Callable, str]

get()

Get initial method descriptor value.

Return type

~T

get_name(func, params=None)

Generates name from method and provided kwargs.

Parameters
  • func (Callable) – Method to generate name for.

  • params (Dict[Any, Any], optional) – Any kwargs to update the defaults with. Defaults to None. If none, uses default kwargs.

Returns

Generated name

Return type

str

is_descriptor()

Determine if initial method provided is a descriptor.

Return type

bool

resolve_proxy(**kwargs)

Resolves appropriate instance and method to proxy to.

If additional kwargs are provided and a proxy is not found, the function will continue to remove one kwarg and recurse into itself until either a match is found or it runs out of kwargs.

Return type

(typing.Type[micropy.project.modules.modules.ProjectModule], <class ‘str’>)

Returns

Instance and method name if resolved, otherwise None.