Skip to content

Fix sdist build under setuptools >= 82 (pkg_resources removed)#32

Open
sethc555 wants to merge 1 commit into
youknowone:mainfrom
sethc555:fix/setuptools-82-pkg-resources
Open

Fix sdist build under setuptools >= 82 (pkg_resources removed)#32
sethc555 wants to merge 1 commit into
youknowone:mainfrom
sethc555:fix/setuptools-82-pkg-resources

Conversation

@sethc555

@sethc555 sethc555 commented Jun 11, 2026

Copy link
Copy Markdown

setuptools 82.0.0 (2026-02-08) removed pkg_resources. Because pip's default isolated build installs the latest setuptools, installing wirerope from sdist now fails:

$ docker run --rm python:3.12 pip install --no-binary :all: wirerope
...
ModuleNotFoundError: No module named 'pkg_resources'

This swaps the pkg_resources setuptools-version check for stdlib importlib.metadata (available since Python 3.8), preserving the original error message.

Verified: with this patch the sdist builds a wheel against setuptools 82 in a clean python:3.12 container; without it, it does not.

Found while scanning the top-5000 PyPI packages for breakage from the setuptools 82 removals — happy to adjust the patch however you prefer.

Summary by CodeRabbit

  • Chores
    • Updated the internal package installation verification process to use a more efficient method for checking setuptools version compatibility during setup. The validation requirement remains unchanged—setuptools version 39.2.0 or higher is still enforced.

…>=82)

setuptools 82.0.0 (2026-02-08) removed pkg_resources, so building this
project's sdist in a default isolated build environment fails with
ModuleNotFoundError: No module named 'pkg_resources'.

Use importlib.metadata (stdlib since 3.8) instead of pkg_resources for the setuptools version check.

Verified: the patched sdist builds a wheel with setuptools 82 in a
clean python:3.12 container; the unpatched one does not.

Co-Authored-By: Claude Fable 5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Jun 11, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

The setup.py bootstrap logic is updated to replace the deprecated pkg_resources-based setuptools version check with importlib.metadata.version(), manually parsing and comparing the first two numeric version components against (39, 2). Error handling behavior is preserved.

Changes

Setuptools version validation

Layer / File(s) Summary
Version check implementation and error handling
setup.py
Replaces pkg_resources.get_distribution("setuptools>=39.2.0") with importlib.metadata.version("setuptools") to validate installed setuptools meets the 39.2 minimum; preserves exception catching and upgrade instruction message.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐰 A setuptools check, so small and neat,
From pkg_resources to metadata—what a treat!
Version numbers parsed, compared with care,
Bootstrap logic now breathes fresher air.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately and specifically describes the main change: replacing pkg_resources (removed in setuptools 82) with an alternative approach for version checking in setup.py.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@setup.py`:
- Line 5: The version parsing on the assert line using tuple(int(x) for x in
version("setuptools").split(".")[:2]) can raise ValueError for non-numeric
components; replace this manual parse with a robust PEP 440-aware check (e.g.,
use packaging.version.parse or pkg_resources.parse_version to obtain a Version
object and compare its base numeric components or major/minor attributes) or
wrap the int() conversion in a try/except that treats parse failures as "too
old" and triggers the same upgrade message; update the assertion logic that
references version("setuptools") so it no longer directly casts split parts to
int.
- Line 5: The setuptools minimum-version check in setup.py currently asserts
tuple(int(x) for x in version("setuptools").split(".")[:2]) >= (39, 2) which
conflicts with pyproject.toml's setuptools>=40.8.0; update the assertion to
require (40, 8) (i.e., change the RHS tuple in that assertion) so it matches
pyproject.toml, or if there is an intentional fallback, add a clear comment
above the assert explaining why a lower 39.2 check is kept and reference the
pyproject.toml requirement.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 2df76896-6470-4e8c-b6b8-6242285563ba

📥 Commits

Reviewing files that changed from the base of the PR and between e5e0576 and c816e9c.

📒 Files selected for processing (1)
  • setup.py

Comment thread setup.py

try:
get_distribution("setuptools>=39.2.0")
assert tuple(int(x) for x in version("setuptools").split(".")[:2]) >= (39, 2)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick | 🔵 Trivial | ⚡ Quick win

Version parsing may fail on non-standard version strings.

The manual parsing logic split(".")[:2] followed by int(x) will raise ValueError if setuptools has a non-standard version with non-numeric components in the first or second position (e.g., "82a1.0").

While setuptools follows PEP 440 versioning (where pre-release identifiers appear after numeric components), the broad except Exception handler on line 6 will catch any parsing failures and re-raise with the upgrade message, which is reasonable fallback behavior.

🔧 Optional: More robust version parsing with packaging library

If packaging is already a project dependency, consider using it for PEP 440-compliant version parsing:

-from importlib.metadata import version
+from importlib.metadata import version as get_version
+from packaging.version import Version

 try:
-    assert tuple(int(x) for x in version("setuptools").split(".")[:2]) >= (39, 2)
+    assert Version(get_version("setuptools")) >= Version("39.2.0")

This would handle all PEP 440 version formats correctly.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@setup.py` at line 5, The version parsing on the assert line using
tuple(int(x) for x in version("setuptools").split(".")[:2]) can raise ValueError
for non-numeric components; replace this manual parse with a robust PEP
440-aware check (e.g., use packaging.version.parse or
pkg_resources.parse_version to obtain a Version object and compare its base
numeric components or major/minor attributes) or wrap the int() conversion in a
try/except that treats parse failures as "too old" and triggers the same upgrade
message; update the assertion logic that references version("setuptools") so it
no longer directly casts split parts to int.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Check for setuptools version requirements across the codebase

echo "=== setup.py version check ==="
rg -n "39.*2" setup.py

echo -e "\n=== pyproject.toml build requirements ==="
rg -n "setuptools" pyproject.toml

echo -e "\n=== Any other version requirements ==="
rg -n "setuptools.*>=.*[0-9]" --type py

Repository: youknowone/wirerope

Length of output: 452


Align setuptools minimum version enforcement between setup.py and pyproject.toml.

setup.py asserts setuptools >= (39, 2) (setup.py:5) while pyproject.toml requires setuptools>=40.8.0 (pyproject.toml:2). Update the assertion to 40.8.0 or document why the fallback check intentionally allows a lower version.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@setup.py` at line 5, The setuptools minimum-version check in setup.py
currently asserts tuple(int(x) for x in version("setuptools").split(".")[:2]) >=
(39, 2) which conflicts with pyproject.toml's setuptools>=40.8.0; update the
assertion to require (40, 8) (i.e., change the RHS tuple in that assertion) so
it matches pyproject.toml, or if there is an intentional fallback, add a clear
comment above the assert explaining why a lower 39.2 check is kept and reference
the pyproject.toml requirement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant