micropy.stubs.source

micropy.stubs.source

This module contains abstractions for handling stub sources and their location.

Functions

get_source(location, **kwargs)

Factory for StubSource Instance.

Classes

LocalStubSource(path, **kwargs)

Stub Source Subclass for local locations.

RemoteStubSource(name, **kwargs)

Stub Source for remote locations.

StubRepo(name, location, path, **kwargs)

Represents a remote repository for stubs.

StubSource(location[, log])

Abstract Base Class for Stub Sources.

class micropy.stubs.source.LocalStubSource(path, **kwargs)

Bases: micropy.stubs.source.StubSource

Stub Source Subclass for local locations.

Parameters

path (str) – Path to Stub Source

Returns

Instance of LocalStubSource

Return type

obj

class micropy.stubs.source.RemoteStubSource(name, **kwargs)

Bases: micropy.stubs.source.StubSource

Stub Source for remote locations.

Parameters

url (str) – URL to Stub Source

Returns

Instance of RemoteStubSource

Return type

obj

ready()

Retrieves and unpacks source.

Prepares remote stub resource by downloading and unpacking it into a temporary directory. This directory is removed on exit of the superclass context manager

Returns

StubSource.ready parent method

Return type

callable

class micropy.stubs.source.StubRepo(name, location, path, **kwargs)

Bases: object

Represents a remote repository for stubs.

Parameters
  • name (str) – Repo Name

  • location (str) – Valid url

  • ref (str) – path to repo definition file

classmethod from_json(content)

Create StubRepo Instances from JSON file.

Parameters

file_obj (str or bytes) – json content

Returns

iterable of created repos

get_url(path)

Returns formatted url to provided path.

Parameters

path (str) – path to format

Returns

formatted url

Return type

str

has_package(name)

Checks if package is available in repo.

Parameters

name (str) – name of package

Returns

True if package is available

Return type

bool

classmethod resolve_package(name)

Attempts to resolve package from all repos.

Parameters

name (str) – package to resolve

Raises

StubNotFound – Package could not be resolved

Returns

url to package

Return type

str

search(query)

Searches repository packages.

Parameters

query (str) – query to search by

Returns

List of matching results

Return type

[str]

class micropy.stubs.source.StubSource(location, log=None)

Bases: object

Abstract Base Class for Stub Sources.

ready(path=None, teardown=None)

Yields prepared Stub Source.

Allows StubSource subclasses to have a preperation method before providing a local path to itself.

Parameters
  • path (str, optional) – path to stub source. Defaults to location.

  • teardown (func, optional) – callback to execute on exit. Defaults to None.

Yields

Resolved PathLike object to stub source

micropy.stubs.source.get_source(location, **kwargs)

Factory for StubSource Instance.

Parameters

location (str) – PathLike object or valid URL

Returns

Either Local or Remote StubSource Instance

Return type

obj