declare_modules_as_importable
(class from pyomo.common.dependencies)
- class pyomo.common.dependencies.declare_modules_as_importable(globals_dict)[source]
Bases:
objectMake all
ModuleTypeandDeferredImportModulesimportable through theglobals_dictcontext.This context manager will detect all modules imported into the specified
globals_dictenvironment (either directly or throughattempt_import()) and will make those modules importable from the specifiedglobals_dictcontext. It works by detecting changes in the specifiedglobals_dictdictionary and adding any new modules or instances ofDeferredImportModulethat it finds (and any of their deferred submodules) tosys.modulesso that the modules can be imported through theglobals_dictnamespace.For example,
pyomo/common/dependencies.pydeclares:>>> with declare_modules_as_importable(globals()): ... scipy, scipy_available = attempt_import( ... 'scipy', callback=_finalize_scipy, ... deferred_submodules=['stats', 'sparse', 'spatial', 'integrate'])
Which enables users to use:
>>> import pyomo.common.dependencies.scipy.sparse as spa
If the deferred import has not yet been triggered, then the
DeferredImportModuleis returned and namedspa. However, if the import has already been triggered, thenspawill either be thescipy.sparsemodule, or aModuleUnavailableinstance.Methods
__init__(globals_dict)Member Documentation