micropy.stubs

micropy.stubs

This module contains all functionality relating to stub files/frozen modules and their usage in MicropyCli

Classes

StubManager([resource, repos])

Manages a collection of Stubs.

source

micropy.stubs.source

class micropy.stubs.StubManager(resource=None, repos=None)

Bases: object

Manages a collection of Stubs.

Kwargs:

resource (str): Default resource path repos ([StubRepo]): Repos for Remote Stubs

Raises
Returns

Instance of StubManager

Return type

object

add(location, dest=None, force=False)

Add stub(s) from source.

Parameters
  • source (str) – path to stub(s)

  • dest (str, optional) – path to copy stubs to. Defaults to self.resource

  • force (bool, optional) – overwrite existing stubs. Defaults to False.

Raises

TypeError – No resource or destination provided

from_stubber(path, dest)

Formats stubs generated by createstubs.py.

Creates a stub package from the stubs generated by createstubs.py. Also attempts to auto-resolve the stubs firmware name.

Parameters
  • path (str) – path to generated stubs

  • dest (str) – path to output

Returns

formatted stubs

Return type

str

is_valid(path)

Check if stub is valid without raising an exception.

Parameters

path (str) – path to stub

Returns

True if stub is valid

Return type

bool

iter_by_firmware(stubs=None)

Iterate stubs sorted by firmware.

Parameters

stubs ([Stub], optional) – Sublist of Stubs to iterate over. Defaults to None. If none, uses all installed stubs.

load_from(directory, *args, **kwargs)

Recursively loads stubs from a directory.

Parameters

directory (str) – Path to load from

Returns

List of loaded Stubs

Return type

[DeviceStub]

resolve_firmware(stub)

Resolves FirmwareStub for DeviceStub instance.

Parameters

stub (DeviceStub) – Stub to resolve

Returns

Instance of FirmwareStub NoneType: None if an appropriate

FirmwareStub cannot be found

Return type

FirmwareStub

resolve_subresource(stubs, subresource)

Resolve or Create StubManager from list of stubs.

Parameters
  • stubs ([Stub]) – List of stubs to use in subresource

  • subresource (str) – path to subresource

Returns

StubManager with subresource stubs

Return type

StubManager

search_remote(query)

Search all repositories for query.

Parameters

query (str) – query to search for

Returns

List of result tuples. The first item

is the package name, and the second is a bool based on whether the package is installed or not

Return type

[tuple]

validate(path, schema=None)

Validates given stub path against its schema.

Parameters
  • path (str) – path to validate

  • schema (str, optional) – Path to schema. Defaults to None. If None, the DeviceStub schema is used.

Raises
verbose_log(state)

Enable Stub logging to stdout.

Parameters

state (bool) – State to set

Returns

state

Return type

bool