From fbf6e63a3e1fc055d56682de89c30b35b4107c40 Mon Sep 17 00:00:00 2001 From: Jason Barnett <862300+jasonwbarnett@users.noreply.github.com> Date: Wed, 15 Jul 2026 19:45:49 +0000 Subject: [PATCH] Replace deprecated pkg_resources with packaging in setup.py 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/asyncpg#1337 Co-Authored-By: Claude Opus 4.8 (1M context) Claude-Session: https://claude.ai/code/session_01ScLtrCvUAVqPrVbcqsGUDJ --- pyproject.toml | 3 ++- setup.py | 8 +++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index e2b18388..5d09895b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -62,7 +62,8 @@ docs = [ [build-system] requires = [ "setuptools>=77.0.3", - "Cython(>=3.2.1,<4.0.0)" + "Cython(>=3.2.1,<4.0.0)", + "packaging>=20" ] build-backend = "setuptools.build_meta" diff --git a/setup.py b/setup.py index f9fafadf..5fdc53ff 100644 --- a/setup.py +++ b/setup.py @@ -188,7 +188,7 @@ def finalize_options(self): need_cythonize = True if need_cythonize: - import pkg_resources + from packaging.requirements import Requirement # Double check Cython presence in case setup_requires # didn't go into effect (most likely because someone @@ -201,8 +201,10 @@ def finalize_options(self): 'please install {} to compile asyncpg from source'.format( CYTHON_DEPENDENCY)) - cython_dep = pkg_resources.Requirement.parse(CYTHON_DEPENDENCY) - if Cython.__version__ not in cython_dep: + cython_dep = Requirement(CYTHON_DEPENDENCY) + if not cython_dep.specifier.contains( + Cython.__version__, prereleases=True + ): raise RuntimeError( 'asyncpg requires {}, got Cython=={}'.format( CYTHON_DEPENDENCY, Cython.__version__