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: Optional[bool] = None, version: Optional[str] = None, pkg_name: Optional[str] = None, install_flags: Optional[List[str]] = None, requires: Optional[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 and optionally the preferred version of the package, formatted as a version string. For example,
'example_module>=0.5.0'
or'example_module==1.8.0'
.log (bool) – Whether to log information about the module. Defaults to True.
version (str) – [DEPRECATED - use name instead] 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.
requires (List[str]) – Additional dependencies required by the module which are not specified as dependencies. This parameter should only be required when a module does not correctly specify dependencies. Defaults to [].
- 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