Light plugin framework¶
module: rspub.util.plugg
Py-module and -class inspector
-
rspub.util.plugg.
APPLICATION_HOME
= '/home/docs/checkouts/readthedocs.org/user_builds/rspub-core/checkouts/latest'¶ The absolute path to the directory that is the application home or root directory.
During run time. So the value shown in documentation is not a constant!
-
class
rspub.util.plugg.
Inspector
(stop_on_error=False)[source]¶ Bases:
object
Find py-modules and -classes in directories.
This class loads modules during its inspection. What the behavior will be upon encountering an ImportError can be set by the constructor parameter stop_on_error (boolean). It will then either log the exception (default) or raise the exception.
-
__init__
(stop_on_error=False)[source]¶ Initialize an Inspector.
Parameters: stop_on_error – True for stop on error, False otherwise
-
static
list_py_files
(*directories) → str[source]¶ Generator of py filenames.
Walks the given directories one-by-one recursively and yields each py-file it encounters. A file is considered py-file when its filename ends with .py.
Files __init__.py and setup.py are neglected.
Parameters: directories (str) – directories to search Returns: yields absolute filenames of py-files
-
load_modules
(*directories)[source]¶ Generator of modules.
Walks the given directories one-by-one recursively and yields each module it encounters. The encountered modules will be imported. What the behavior will be upon encountering an ImportError can be set by the constructor parameter stop_on_error (boolean).
Parameters: directories (str) – directories to search Returns: yields imported modules
-
list_classes
(*directories)[source]¶ Generator of classes.
Walks the given directories one-by-one recursively and yields each class it encounters.
Parameters: directories (str) – directories to search Returns: yields encountered classes
-
list_classes_filtered
(predicates=[], *directories)[source]¶ Generator of filtered classes.
Walks the given directories one-by-one recursively and yields encountered classes if they pass all the predicates given in predicates.
Parameters: - predicates (list) – a list of one-argument predicates that filter classes
- directories (str) – directories to search
Returns: yields encountered classes that pass the predicates
-
-
rspub.util.plugg.
is_subclass_of
(super)[source]¶ Predicate for subclass detection
f(cls) = issubclass(cls, super)
Parameters: super – the superclass in the detection Returns: lambda for class subclass detection
-
rspub.util.plugg.
is_qnamed
(qname)[source]¶ Predicate for qualified class-name detection.
f(cls) = cls.qualified_name == qname
Parameters: qname – the qualified name in the detection Returns: lambda for qualified class-name detection
-
rspub.util.plugg.
is_named
(name)[source]¶ Predicate for loose class-name detection.
f(cls) = cls.name == name or cls.qualified_name == name
Parameters: name – the class-name or qualified class-name in the detection Returns: lambda for loose class-name detection