Skip to content

Add --rename-dep option to rename dependencies in wheels#3

Open
ianhi wants to merge 4 commits intomainfrom
rename-deps
Open

Add --rename-dep option to rename dependencies in wheels#3
ianhi wants to merge 4 commits intomainfrom
rename-deps

Conversation

@ianhi
Copy link
Copy Markdown
Collaborator

@ianhi ianhi commented Dec 24, 2025

Summary

Add the ability to rename dependencies when renaming a wheel, enabling installation of packages with conflicting dependency trees.

New Features

  • --rename-dep CLI option: Rename dependencies in the wheel's METADATA and Python imports

    spare-tire rename pkg-1.0.0.whl pkg_v1 --rename-dep mydep=mydep_v1
  • --python-version option for download: Specify target Python version when downloading wheels (useful with uvx)

    uvx spare-tire download zarr --python-version 3.12 -o ./wheels/
  • Module attribute rewriting: Import rewriting now handles pkg.attr patterns (e.g., zarr.open()zarr_v2.open())

  • rename_wheel_from_bytes support: The bytes-based API now supports rename_deps for proxy server use

Use Case: Conflicting Dependencies

When two versions of a package require incompatible versions of the same dependency:

# Scenario: mypkg v1 needs zarr<3, mypkg v2 needs zarr>=3

# 1. Download and rename zarr v2
spare-tire download zarr --version ">=2,<3" --rename zarr_v2 -o ./wheels/

# 2. Rename mypkg v1, updating its dependency
spare-tire rename mypkg-1.0.0.whl mypkg_v1 --rename-dep zarr=zarr_v2 -o ./wheels/

# 3. Install both versions
pip install zarr  # v3
pip install ./wheels/zarr_v2-*.whl
pip install ./wheels/mypkg_v1-*.whl

Now both work in the same Python session:

import zarr           # v3.x
import zarr_v2        # v2.x
import mypkg          # uses zarr v3
import mypkg_v1       # uses zarr_v2

Testing

  • 28 pytest tests pass (4 new tests for dependency renaming)
  • Conflicting deps fixture (tests/fixtures/conflicting-deps/): Synthetic test with mypkg/mydep
  • Zarr compatibility fixture (tests/fixtures/zarr-compat/): Real-world test downloading zarr v2 from PyPI, renaming to zarr_v2, and verifying both zarr v2 and v3 can read the same Zarr format 2 data

Run the zarr test:

uv run python tests/fixtures/zarr-compat/test_zarr_compat.py

Files Changed

  • src/spare_tire/rename.py - Add rename_deps parameter to both rename functions, enhance import rewriting
  • src/spare_tire/download.py - Add python_version parameter
  • src/spare_tire/cli.py - Add --rename-dep and --python-version options
  • tests/test_integration.py - Add TestDependencyRenaming class with 4 tests
  • README.md - Document new features with examples
  • AGENTS.md - Update function signatures
  • tests/fixtures/conflicting-deps/ - Synthetic dependency conflict test
  • tests/fixtures/zarr-compat/ - Real zarr v2/v3 compatibility test

ianhi and others added 4 commits December 24, 2025 17:15
When renaming a package that depends on another package that also needs
renaming, the new --rename-dep option updates both the METADATA
(Requires-Dist) and Python import statements.

Example:
  spare-tire rename mydep-1.0.0.whl mydep_v1
  spare-tire rename mypkg-1.0.0.whl mypkg_v1 --rename-dep mydep=mydep_v1

This enables installing packages with conflicting dependencies by
renaming the entire dependency tree of the older version.

Changes:
- Add rename_deps parameter to rename_wheel() function
- Update _update_metadata() to rewrite Requires-Dist lines
- Add --rename-dep CLI option (can be used multiple times)
- Add test fixtures demonstrating conflicting dependency resolution
- Update documentation in README.md and AGENTS.md

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Enhance import rewriting to also update module attribute access patterns
like `zarr.open()` and `zarr.__version__` when renaming dependencies.

Add real-world integration test that:
- Downloads zarr v2 from PyPI and renames to zarr_v2
- Creates test packages using different zarr versions
- Verifies both zarr v2 and v3 can coexist in the same environment
- Confirms both can read the same Zarr format 2 data

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add section showing how to use --rename-dep to install conflicting
zarr versions (v2 and v3) in the same environment.

Also add README to the zarr-compat test fixture with usage instructions.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Update rename_wheel_from_bytes to support rename_deps parameter
  (needed for proxy server to support dependency renaming)
- Add TestDependencyRenaming class with 4 pytest tests:
  - test_rename_deps_updates_metadata
  - test_rename_deps_updates_imports
  - test_rename_multiple_deps
  - test_rename_deps_with_extras

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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