include.base.import_hook module¶
-
class
include.base.import_hook.
BaseIncludeLoader
(module_prefix)¶ Bases:
object
Import hook to load Python modules from an arbitrary location
Parameters: module_prefix (str) – prefix for modules to import Base class for import hooks to non-standard code sources. Implements the general structure for encoded sources: a module source translates to an artificial module path of the form
<module_prefix>.<encoded_name>
. Themodule_prefix
identifies the code source type (and import hook) while theencoded_name
contains all required information to retrieve the code.For example, a
module_prefix
ofinclude.type.files
could identify a source file type, and anencoded_name
ofSLASHtmpSLASHfooDOTpy
point to the path/tmp/foo.py
. The resulting module would appear asinclude.type.files.SLASHtmpSLASHfooDOTpy
.Note that
module_prefix
must point to a valid package, not a module. It will be actually imported by the regular import machinery, and can be used to bootstrap hooks.The
encoded_name
is a free form field. The base class provides means to escape invalid and reserved symbols (/
and.
), but subclasses are free to use them if it is suitable for them. Hooks should useencoded_name
to store a URI (or similar) to retrieve source code. As per Python rules, including a dot (.
) in theencoded_name
requires the hook to import each portion separately.-
find_module
(fullname, path=None)¶ Find the appropriate loader for module
name
Parameters:
-
load_module
(name)¶ Load and return a module
Always returns the corresponding module. If the module is already loaded, the existing module is returned.
-
module2uri
(module_name)¶ Convert an encoded module name to an unencoded source uri
-
module_prefix
¶
-
uri2module
(uri)¶ Convert an unencoded source uri to an encoded module name
-