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
Summary
setup.py uses the deprecated pkg_resources module (from setuptools) to validate the installed Cython version when building from source. pkg_resources emits DeprecationWarning: pkg_resources is deprecated as an API on 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 packaging library:
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
Closes #1337