Skip to content

Commit

Permalink
Merge pull request #3385 from jsiirola/moved-modules
Browse files Browse the repository at this point in the history
Improved support for moved/renamed/deprecated modules
  • Loading branch information
blnicho authored Nov 5, 2024
2 parents 4242394 + c37dda3 commit f46e2fd
Show file tree
Hide file tree
Showing 35 changed files with 610 additions and 286 deletions.
19 changes: 19 additions & 0 deletions pyomo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,22 @@

from . import common
from .version import __version__


#
# declare deprecation paths for removed modules
#
from pyomo.common.deprecation import moved_module

moved_module(
'pyomo.pysp',
'pysp',
version='6.0',
msg="PySP has been removed from the pyomo.pysp namespace. "
"Beginning in Pyomo 6.0, PySP is distributed as a separate "
"package. Please see https://github.com/Pyomo/pysp for "
"information on downloading and installing PySP",
)
# (*silently*) redirect 'pyomo.__future__' to 'pyomo.future'
moved_module('pyomo.__future__', 'pyomo.future', msg=None)
del moved_module
18 changes: 18 additions & 0 deletions pyomo/_archive/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# ___________________________________________________________________________
#
# Pyomo: Python Optimization Modeling Objects
# Copyright (c) 2008-2024
# National Technology and Engineering Solutions of Sandia, LLC
# Under the terms of Contract DE-NA0003525 with National Technology and
# Engineering Solutions of Sandia, LLC, the U.S. Government retains certain
# rights in this software.
# This software is distributed under the 3-clause BSD License.
# ___________________________________________________________________________

__doc__ = """This package contains archived modules that are no longer part of the
official Pyomo API.
These modules are still importable through their old names via
:func:`pyomo.common.moved_module()`
"""
14 changes: 14 additions & 0 deletions pyomo/_archive/chull.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# ___________________________________________________________________________
#
# Pyomo: Python Optimization Modeling Objects
# Copyright (c) 2008-2024
# National Technology and Engineering Solutions of Sandia, LLC
# Under the terms of Contract DE-NA0003525 with National Technology and
# Engineering Solutions of Sandia, LLC, the U.S. Government retains certain
# rights in this software.
# This software is distributed under the 3-clause BSD License.
# ___________________________________________________________________________

"This is the deprecated pyomo.gdp.plugins.chull module"

from pyomo.gdp.plugins.hull import _Deprecated_Name_Hull as ConvexHull_Transformation
4 changes: 2 additions & 2 deletions pyomo/common/plugin.py → pyomo/_archive/component_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
# This software is distributed under the 3-clause BSD License.
# ___________________________________________________________________________

from pyomo.common.deprecation import relocated_module
"This is the deprecated pyomo.core.kernel.component_map module"

relocated_module('pyomo.common.plugin_base', version='6.5.0')
from pyomo.common.collections import ComponentMap
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
# This software is distributed under the 3-clause BSD License.
# ___________________________________________________________________________

from pyomo.common.deprecation import relocated_module
"This is the deprecated pyomo.core.kernel.component_set module"

relocated_module('pyomo.repn.tests.nl_diff', version='6.6.0', remove_in='6.6.1')
from pyomo.common.collections import ComponentSet
10 changes: 2 additions & 8 deletions pyomo/core/expr/current.py → pyomo/_archive/current.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,11 @@
# This software is distributed under the 3-clause BSD License.
# ___________________________________________________________________________

"This is the deprecated pyomo.core.expr.current module"

import enum
import math

from pyomo.common.deprecation import deprecation_warning

deprecation_warning(
"pyomo.core.expr.current is deprecated. "
"Please import expression symbols from pyomo.core.expr",
version='6.6.2',
)

#
# Common intrinsic functions
#
Expand Down
12 changes: 1 addition & 11 deletions pyomo/core/base/plugin.py → pyomo/_archive/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,8 @@
# rights in this software.
# This software is distributed under the 3-clause BSD License.
# ___________________________________________________________________________
import inspect
from pyomo.common.deprecation import deprecation_warning

deprecation_warning(
"The pyomo.core.base.plugin module is deprecated. "
"See pyomo.core.base.transformation for Transformation and "
"TransformationFactory, pyomo.core.base.component for "
"ModelComponentFactory and pyomo.scripting.interface for "
"IPyomoScript* interfaces.",
version='6.0',
calling_frame=inspect.currentframe().f_back,
)
"This is the deprecated pyomo.core.base.plugin module"

from pyomo.core.base.component import ModelComponentFactory
from pyomo.core.base.transformation import (
Expand Down
4 changes: 2 additions & 2 deletions pyomo/common/getGSL.py → pyomo/_archive/rangeset.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
# This software is distributed under the 3-clause BSD License.
# ___________________________________________________________________________

from pyomo.common.deprecation import relocated_module
"This is the deprecated pyomo.core.base.rangeset module"

relocated_module('pyomo.common.gsl', version='6.5.0')
from pyomo.core.base.set import RangeSet
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,7 @@
# This software is distributed under the 3-clause BSD License.
# ___________________________________________________________________________

from pyomo.common.deprecation import deprecation_warning

deprecation_warning(
"pyomo.core.kernel.register_numpy_types is deprecated. NumPy type "
"registration is handled automatically by pyomo.common.dependencies.numpy",
version='6.1',
)
"This is the deprecated pyomo.core.kernel.register_numpy_types module"

from pyomo.common.numeric_types import (
RegisterNumericType,
Expand Down
23 changes: 23 additions & 0 deletions pyomo/_archive/sets.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# ___________________________________________________________________________
#
# Pyomo: Python Optimization Modeling Objects
# Copyright (c) 2008-2024
# National Technology and Engineering Solutions of Sandia, LLC
# Under the terms of Contract DE-NA0003525 with National Technology and
# Engineering Solutions of Sandia, LLC, the U.S. Government retains certain
# rights in this software.
# This software is distributed under the 3-clause BSD License.
# ___________________________________________________________________________

"This is the deprecated pyomo.core.base.sets module"

from pyomo.core.base.set import (
process_setarg,
set_options,
simple_set_rule,
_SetDataBase,
SetData,
Set,
SetOf,
IndexedSet,
)
18 changes: 18 additions & 0 deletions pyomo/_archive/template_expr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# ___________________________________________________________________________
#
# Pyomo: Python Optimization Modeling Objects
# Copyright (c) 2008-2024
# National Technology and Engineering Solutions of Sandia, LLC
# Under the terms of Contract DE-NA0003525 with National Technology and
# Engineering Solutions of Sandia, LLC, the U.S. Government retains certain
# rights in this software.
# This software is distributed under the 3-clause BSD License.
# ___________________________________________________________________________

"This is the deprecated pyomo.core.base.template_expr module"

from pyomo.core.expr.template_expr import (
IndexTemplate,
_GetItemIndexer,
TemplateExpressionError,
)
9 changes: 9 additions & 0 deletions pyomo/common/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,12 @@
from .deprecation import deprecated
from .errors import DeveloperError
from ._command import pyomo_command, get_pyomo_commands

#
# declare deprecation paths for removed modules
#
from .deprecation import moved_module

moved_module('pyomo.common.getGSL', 'pyomo.common.gsl', version='6.5.0')
moved_module('pyomo.common.plugin', 'pyomo.common.plugin_base', version='6.5.0')
del moved_module
16 changes: 13 additions & 3 deletions pyomo/common/dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,11 +518,21 @@ def find_spec(self, fullname, path, target=None):
if fullname not in self._callbacks:
return None

spec = importlib.machinery.PathFinder.find_spec(fullname, path, target)
if spec is None:
spec = None
# Continue looking for the finder that would have originally
# loaded the deferred import module b starting at the next
# finder in sys.meta_path (this way, we are agnostic to where
# the module is coming from: file system, registry, etc.)
for finder in sys.meta_path[sys.meta_path.index(self) + 1 :]:
spec = finder.find_spec(fullname, path, target)
if spec is not None:
break
else:
# Module not found. Returning None will proceed to the next
# finder (which is likely to raise a ModuleNotFoundError)
# finder (which will eventually raise a ModuleNotFoundError)
return None
# Override the loader to trigger the finalization callback
# after the original loader is finished
spec.loader = DeferredImportCallbackLoader(
spec.loader, self._callbacks[fullname]
)
Expand Down
Loading

0 comments on commit f46e2fd

Please sign in to comment.