loader

class invoke.loader.Loader(config: Config | None = None)

Abstract class defining how to find/import a session’s base Collection.

New in version 1.0.

__init__(config: Config | None = None) None

Set up a new loader with some Config.

Parameters:

config – An explicit Config to use; it is referenced for loading-related config options. Defaults to an anonymous Config() if none is given.

find(name: str) ModuleSpec | None

Implementation-specific finder method seeking collection name.

Must return a ModuleSpec valid for use by importlib, which is typically a name string followed by the contents of the 3-tuple returned by importlib.module_from_spec (name, loader, origin.)

For a sample implementation, see FilesystemLoader.

New in version 1.0.

load(name: str | None = None) Tuple[module, str]

Load and return collection module identified by name.

This method requires a working implementation of find in order to function.

In addition to importing the named module, it will add the module’s parent directory to the front of sys.path to provide normal Python import behavior (i.e. so the loaded module may load local-to-it modules or packages.)

Returns:

Two-tuple of (module, directory) where module is the collection-containing Python module object, and directory is the string path to the directory the module was found in.

New in version 1.0.

class invoke.loader.FilesystemLoader(start: str | None = None, **kwargs: Any)

Loads Python files from the filesystem (e.g. tasks.py.)

Searches recursively towards filesystem root from a given start point.

New in version 1.0.

__init__(start: str | None = None, **kwargs: Any) None

Set up a new loader with some Config.

Parameters:

config – An explicit Config to use; it is referenced for loading-related config options. Defaults to an anonymous Config() if none is given.

find(name: str) ModuleSpec | None

Implementation-specific finder method seeking collection name.

Must return a ModuleSpec valid for use by importlib, which is typically a name string followed by the contents of the 3-tuple returned by importlib.module_from_spec (name, loader, origin.)

For a sample implementation, see FilesystemLoader.

New in version 1.0.