palgen.loaders.python
#
Module Contents#
- class palgen.loaders.python.Python(project_name=None)#
palgen.loaders.python.Python palgen.loaders.loader.Loader palgen.loaders.loader.Loader palgen.loaders.loader.Loader palgen.loaders.python.Python palgen.loaders.python.Python palgen.loaders.python.Python palgen.loaders.python.Python->palgen.loaders.loader.Loader Loads palgen extensions from Python modules (that is, files).
- Parameters:
project_name (
Optional[str], optional
) – Project name used to give extensions a proper import name. Defaults to None.
- __slots__ = ('project_name',)#
- ingest(sources)#
Ingests extensions from the given sources. This skips all files not ending in ‘.py’.
- Parameters:
sources (
Iterable[Path]
) – An iterable of paths to input files- Yields:
tuple[str, Type[Extension]]
– name and class of all discovered palgen extensions- Return type:
Iterable[palgen.loaders.loader.ExtensionInfo]
- load(source, import_name=None)#
Attempt loading palgen extensions from Python module at the given path.
- Parameters:
path (
Path
) – Path to the Python moduleimport_name (
Optional[str], optional
) – Qualified name to use for the Python module. Defaults to None.source (pathlib.Path) –
- Yields:
tuple[str, Type[Extension]]
– name and class of all discovered palgen extensions- Return type:
Iterable[palgen.loaders.loader.ExtensionInfo]
- static check_candidate(path)#
Analyzes the AST of the Python extension at the given path without executing it. If the AST does not contain any valid subclasses of palgen.Extension the Python module will not be deemed a valid candidate for further processing.
- Parameters:
path (
Path
) – Path to the file to check- Returns:
True if the path points to a valid candidate, False otherwise.
- Return type:
- static get_parent(path)#
Gets the name of the parent package (in terms of Python’s import machinery). The __init__.py will be analyzed without executing the Python module. If it includes a constant named
_PRIVATE
and_PRIVATE = True
it will randomize the parent module name. Otherwise it will use the content of the string constant_NAME
or fall back to the folder’s name.Warning:
- get_module(path)#
Gets the qualified name for the Python module found at path. Falls back to a random project name (and therefore a private extension) if this loader hasn’t been assigned a project yet.