Skip to content

Add package=sdist-wheel package type#3741

Merged
gaborbernat merged 18 commits intotox-dev:mainfrom
rahuldevikar:users/rahuldevikar/build-from-sdist
Feb 19, 2026
Merged

Add package=sdist-wheel package type#3741
gaborbernat merged 18 commits intotox-dev:mainfrom
rahuldevikar:users/rahuldevikar/build-from-sdist

Conversation

@rahuldevikar
Copy link
Copy Markdown
Collaborator

@rahuldevikar rahuldevikar commented Feb 17, 2026

Adds a new sdist-wheel package type that builds a wheel from a source distribution rather than directly from the source tree. This validates that the sdist is complete and that the package can be correctly built from it — catching missing files or packaging errors early.

Usage

[env_run_base]
package = "sdist-wheel"

[testenv]
package = sdist-wheel

How it works

  1. Builds an sdist via build_sdist
  2. Extracts the sdist to a temporary directory
  3. Swaps the package root to the extracted source
  4. Builds a wheel via build_wheel from that extracted sdist
  5. Cleans up the sdist and extraction directory
  • ran the linter to address style issues (tox -e fix)
  • wrote descriptive pull request text
  • ensured there are test(s) validating the fix
  • added news fragment in docs/changelog folder
  • updated/extended the documentation

@rahuldevikar rahuldevikar marked this pull request as ready for review February 18, 2026 00:15
Comment thread src/tox/tox_env/python/virtual_env/package/pyproject.py Outdated
@rahuldevikar rahuldevikar marked this pull request as draft February 18, 2026 03:48
@rahuldevikar rahuldevikar marked this pull request as ready for review February 18, 2026 05:47
Comment thread src/tox/tox_env/python/virtual_env/package/pyproject.py Outdated
@rahuldevikar rahuldevikar marked this pull request as draft February 18, 2026 07:49
@rahuldevikar rahuldevikar marked this pull request as ready for review February 18, 2026 15:57
@gaborbernat
Copy link
Copy Markdown
Member

Suggested Simplification: Reuse wheel_build_env Infrastructure

The current implementation introduces sdist_wheel_build_env as a new build environment type, but this creates unnecessary complexity. The existing wheel_build_env infrastructure (used for package=wheel and package=editable) can be reused for sdist-wheel builds with minimal changes.

Proposed Architecture

Instead of creating a separate sdist_wheel_build_env system, sdist-wheel should follow the same two-environment pattern as regular wheel builds:

  • .pkg environment: Builds and extracts the sdist (currently only builds, extraction is new)
  • .pkg-cpython313 (or whatever wheel_build_env resolves to): Builds the wheel from the extracted sdist

This leverages the existing _wheel_build_envs dictionary and all the wheel-building machinery already in place.

Workflow Diagram

sequenceDiagram
    participant User
    participant RunEnv as Test Environment<br/>(py313)
    participant PkgEnv as .pkg<br/>(Package Env)
    participant WheelEnv as .pkg-cpython313<br/>(wheel_build_env)
    participant TmpDir as .pkg/tmp/

    User->>RunEnv: tox run with package=sdist-wheel
    RunEnv->>PkgEnv: Request package
    
    Note over PkgEnv,WheelEnv: Registration Phase
    PkgEnv->>PkgEnv: Add "sdist-wheel" to package.py:80<br/>wheel_build_env check
    PkgEnv->>WheelEnv: Register wheel_build_env<br/>(same as wheel/editable)
    
    rect rgb(255, 244, 225)
        Note over PkgEnv: Phase 1: Build sdist
        PkgEnv->>PkgEnv: Install build-system.requires
        PkgEnv->>PkgEnv: Build sdist → my-pkg.tar.gz
    end
    
    rect rgb(240, 225, 255)
        Note over PkgEnv,TmpDir: Phase 2: Extract
        PkgEnv->>TmpDir: Extract to env_tmp_dir/sdist-extract/
        Note over TmpDir: Same location as cmd_builder.py:111
        TmpDir-->>PkgEnv: Extracted source path
    end
    
    rect rgb(225, 255, 240)
        Note over WheelEnv: Phase 3: Build wheel
        PkgEnv->>WheelEnv: Get from _wheel_build_envs[wheel_build_env]
        PkgEnv->>WheelEnv: Set root = extracted_path
        Note over WheelEnv: Root setter closes old backend,<br/>creates new frontend
        WheelEnv->>WheelEnv: Read pyproject.toml from extracted sdist
        WheelEnv->>WheelEnv: Install build deps<br/>(from extracted pyproject.toml)
        WheelEnv->>WheelEnv: Build wheel using existing logic<br/>(lines 283-300 in pyproject.py)
        WheelEnv-->>PkgEnv: Return wheel
    end
    
    rect rgb(245, 245, 245)
        Note over TmpDir: Phase 4: Cleanup
        Note over TmpDir: env_tmp_dir cleared automatically<br/>on next setup (api.py:350-356)
        Note over PkgEnv: No manual shutil.rmtree needed
    end
    
    PkgEnv-->>RunEnv: Install wheel
    RunEnv->>User: Run tests
Loading

Benefits

  1. Reuses existing infrastructure: No new sdist_wheel_build_env config or _sdist_wheel_build_envs dictionary needed
  2. Automatic cleanup: Using env_tmp_dir for extraction means tox's lifecycle handles cleanup automatically (see api.py:350-356)—no manual shutil.rmtree required
  3. Consistent with existing patterns: cmd_builder.py:111 already uses self.env_tmp_dir / "sdist-extract" for the exact same purpose
  4. Less code: Eliminates duplicate environment management logic

Required Changes

  1. package.py:80: Add "sdist-wheel" to the wheel_build_env check
  2. pyproject.py:register_run_env: Simple registration that sets up both sdist and wheel hooks
  3. pyproject.py:perform_packaging: Extract sdist to env_tmp_dir, delegate to existing wheel_build_env
  4. Remove: sdist_wheel_build_env config, _sdist_wheel_build_envs dictionary, manual cleanup code

Let me know if you'd like me to clarify any part of this proposal!

@rahuldevikar rahuldevikar marked this pull request as draft February 18, 2026 18:17
@rahuldevikar rahuldevikar marked this pull request as ready for review February 18, 2026 19:12
@rahuldevikar rahuldevikar marked this pull request as draft February 18, 2026 19:48
@rahuldevikar rahuldevikar marked this pull request as ready for review February 18, 2026 22:02
@gaborbernat gaborbernat force-pushed the users/rahuldevikar/build-from-sdist branch 3 times, most recently from 2d7412a to cee7c3e Compare February 19, 2026 01:41
Signed-off-by: Bernát Gábor <[email protected]>
@gaborbernat gaborbernat force-pushed the users/rahuldevikar/build-from-sdist branch from cee7c3e to 14b459c Compare February 19, 2026 01:42
@gaborbernat gaborbernat enabled auto-merge (squash) February 19, 2026 01:43
@gaborbernat gaborbernat merged commit 17d3c1e into tox-dev:main Feb 19, 2026
52 of 53 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants