declare_deferred_modules_as_importable

(function from pyomo.common.dependencies)

pyomo.common.dependencies.declare_deferred_modules_as_importable(globals_dict)[source]

DEPRECATED.

Make all DeferredImportModules in globals_dict importable

This function will go throughout the specified globals_dict dictionary and add any instances of DeferredImportModule that it finds (and any of their deferred submodules) to sys.modules so that the modules can be imported through the globals_dict namespace.

For example, pyomo/common/dependencies.py declares:

>>> scipy, scipy_available = attempt_import(
...     'scipy', callback=_finalize_scipy,
...     deferred_submodules=['stats', 'sparse', 'spatial', 'integrate'])
>>> declare_deferred_modules_as_importable(globals())
WARNING: DEPRECATED: ...

Which enables users to use:

>>> import pyomo.common.dependencies.scipy.sparse as spa

If the deferred import has not yet been triggered, then the DeferredImportModule is returned and named spa. However, if the import has already been triggered, then spa will either be the scipy.sparse module, or a ModuleUnavailable instance.

Deprecated since version 6.7.2: declare_deferred_modules_as_importable() is deprecated. Use the declare_modules_as_importable context manager.