prefect.utilities.importtools
to_qualified_name
obj
: an importable Python objectfrom_qualified_name
name
: The fully-qualified name of the object to import.load_script_as_module
prefect.exceptions.ScriptError
is created to wrap the exception and raised.
load_module
import_object
lazy_import
lazy_import("docker.errors")
and import docker.errors
in the
same codebase will import docker.errors
twice and can lead to unexpected
behavior, e.g. type check failures and import-time side effects running
twice.
Adapted from the Python documentation and lazy_loader
safe_load_namespace
filepath
is provided, sys.path
is modified to support relative imports.
Changes to sys.path
are reverted after completion, but this function is not thread safe
and use of it in threaded contexts may result in undesirable behavior.
Args:
source_code
: The source code to loadfilepath
: Optional file path of the source code. If provided, enables relative imports.DelayedImportErrorModule
lazy_import
when the module cannot be found. When any
of the module’s attributes are accessed, we will throw a ModuleNotFoundError
.
Adapted from lazy_loader
AliasedModuleDefinition
AliasedModuleFinder
.
Args:
alias
: The import name to createreal
: The import name of the module to reference for the aliascallback
: A function to call when the alias module is loadedAliasedModuleFinder
find_spec
AliasedModuleLoader
exec_module