Resolve an assortment of infrastructure errors - pkg_resources and GAMS#3644
Merged
blnicho merged 15 commits intoPyomo:mainfrom Jun 27, 2025
Merged
Resolve an assortment of infrastructure errors - pkg_resources and GAMS#3644blnicho merged 15 commits intoPyomo:mainfrom
blnicho merged 15 commits intoPyomo:mainfrom
Conversation
jsiirola
requested changes
Jun 24, 2025
Member
jsiirola
left a comment
There was a problem hiding this comment.
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._parserbc9798c to
35cfd18
Compare
Member
|
Merging this to get tests passing again but we're not happy with the workaround for the NEOS connection issue. @mrmundt is working on a separate PR to revamp the NEOS connection logic. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes NA
Summary/Motivation:
We have lots of new deprecation warnings showing up in the book examples because the
pyomo_mainscript usespkg_resources.Changes proposed in this PR:
pkg_resourceswithimportlib.metadataLegal Acknowledgement
By contributing to this software project, I have read the contribution guide and agree to the following terms and conditions for my contribution: