Skip to content

Drop setuptools concat_license_files; adopt PEP 639 license-files - #180237

Closed
zklaus wants to merge 31 commits into
gh/zklaus/43/basefrom
gh/zklaus/43/head
Closed

zklaus wants to merge 31 commits into
gh/zklaus/43/basefrom
gh/zklaus/43/head

Conversation

@zklaus

@zklaus zklaus commented Apr 13, 2026 •

Copy link
Copy Markdown
Collaborator

Stack from ghstack (oldest at bottom):

Context

This PR started out as an attempt to port the license file handling, including the concatenation and overwriting of the original LICENSE to a cmake controlled version. However, that proved tricky and brittle, as particularly the overwrite of the LICENSE file introduces race conditions and failure modes for, for example, subsequent builds in the same directory. Instead, PEP 639 gives us a clean alternative by embedding all the license files in the wheel.

That is why this PR ended up also covering some aspects of #158104, though hopefully with a smaller footprint; because of the discussion over there, I also triggered a manual check of inductor-perf-test-nightly-macos.yml, which came back green.

Summary

Replace the legacy "concatenate every third-party LICENSE into the top-level LICENSE during bdist_wheel" mechanism with the standard PEP 639 license-files field. Setuptools 77+ implements PEP 639 with directory-preserving placement at *.dist-info/licenses/<path>, and scikit-build-core's tool.scikit-build.wheel.license-files was already configured the same way during the migration.

What changes

  • setup.py: remove the concat_license_files context manager and its bdist_wheel / sdist command-class overrides.
  • pyproject.toml: declare [project].license-files (mirrors the tool.scikit-build.wheel.license-files glob already present), and migrate license = { text = "BSD-3-Clause" } to the PEP 639 string form license = "BSD-3-Clause" (resolves the existing TODO; the table form is deprecated in setuptools 77+).
  • requirements-build.txt and the dev dependency group: bump setuptools to >=77.0.0, the first release implementing PEP 639.
  • third_party/build_bundled.py and third_party/LICENSES_BUNDLED.txt: deleted. The script existed to feed concat_license_files; with PEP 639 each third-party license ships individually at its own path, so the concatenation step (and the checked-in artifact it produced) are no longer needed.
  • test/test_license.py: drop the source-tree check that validated LICENSES_BUNDLED.txt against build_bundled.py. Replace the dist-info check with one that verifies at least one third-party license is shipped under <dist-info>/licenses/third_party/.

Behavior change for downstream consumers

Compliance is preserved end-to-end — every third-party license still ships in the wheel. The change is layout, not content:

Before After
Top-level *.dist-info/licenses/LICENSE (~342 KB, concatenated) *.dist-info/licenses/LICENSE (bare BSD-3-Clause)
Per-library (none) *.dist-info/licenses/third_party/<lib>/LICENSE

Tools that scanned a single LICENSE file will need to walk the dist-info licenses/ tree instead.

Replaces

This subsumes #182122, which updated test_license.py against main to support both the legacy and PEP 639 layouts. With the migration landing in this PR, the legacy branch becomes unreachable, so the test is rewritten directly here.

Test plan

  • pytest test/test_license.py (skips outside an installed wheel; runs and verifies third-party licenses on a built wheel)
  • Inspect a fresh wheel: *.dist-info/licenses/LICENSE contains only the BSD-3-Clause text; *.dist-info/licenses/third_party/<lib>/LICENSE exists for representative submodules

Co-Generated with Claude Code

cc @XuehaiPan

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Apr 13, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/180237

Note: Links to docs will display an error until the docs builds have been completed.

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

✅ You can merge normally! (2 Unrelated Failures)

As of commit d22cf34 with merge base bef98a5 (image):

FLAKY - The following jobs failed but were likely due to flakiness present on trunk:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

zklaus added a commit to zklaus/pytorch that referenced this pull request Apr 13, 2026
Generate LICENSES_BUNDLED.txt at build time by calling
third_party/build_bundled.py, and install it as LICENSE in the wheel.
The setuptools concat_license_files context manager remains for
setuptools builds.

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


ghstack-source-id: 5762514
Pull-Request: pytorch#180237
@zklaus
zklaus marked this pull request as ready for review April 14, 2026 18:30
@zklaus zklaus added ciflow/binaries Trigger all binary build and upload jobs on the PR release notes: releng release notes category labels Apr 14, 2026
zklaus added a commit to zklaus/pytorch that referenced this pull request Apr 15, 2026
Generate LICENSES_BUNDLED.txt at build time by calling
third_party/build_bundled.py, and install it as LICENSE in the wheel.
The setuptools concat_license_files context manager remains for
setuptools builds.

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


ghstack-source-id: 5762514
Pull-Request: pytorch#180237
zklaus added a commit to zklaus/pytorch that referenced this pull request Apr 17, 2026
Generate LICENSES_BUNDLED.txt at build time by calling
third_party/build_bundled.py, and install it as LICENSE in the wheel.
The setuptools concat_license_files context manager remains for
setuptools builds.

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


ghstack-source-id: 5762514
Pull-Request: pytorch#180237
zklaus added 3 commits April 20, 2026 13:41
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
jemitche1 pushed a commit to jemitche1/pytorch that referenced this pull request May 14, 2026
The PEP 639 migration in the following commit ("Drop setuptools
concat_license_files; adopt PEP 639 license-files") requires
setuptools>=77, which in turn requires packaging>=24.2 to validate
the PEP 639 license expressions in pyproject.toml. The CI docker
image still pinned packaging==24.0.

The version is matched to the floor declared alongside the setuptools
bump in pyproject.toml and requirements-build.txt.

Landing this one-line bump on its own so the docker image refresh
propagates independently of the license PR (pytorchgh-180237), which had
been flaking on docker image rebuild races.

Co-Generated with [Claude Code](https://claude.com/claude-code)
Pull Request resolved: pytorch#183700
Approved by: https://github.com/atalman
Alokksinha00 pushed a commit to Alokksinha00/pytorch that referenced this pull request May 15, 2026
…77644)

Adds `cmake/PostBuildSteps.cmake` with two post-build steps previously handled by `setup.py`'s `build_ext.run()`:

- **`TORCH_STABLE_ONLY` header wrapping** — runs `tools/wrap_headers.py` at install time to add guards to installed headers. Headers wrapped this way error when included with `TORCH_STABLE_ONLY` or `TORCH_TARGET_VERSION` defined.
- **`compile_commands.json` merging** — runs `tools/merge_compile_commands.py` as a build target to combine compile commands from cmake build subdirectories into a single file at the project root.

Both `wrap_headers.py` and `merge_compile_commands.py` are extracted from inline code in `setup.py` into standalone scripts under `tools/`. The corresponding code is removed from `setup.py`'s `build_ext` class (97 lines removed).

This creates the `PostBuildSteps.cmake` module that subsequent PRs (pytorch#180237, pytorch#180238, pytorch#180239) extend with license bundling, Windows DLL bundling, and macOS OpenMP embedding.

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

Pull Request resolved: pytorch#177644
Approved by: https://github.com/atalman
Alokksinha00 pushed a commit to Alokksinha00/pytorch that referenced this pull request May 15, 2026
…torch#180237)

## Context

This PR started out as an attempt to port the license file handling, including the concatenation and overwriting of the original LICENSE to a cmake controlled version. However, that proved tricky and brittle, as particularly the overwrite of the LICENSE file introduces race conditions and failure modes for, for example, subsequent builds in the same directory. Instead, [PEP 639](https://peps.python.org/pep-0639/) gives us a clean alternative by embedding all the license files in the wheel.

That is why this PR ended up also covering some aspects of pytorch#158104, though hopefully with a smaller footprint; because of the discussion over there, I also triggered a manual check of [`inductor-perf-test-nightly-macos.yml`](https://github.com/pytorch/pytorch/actions/runs/25632518115), which came back green.

## Summary

Replace the legacy "concatenate every third-party `LICENSE` into the top-level `LICENSE` during `bdist_wheel`" mechanism with the standard [PEP 639](https://peps.python.org/pep-0639/) `license-files` field. Setuptools 77+ implements PEP 639 with directory-preserving placement at `*.dist-info/licenses/<path>`, and scikit-build-core's `tool.scikit-build.wheel.license-files` was already configured the same way during the migration.

## What changes

- `setup.py`: remove the `concat_license_files` context manager and its `bdist_wheel` / `sdist` command-class overrides.
- `pyproject.toml`: declare `[project].license-files` (mirrors the `tool.scikit-build.wheel.license-files` glob already present), and migrate `license = { text = "BSD-3-Clause" }` to the PEP 639 string form `license = "BSD-3-Clause"` (resolves the existing TODO; the table form is deprecated in setuptools 77+).
- `requirements-build.txt` and the `dev` dependency group: bump `setuptools` to `>=77.0.0`, the first release implementing PEP 639.
- `third_party/build_bundled.py` and `third_party/LICENSES_BUNDLED.txt`: deleted. The script existed to feed `concat_license_files`; with PEP 639 each third-party license ships individually at its own path, so the concatenation step (and the checked-in artifact it produced) are no longer needed.
- `test/test_license.py`: drop the source-tree check that validated `LICENSES_BUNDLED.txt` against `build_bundled.py`. Replace the dist-info check with one that verifies at least one third-party license is shipped under `<dist-info>/licenses/third_party/`.

## Behavior change for downstream consumers

Compliance is preserved end-to-end — every third-party license still ships in the wheel. The change is layout, not content:

| | Before | After |
| --- | --- | --- |
| Top-level | `*.dist-info/licenses/LICENSE` (~342 KB, concatenated) | `*.dist-info/licenses/LICENSE` (bare BSD-3-Clause) |
| Per-library | (none) | `*.dist-info/licenses/third_party/<lib>/LICENSE` |

Tools that scanned a single `LICENSE` file will need to walk the `dist-info` `licenses/` tree instead.

## Replaces

This subsumes pytorch#182122, which updated `test_license.py` against `main` to support both the legacy and PEP 639 layouts. With the migration landing in this PR, the legacy branch becomes unreachable, so the test is rewritten directly here.

## Test plan

- [x] `pytest test/test_license.py` (skips outside an installed wheel; runs and verifies third-party licenses on a built wheel)
- [x] Inspect a fresh wheel: `*.dist-info/licenses/LICENSE` contains only the BSD-3-Clause text; `*.dist-info/licenses/third_party/<lib>/LICENSE` exists for representative submodules

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

Pull Request resolved: pytorch#180237
Approved by: https://github.com/rgommers, https://github.com/atalman, https://github.com/malfet
Alokksinha00 pushed a commit to Alokksinha00/pytorch that referenced this pull request May 15, 2026
Install runtime DLLs (OpenMP, libuv, CUDA) into the wheel on Windows
via CMake install steps, supporting the scikit-build-core migration.
This replaces the equivalent CI copy.bat / copy_cpu.bat scripts that
copied DLLs into the source tree before setuptools ran.

The setup.py logic that copies torch/lib/_C.lib stays in place here;
once _C is built by CMake (later in the stack) the install for that
file moves to the same CMakeLists.txt that defines the target.

Co-Generated with [Claude Code](https://claude.com/claude-code)
Pull Request resolved: pytorch#180238
Approved by: https://github.com/atalman
ghstack dependencies: pytorch#180237
Alokksinha00 pushed a commit to Alokksinha00/pytorch that referenced this pull request May 15, 2026
…80238)"

This reverts commit 1e2a0b0.

Reverted pytorch#180238 on behalf of https://github.com/pytorch-auto-revert due to Reverted automatically by pytorch's autorevert, to avoid this behaviour add the tag autorevert: disable ([comment](pytorch#180237 (comment)))
Alokksinha00 pushed a commit to Alokksinha00/pytorch that referenced this pull request May 15, 2026
…iles (pytorch#180237)"

This reverts commit 70bae40.

Reverted pytorch#180237 on behalf of https://github.com/pytorch-auto-revert due to Reverted automatically by pytorch's autorevert, to avoid this behaviour add the tag autorevert: disable ([comment](pytorch#180237 (comment)))
Alokksinha00 pushed a commit to Alokksinha00/pytorch that referenced this pull request May 15, 2026
…torch#180237)

## Context

This PR started out as an attempt to port the license file handling, including the concatenation and overwriting of the original LICENSE to a cmake controlled version. However, that proved tricky and brittle, as particularly the overwrite of the LICENSE file introduces race conditions and failure modes for, for example, subsequent builds in the same directory. Instead, [PEP 639](https://peps.python.org/pep-0639/) gives us a clean alternative by embedding all the license files in the wheel.

That is why this PR ended up also covering some aspects of pytorch#158104, though hopefully with a smaller footprint; because of the discussion over there, I also triggered a manual check of [`inductor-perf-test-nightly-macos.yml`](https://github.com/pytorch/pytorch/actions/runs/25632518115), which came back green.

## Summary

Replace the legacy "concatenate every third-party `LICENSE` into the top-level `LICENSE` during `bdist_wheel`" mechanism with the standard [PEP 639](https://peps.python.org/pep-0639/) `license-files` field. Setuptools 77+ implements PEP 639 with directory-preserving placement at `*.dist-info/licenses/<path>`, and scikit-build-core's `tool.scikit-build.wheel.license-files` was already configured the same way during the migration.

## What changes

- `setup.py`: remove the `concat_license_files` context manager and its `bdist_wheel` / `sdist` command-class overrides.
- `pyproject.toml`: declare `[project].license-files` (mirrors the `tool.scikit-build.wheel.license-files` glob already present), and migrate `license = { text = "BSD-3-Clause" }` to the PEP 639 string form `license = "BSD-3-Clause"` (resolves the existing TODO; the table form is deprecated in setuptools 77+).
- `requirements-build.txt` and the `dev` dependency group: bump `setuptools` to `>=77.0.0`, the first release implementing PEP 639.
- `third_party/build_bundled.py` and `third_party/LICENSES_BUNDLED.txt`: deleted. The script existed to feed `concat_license_files`; with PEP 639 each third-party license ships individually at its own path, so the concatenation step (and the checked-in artifact it produced) are no longer needed.
- `test/test_license.py`: drop the source-tree check that validated `LICENSES_BUNDLED.txt` against `build_bundled.py`. Replace the dist-info check with one that verifies at least one third-party license is shipped under `<dist-info>/licenses/third_party/`.

## Behavior change for downstream consumers

Compliance is preserved end-to-end — every third-party license still ships in the wheel. The change is layout, not content:

| | Before | After |
| --- | --- | --- |
| Top-level | `*.dist-info/licenses/LICENSE` (~342 KB, concatenated) | `*.dist-info/licenses/LICENSE` (bare BSD-3-Clause) |
| Per-library | (none) | `*.dist-info/licenses/third_party/<lib>/LICENSE` |

Tools that scanned a single `LICENSE` file will need to walk the `dist-info` `licenses/` tree instead.

## Replaces

This subsumes pytorch#182122, which updated `test_license.py` against `main` to support both the legacy and PEP 639 layouts. With the migration landing in this PR, the legacy branch becomes unreachable, so the test is rewritten directly here.

## Test plan

- [x] `pytest test/test_license.py` (skips outside an installed wheel; runs and verifies third-party licenses on a built wheel)
- [x] Inspect a fresh wheel: `*.dist-info/licenses/LICENSE` contains only the BSD-3-Clause text; `*.dist-info/licenses/third_party/<lib>/LICENSE` exists for representative submodules

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

Pull Request resolved: pytorch#180237
Approved by: https://github.com/rgommers, https://github.com/atalman, https://github.com/malfet
Alokksinha00 pushed a commit to Alokksinha00/pytorch that referenced this pull request May 15, 2026
Install runtime DLLs (OpenMP, libuv, CUDA) into the wheel on Windows
via CMake install steps, supporting the scikit-build-core migration.
This replaces the equivalent CI copy.bat / copy_cpu.bat scripts that
copied DLLs into the source tree before setuptools ran.

The setup.py logic that copies torch/lib/_C.lib stays in place here;
once _C is built by CMake (later in the stack) the install for that
file moves to the same CMakeLists.txt that defines the target.

Co-Generated with [Claude Code](https://claude.com/claude-code)
Pull Request resolved: pytorch#180238
Approved by: https://github.com/atalman
ghstack dependencies: pytorch#180237
Alokksinha00 pushed a commit to Alokksinha00/pytorch that referenced this pull request May 15, 2026
…80238)"

This reverts commit a938856.

Reverted pytorch#180238 on behalf of https://github.com/huydhn due to Sorry for reverting your change but another dynamo test failure shows up ([comment](pytorch#180237 (comment)))
Alokksinha00 pushed a commit to Alokksinha00/pytorch that referenced this pull request May 15, 2026
…iles (pytorch#180237)"

This reverts commit abd8c6c.

Reverted pytorch#180237 on behalf of https://github.com/huydhn due to Sorry for reverting your change but another dynamo test failure shows up ([comment](pytorch#180237 (comment)))
pytorchmergebot pushed a commit that referenced this pull request May 15, 2026
The PEP 639 migration in the following commit ("Drop setuptools
concat_license_files; adopt PEP 639 license-files") requires
setuptools>=77, which in turn requires packaging>=24.2 to validate
the PEP 639 license expressions in pyproject.toml. The CI docker
image still pinned packaging==24.0.

The version is matched to the floor declared alongside the setuptools
bump in pyproject.toml and requirements-build.txt.

Landing this one-line bump on its own so the docker image refresh
propagates independently of the license PR (gh-180237), which had
been flaking on docker image rebuild races.

Co-Generated with [Claude Code](https://claude.com/claude-code)
Pull Request resolved: #183700
Approved by: https://github.com/atalman
@zklaus

zklaus commented May 15, 2026

Copy link
Copy Markdown
Collaborator Author

@pytorchbot drci

@zklaus

zklaus commented May 15, 2026

Copy link
Copy Markdown
Collaborator Author

@pytorchbot merge

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge failed

Reason: 1 jobs have failed, first few of them are: windows-arm64-binary-wheel / wheel-py3_12-cpu-build

Details for Dev Infra team Raised by workflow job

@zklaus

zklaus commented May 15, 2026

Copy link
Copy Markdown
Collaborator Author

@pytorchbot merge

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

pytorchmergebot pushed a commit that referenced this pull request May 16, 2026
Install runtime DLLs (OpenMP, libuv, CUDA) into the wheel on Windows
via CMake install steps, supporting the scikit-build-core migration.
This replaces the equivalent CI copy.bat / copy_cpu.bat scripts that
copied DLLs into the source tree before setuptools ran.

The setup.py logic that copies torch/lib/_C.lib stays in place here;
once _C is built by CMake (later in the stack) the install for that
file moves to the same CMakeLists.txt that defines the target.

Co-Generated with [Claude Code](https://claude.com/claude-code)
Pull Request resolved: #180238
Approved by: https://github.com/atalman
ghstack dependencies: #183700, #180237
@github-actions
github-actions Bot deleted the gh/zklaus/43/head branch June 15, 2026 02:28
aperson30 pushed a commit to aperson30/pytorch that referenced this pull request Jun 20, 2026
…77644)

Adds `cmake/PostBuildSteps.cmake` with two post-build steps previously handled by `setup.py`'s `build_ext.run()`:

- **`TORCH_STABLE_ONLY` header wrapping** — runs `tools/wrap_headers.py` at install time to add guards to installed headers. Headers wrapped this way error when included with `TORCH_STABLE_ONLY` or `TORCH_TARGET_VERSION` defined.
- **`compile_commands.json` merging** — runs `tools/merge_compile_commands.py` as a build target to combine compile commands from cmake build subdirectories into a single file at the project root.

Both `wrap_headers.py` and `merge_compile_commands.py` are extracted from inline code in `setup.py` into standalone scripts under `tools/`. The corresponding code is removed from `setup.py`'s `build_ext` class (97 lines removed).

This creates the `PostBuildSteps.cmake` module that subsequent PRs (pytorch#180237, pytorch#180238, pytorch#180239) extend with license bundling, Windows DLL bundling, and macOS OpenMP embedding.

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

Pull Request resolved: pytorch#177644
Approved by: https://github.com/atalman
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autorevert: disable Disable autorevert for a specific PR ci-no-td Do not run TD on this PR ciflow/binaries Trigger all binary build and upload jobs on the PR ciflow/trunk Trigger trunk jobs on your pull request Merged no-runner-experiments Bypass Meta/LF runner determinator open source release notes: releng release notes category Reverted suppress-bc-linter Suppresses the failures of API backward-compatibility linter (Lint/bc_linter) topic: not user facing topic category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants