Import Helpers¶
Module: polygraphy.mod
-
LATEST_VERSION
= 'latest'¶ Indicates that the latest version of the package is preferred in lazy_import
-
lazy_import
(name: str, log: bool = None, version: str = None, pkg_name: str = None, install_flags: List[str] = None)[source]¶ Lazily import a module.
If config.AUTOINSTALL_DEPS is set to 1, missing modules are automatically installed, and existing modules may be upgraded if newer versions are required.
- Parameters
name (str) – The name of the module.
log (bool) – Whether to log information about the module. Defaults to True.
version (str) – The preferred version of the package, formatted as a version string. For example,
'>=0.5.0'
or'==1.8.0'
. UseLATEST_VERSION
to indicate that the latest version of the package is preferred.pkg_name (str) – The name of the package that provides this module, if it is different from the module name. Used only if automatic installation of dependencies is enabled.
install_flags (List[str]) – Additional flags to provide to the installation command. Used only if automatic installation of dependencies is enabled.
- Returns
A lazily loaded module. When an attribute is first accessed, the module will be imported.
- Return type
LazyModule
-
has_mod
(modname)[source]¶ Checks whether a module is available and usable.
- Parameters
modname (str) – The name of the module to check.
- Returns
Whether the module is available and usable. This returns false if importing the module fails for any reason.
- Return type
bool