Skip to content

Update test_license.py for PEP 639 license layout - #182122

Closed
zklaus wants to merge 1 commit into
pytorch:mainfrom
zklaus:update-test-license-for-pep-639
Closed

zklaus wants to merge 1 commit into
pytorch:mainfrom
zklaus:update-test-license-for-pep-639

Conversation

@zklaus

@zklaus zklaus commented May 1, 2026

Copy link
Copy Markdown
Collaborator

PEP 639 standardizes how license files are included in Python packages, placing them in a licenses/ subdirectory of dist-info. Both setuptools 77+ and scikit-build-core follow this layout. Update the test to check both the legacy combined LICENSE file and the PEP 639 directory structure.

Co-Generated with Claude Code

Replaces #180244.

PEP 639 standardizes how license files are included in Python
packages, placing them in a licenses/ subdirectory of dist-info.
Both setuptools 77+ and scikit-build-core follow this layout.
Update the test to check both the legacy combined LICENSE file
and the PEP 639 directory structure.

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

pytorch-bot Bot commented May 1, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❌ 14 Cancelled Jobs

As of commit 0f50565 with merge base 7e49a76 (image):

CANCELLED JOBS - The following jobs were cancelled. Please retry:

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

@pytorch-bot pytorch-bot Bot added the topic: not user facing topic category label May 1, 2026
@zklaus zklaus added open source ciflow/binaries Trigger all binary build and upload jobs on the PR ciflow/trunk Trigger trunk jobs on your pull request release notes: releng release notes category labels May 1, 2026
@atalman

atalman commented May 5, 2026

Copy link
Copy Markdown
Collaborator

@claude please review this PR

@claude

claude Bot commented May 5, 2026 •

Copy link
Copy Markdown

Claude finished @atalman's task in 1m 28s —— View job


PR Review: Update test_license.py for PEP 639 license layout

  • Gather context and read changed files
  • Analyze the changes for correctness and style
  • Post review feedback

Summary: This PR updates test_distinfo_license to handle the PEP 639 license directory layout where setuptools 77+ and scikit-build-core place license files in a licenses/ subdirectory of dist-info, potentially with individual third-party license files rather than a single combined bundle.

Overall: Looks good. The logic is clear and covers the three relevant scenarios correctly:

  1. Combined LICENSE file containing all third-party licenses (legacy setup.py behavior)
  2. Separate LICENSES_BUNDLED.txt in licenses/third_party/
  3. Individual license files in licenses/third_party/

Minor observations

  1. test/test_license.py:50-52 — Missing file handling: If neither licenses/LICENSE nor LICENSE exists in dist-info, the open(license_file) on line 53 will raise an unhandled FileNotFoundError. This isn't a regression (the pre-existing code had the same behavior), but could be made more informative with a targeted assertion. Not blocking.

  2. test/test_license.py:65-67 — Glob pattern: The glob.glob(..., recursive=True) with "**" will match both files and directories, but the any(os.path.isfile(f) ...) filter on line 70 correctly handles this. Good.

  3. test/test_license.py:50 — Variable shadowing: The local license_file shadows the module-level license_file defined on line 17. This was already the case before this PR and doesn't cause issues since the test method doesn't need the module-level value, but worth noting for future readers.

  4. Style nit: The docstring on line 39-41 could be updated since it now says "Make sure it contains the third party bundle of licenses" but the test now accepts multiple valid layouts. Very minor — not blocking.

No bugs or correctness issues found. The change is well-structured and the fallback logic is sound.

Verdict: Approve ✓

@zklaus

zklaus commented May 8, 2026

Copy link
Copy Markdown
Collaborator Author

Closing in favor of folding this into #180237 — that PR is what makes the legacy combined-LICENSE codepath disappear, so it's the right place to update the test. The fixup there also drops third_party/build_bundled.py and third_party/LICENSES_BUNDLED.txt, which become dead source once concat_license_files is gone.

@zklaus zklaus closed this May 8, 2026
pytorchmergebot pushed a commit that referenced this pull request May 13, 2026
…80237)

## 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 #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 #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: #180237
Approved by: https://github.com/rgommers, https://github.com/atalman, https://github.com/malfet
pytorchmergebot pushed a commit that referenced this pull request May 13, 2026
…80237)

## 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 #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 #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: #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
…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
…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
pytorchmergebot pushed a commit that referenced this pull request May 15, 2026
…80237)

## 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 #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 #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: #180237
Approved by: https://github.com/rgommers, https://github.com/atalman, https://github.com/malfet
ghstack dependencies: #183700
gplutop7 pushed a commit to gplutop7/pytorch that referenced this pull request Jul 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
gplutop7 pushed a commit to gplutop7/pytorch that referenced this pull request Jul 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
gplutop7 pushed a commit to gplutop7/pytorch that referenced this pull request Jul 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
ghstack dependencies: pytorch#183700
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 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
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 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
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 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
ghstack dependencies: pytorch#183700
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/binaries Trigger all binary build and upload jobs on the PR ciflow/trunk Trigger trunk jobs on your pull request open source release notes: releng release notes category topic: not user facing topic category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants