-
Notifications
You must be signed in to change notification settings - Fork 546
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
mrmundt
wants to merge
9
commits into
Pyomo:main
Choose a base branch
from
mrmundt:pkgresource-depr
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
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
jsiirola
requested changes
Jun 24, 2025
There was a problem hiding this 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
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_main
script usespkg_resources
.Changes proposed in this PR:
pkg_resources
withimportlib.metadata
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: