Replace deprecated pkg_resources with packaging in setup.py - #1
Closed
jasonwbarnett wants to merge 1 commit into
Closed
Replace deprecated pkg_resources with packaging in setup.py#1jasonwbarnett 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
Author
|
Superseded by the upstream PR MagicStack#1338 — this fix belongs against upstream rather than the company fork. Closing here. |
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.
What & why
setup.pyusespkg_resources(from setuptools) to validate the installed Cython version when building from source.pkg_resourcesis deprecated by setuptools and slated for removal — it emitsDeprecationWarning: pkg_resources is deprecated as an APIon import and is unavailable in some modern setuptools configurations, which can make source builds warn or fail.Change
Port the Cython version check to the
packaginglibrary:packaging>=20to[build-system].requiresinpyproject.tomlso 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 in the sister project MagicStack/uvloop@b377b7c.
Verification
python -m py_compile setup.pypasses.pkg_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.Related