Replace deprecated pkg_resources with packaging in setup.py#1338
Open
jasonwbarnett wants to merge 1 commit into
Open
Replace deprecated pkg_resources with packaging in setup.py#1338jasonwbarnett wants to merge 1 commit into
jasonwbarnett wants to merge 1 commit into
Conversation
setup.py used pkg_resources.Requirement to validate the installed Cython
version at build time. pkg_resources is deprecated by setuptools and slated
for removal: it emits a DeprecationWarning on import and is unavailable in
some modern setuptools configurations, which can make source builds warn or
fail.
Port the check to the packaging library:
- pkg_resources.Requirement.parse(CYTHON_DEPENDENCY)
-> packaging.requirements.Requirement(CYTHON_DEPENDENCY)
- Cython.__version__ not in cython_dep
-> not cython_dep.specifier.contains(Cython.__version__, prereleases=True)
pkg_resources.Requirement.__contains__ passed prereleases=True internally, so
passing prereleases=True preserves the original behavior exactly. Add
packaging>=20 to build-system.requires so it is available when building from
source.
Mirrors the same fix in the sister project MagicStack/uvloop@b377b7c.
Refs: MagicStack#1337
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ScLtrCvUAVqPrVbcqsGUDJ
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.
Summary
setup.pyuses the deprecatedpkg_resourcesmodule (from setuptools) to validate the installed Cython version when building from source.pkg_resourcesemitsDeprecationWarning: pkg_resources is deprecated as an APIon import, is slated for removal, and is unavailable in some modern setuptools configurations — which can make source builds warn or fail.This ports the Cython version check to the
packaginglibrary:packaging>=20to[build-system].requiresso it is available at build time.pkg_resources.Requirement.__contains__usedprereleases=Trueinternally, so passingprereleases=Truepreserves the original behavior exactly (including accepting in-range prereleases such as3.3.0b1).This mirrors the same fix already made in the sister project uvloop (MagicStack/uvloop@b377b7c).
Relationship to #1314
#1314 addresses the same deprecation by removing the Cython version check entirely. This PR is an alternative that keeps the check while dropping the deprecated dependency. Happy to defer to whichever direction you prefer.
Verification
python -m py_compile setup.pypasses; nopkg_resourcesreferences remain in the tree.packaging.requirements.Requirement("Cython(>=3.2.1,<4.0.0)")parses the parenthesized PEP 508 form, and that.specifier.contains(v, prereleases=True)matches the oldpkg_resourcesbehavior across in-range, out-of-range, and prerelease versions.Closes #1337