-
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
Conversation
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
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.
2 questions:
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.
Pending successful tests...
bc9798c
to
35cfd18
Compare
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. |
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: