moved_module

(function from pyomo.common.deprecation)

pyomo.common.deprecation.moved_module(old_name, new_name, msg=NOTSET, logger=None, version=None, remove_in=None)[source]

Provide a deprecation path for moved / renamed modules

This function hooks into the Python importlib to cause any import of the old_name to instead import and return the module from new_name. The new module is automatically registered with sys.modules under both the old and new names.

Because moved_module() works through the Python importlib system, the old module file can be completely deleted (in contrast to the [deprecated] relocated_module() function). Calls to moved_module() should be placed in any package above the removed module in the package hierarchy (or in any other location that is guaranteeded to be imported / executed before any attempts at importng the module through its old name.

Any import of the module through the old name will emit a deprecation warning unless the msg is None (see also deprecated()).

Parameters:
  • old_name (str) – The original (fully-qualified) module name (that has been removed)

  • new_name (str) – The new (fully-qualified) module name

  • msg (str) – A custom deprecation message. If None, the deprecation message will be suppressed. If NOTSET (default), a generic deprecation message will be logged.

  • logger (str) – The logger to use for emitting the warning (default: the calling pyomo package, or “pyomo”)

  • version (str [required]) – The version in which the module was renamed or moved. General practice is to set version to the current development version (from pyomo –version) during development and update it to the actual release as part of the release process.

  • remove_in (str) – The version in which the module will be removed from the code.

Example

>>> from pyomo.common.deprecation import moved_module
>>> moved_module(
...     'pyomo.common.old_deprecation',
...     'pyomo.common.deprecation',
...     version='1.2.3',
... )
>>> import pyomo.common.old_deprecation
WARNING: DEPRECATED: The 'pyomo.common.old_deprecation' module has
    been moved to 'pyomo.common.deprecation'. Please update your import.
    (deprecated in 1.2.3) ...
>>> import pyomo.common.deprecation
>>> pyomo.common.old_deprecation is pyomo.common.deprecation
True