Skip to content

Resolve an assortment of infrastructure errors - pkg_resources and GAMS #3644

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

mrmundt
Copy link
Contributor

@mrmundt mrmundt commented Jun 24, 2025

Fixes NA

Summary/Motivation:

We have lots of new deprecation warnings showing up in the book examples because the pyomo_main script uses pkg_resources.

Changes proposed in this PR:

  • Replace pkg_resources with importlib.metadata
  • Turn off GAMS until we can figure out a new licensing plan

Legal Acknowledgement

By contributing to this software project, I have read the contribution guide and agree to the following terms and conditions for my contribution:

  1. I agree my contributions are submitted under the BSD license.
  2. I represent I am authorized to make the contributions and grant the license. If my employer has rights to intellectual property that includes these contributions, I represent that I have received permission to make contributions and grant the required license on behalf of that employer.

Copy link
Member

@jsiirola jsiirola left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition, this PR is missing pkg_resources in 2 other places:

diff --git a/pyomo/contrib/appsi/solvers/maingo.py b/pyomo/contrib/appsi/solvers/maingo.py
index 8273061be..94d18cc26 100644
--- a/pyomo/contrib/appsi/solvers/maingo.py
+++ b/pyomo/contrib/appsi/solvers/maingo.py
@@ -173,11 +173,15 @@ class MAiNGO(PersistentBase, PersistentSolver):
         return self._available

     def version(self):
-        import pkg_resources
+        import importlib.metadata

-        version = pkg_resources.get_distribution('maingopy').version
-
-        return tuple(int(k) for k in version.split('.'))
+        version = importlib.metadata.version('maingopy').split('.')
+        for i, n in enumerate(version):
+            try:
+                version[i] = int(version[i])
+            except:
+                pass
+        return tuple(version)

     @property
     def config(self) -> MAiNGOConfig:

and

diff --git a/pyomo/common/dependencies.py b/pyomo/common/dependencies.py
index a2cf06fbb..a68c1797b 100644
--- a/pyomo/common/dependencies.py
+++ b/pyomo/common/dependencies.py
@@ -449,10 +449,22 @@ def check_min_version(module, min_version):

             _parser = _version.parse
         except ImportError:
-            # pkg_resources is an order of magnitude slower to import than
-            # packaging.  Only use it if the preferred (but optional)
-            # packaging library is not present
-            from pkg_resources import parse_version as _parser
+            try:
+                # pkg_resources is an order of magnitude slower to import than
+                # packaging.  Only use it if the preferred (but optional)
+                # packaging library is not present
+                from pkg_resources import parse_version as _parser
+            except ImportError:
+                # This parser is NOT complient with PEP 440, but will be
+                # OK in 99% of the use cases.
+                def _parser(verstr):
+                    version = verstr.split('.')
+                    for i, v in enumerate(version):
+                        try:
+                            version[i] = int(v)
+                        except:
+                            pass
+                    return tuple(version)
         check_min_version._parser = _parser
     else:
         _parser = check_min_version._parser

@blnicho blnicho moved this from Todo to Review In Progress in July 2025 Release Jun 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Review In Progress
Development

Successfully merging this pull request may close these issues.

2 participants