fix: replace pkg_resources with importlib.metadata for setuptools 82+#286
fix: replace pkg_resources with importlib.metadata for setuptools 82+#286junagent wants to merge 2 commits intovpython:masterfrom
Conversation
vpython/__init__.py
Outdated
| @@ -1,4 +1,4 @@ | |||
| from pkg_resources import get_distribution, DistributionNotFound | |||
| from importlib.metadata import version as get_distribution, PackageNotFoundError as DistributionNotFound | |||
There was a problem hiding this comment.
Instead of trying to make version act like get_distribution, how about just:
| from importlib.metadata import version as get_distribution, PackageNotFoundError as DistributionNotFound | |
| from importlib.metadata import version, DistributionNotFound |
vpython/__init__.py
Outdated
There was a problem hiding this comment.
This becomes
| __version__ = version(__name__) |
which fixes the error in CI.
ALSO revise the name of the exception below.
|
Thanks for the review! I want to make sure I understand correctly. The current fix imports: Then uses: Is your suggestion to change it to: Or something else? Happy to revise to match your vision exactly. |
Address maintainer review feedback: use version() directly instead of aliasing to get_distribution(), and update exception name to PackageNotFoundError. Fixes vpython#286
|
Thanks for the review! I've pushed a new commit addressing your feedback:
The simpler approach is cleaner. Let me know if anything else needs adjustment. |
Summary
pkg_resources was removed from setuptools 82.0.0 (PEP 740, Feb 2026). This breaks vpython when installed with the latest setuptools.
Fix
Replace pkg_resources usage with the stdlib importlib.metadata module:
Testing
pip install setuptools>=82
pip install vpython # should work without pkg_resources error
python -c "import vpython; print(vpython.version)"
Fixes #285
Fixes #285