Skip to content

Replace deprecated distutils usage - #182120

Closed
zklaus wants to merge 6 commits into
pytorch:mainfrom
zklaus:replace-distutils
Closed

zklaus wants to merge 6 commits into
pytorch:mainfrom
zklaus:replace-distutils

Conversation

@zklaus

@zklaus zklaus commented May 1, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Replace deprecated distutils usage in CI scripts and tooling, in preparation
for Python 3.12+ (where distutils is removed). Two patterns are handled:

  • distutils.sysconfig.get_python_lib() → sysconfig.get_path("purelib") in
    .ci/pytorch/macos-test.sh, .ci/pytorch/test.sh, and
    .ci/pytorch/smoke_test/check_binary_symbols.py.
  • distutils.util.strtobool → a small local replacement in
    tools/strtobool.py, imported by .github/scripts/generate_pytorch_version.py,
    tools/generate_torch_version.py, and tools/alerts/create_alerts.py.

Suggested review order

  1. tools/strtobool.py — the consolidated helper, semantically identical to
    the removed distutils.util.strtobool.
  2. The three Python call sites that import it. .github/scripts/... uses the
    same sys.path shim already established in
    .github/scripts/close_nonexistent_disable_issues.py for cross-importing
    from tools/.
  3. The sysconfig substitutions in the shell scripts and
    check_binary_symbols.py — mechanical.
Out of scope (intentional)
  • tools/build_pytorch_libs.py (distutils._msvccompiler._get_vc_env):
    deferred to a follow-up — the API is private and the replacement is not a
    one-liner.
  • tools/setup_helpers/cmake.py (from distutils.version import LooseVersion)
    and setup.py (setuptools.distutils.log.warn): both files are deleted
    outright by the scikit-build-core migration (Replace setup.py with a deprecation shim, remove setuptools helpers #180248); fixing them here
    would just create merge conflicts.
  • test/run_test.py:135's strtobool: deliberately permissive
    (s.lower() not in {"", "0", "false", "off"}) and never raises. Switching
    to the strict distutils-style helper would change behavior for callers
    passing non-canonical truthy values such as TEST_SHOWLOCALS=yeah.
  • Other str2bool variants in benchmarks/operator_benchmark/,
    torch/utils/hipify/, and .ci/lumen_cli/ do not use distutils and are
    not in this PR's scope.

Replaces #180241.

Authored with Claude.

@pytorch-bot pytorch-bot Bot added the release notes: releng release notes category label May 1, 2026
@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/182120

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

✅ No Failures, 18 Unclassified Failures

As of commit 2e7df7a with merge base b14e6fb (image):
💚 Looks good so far! There are no failures yet. 💚

UNCLASSIFIED FAILURES - DrCI could not classify the following jobs because the workflow did not run on the merge base. The failures may be pre-existing on trunk or introduced by this PR:

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

@zklaus zklaus added ciflow/binaries Trigger all binary build and upload jobs on the PR ciflow/trunk Trigger trunk jobs on your pull request topic: not user facing topic category open source labels May 1, 2026
@zklaus
zklaus force-pushed the replace-distutils branch from d3af72d to bbd8d5e Compare May 5, 2026 10:31
@zklaus zklaus changed the title Replace deprecated distutils usage with sysconfig in CI scripts Replace deprecated distutils usage May 5, 2026
@zklaus
zklaus force-pushed the replace-distutils branch from bbd8d5e to 613ae6e Compare May 6, 2026 08:43
@zklaus
zklaus marked this pull request as ready for review May 6, 2026 08:43
@zklaus
zklaus requested a review from a team as a code owner May 6, 2026 08:43
@zklaus

zklaus commented May 6, 2026

Copy link
Copy Markdown
Collaborator Author

@pytorchbot merge -i "Rocm failures unrelated"

@pytorch-bot

pytorch-bot Bot commented May 6, 2026

Copy link
Copy Markdown

❌ 🤖 pytorchbot command failed:

@pytorchbot: error: unrecognized arguments: Rocm failures unrelated

usage: @pytorchbot [-h]
                   
                   {merge,revert,rebase,label,drci,lint,fix-lint,apply-lint,cherry-pick}
                   ...

Try @pytorchbot --help for more info.

@zklaus

zklaus commented May 6, 2026

Copy link
Copy Markdown
Collaborator Author

@pytorchbot merge -i

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge failed

Reason: HTTP Error 504: Gateway Timeout

Details for Dev Infra team Raised by workflow job

@zklaus

zklaus commented May 7, 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 mandatory check(s) failed. The first few are:

Dig deeper by viewing the failures on hud

Details for Dev Infra team Raised by workflow job

Failing merge rule: Core Maintainers

@zklaus
zklaus force-pushed the replace-distutils branch 2 times, most recently from 7d289c4 to 5a0120e Compare May 8, 2026 12:14
zklaus added 2 commits May 9, 2026 11:25
Replace distutils.sysconfig.get_python_lib() with
sysconfig.get_path("purelib") in CI test scripts, and add a local
strtobool() to replace distutils.util.strtobool (removed in
Python 3.12).

Co-Generated with [Claude Code](https://claude.com/claude-code)
zklaus added 4 commits May 9, 2026 11:25
In tools/generate_torch_version.py and tools/alerts/create_alerts.py
strtobool is only used as the argparse type= for boolean flags, so it
is needed only on the CLI path. Importing it at module top-level
forces every library consumer to have the project root on sys.path so
that "from tools.strtobool import strtobool" resolves -- a constraint
that is invisible to readers and easy to break under non-standard
load paths (for example, loading the file via
importlib.util.spec_from_file_location).

Move the import inside the if __name__ == "__main__" block (or, for
create_alerts.py, inside parse_args) so library imports do not depend
on it.

Authored by Claude.
Cover the truthy aliases, falsy aliases, and the ValueError path that
the docstring promises, so future drift between this and the removed
distutils.util.strtobool surfaces locally instead of as an argparse
failure deep in CI.

Authored by Claude.
@zklaus
zklaus force-pushed the replace-distutils branch from 5a0120e to 2e7df7a Compare May 9, 2026 09:25
@cyyever

cyyever commented May 10, 2026

Copy link
Copy Markdown
Collaborator

@pytorchbot merge -i

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

dsashidh pushed a commit to dsashidh/pytorch that referenced this pull request May 13, 2026
## Summary

Replace deprecated `distutils` usage in CI scripts and tooling, in preparation
for Python 3.12+ (where `distutils` is removed). Two patterns are handled:

- `distutils.sysconfig.get_python_lib()` → `sysconfig.get_path("purelib")` in
  `.ci/pytorch/macos-test.sh`, `.ci/pytorch/test.sh`, and
  `.ci/pytorch/smoke_test/check_binary_symbols.py`.
- `distutils.util.strtobool` → a small local replacement in
  `tools/strtobool.py`, imported by `.github/scripts/generate_pytorch_version.py`,
  `tools/generate_torch_version.py`, and `tools/alerts/create_alerts.py`.

## Suggested review order

1. `tools/strtobool.py` — the consolidated helper, semantically identical to
   the removed `distutils.util.strtobool`.
2. The three Python call sites that import it. `.github/scripts/...` uses the
   same `sys.path` shim already established in
   `.github/scripts/close_nonexistent_disable_issues.py` for cross-importing
   from `tools/`.
3. The `sysconfig` substitutions in the shell scripts and
   `check_binary_symbols.py` — mechanical.

<details>
<summary>Out of scope (intentional)</summary>

- `tools/build_pytorch_libs.py` (`distutils._msvccompiler._get_vc_env`):
  deferred to a follow-up — the API is private and the replacement is not a
  one-liner.
- `tools/setup_helpers/cmake.py` (`from distutils.version import LooseVersion`)
  and `setup.py` (`setuptools.distutils.log.warn`): both files are deleted
  outright by the scikit-build-core migration (pytorch#180248); fixing them here
  would just create merge conflicts.
- `test/run_test.py:135`'s `strtobool`: deliberately permissive
  (`s.lower() not in {"", "0", "false", "off"}`) and never raises. Switching
  to the strict distutils-style helper would change behavior for callers
  passing non-canonical truthy values such as `TEST_SHOWLOCALS=yeah`.
- Other `str2bool` variants in `benchmarks/operator_benchmark/`,
  `torch/utils/hipify/`, and `.ci/lumen_cli/` do not use `distutils` and are
  not in this PR's scope.

</details>

Replaces pytorch#180241.

Authored with Claude.

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

Replace deprecated `distutils` usage in CI scripts and tooling, in preparation
for Python 3.12+ (where `distutils` is removed). Two patterns are handled:

- `distutils.sysconfig.get_python_lib()` → `sysconfig.get_path("purelib")` in
  `.ci/pytorch/macos-test.sh`, `.ci/pytorch/test.sh`, and
  `.ci/pytorch/smoke_test/check_binary_symbols.py`.
- `distutils.util.strtobool` → a small local replacement in
  `tools/strtobool.py`, imported by `.github/scripts/generate_pytorch_version.py`,
  `tools/generate_torch_version.py`, and `tools/alerts/create_alerts.py`.

## Suggested review order

1. `tools/strtobool.py` — the consolidated helper, semantically identical to
   the removed `distutils.util.strtobool`.
2. The three Python call sites that import it. `.github/scripts/...` uses the
   same `sys.path` shim already established in
   `.github/scripts/close_nonexistent_disable_issues.py` for cross-importing
   from `tools/`.
3. The `sysconfig` substitutions in the shell scripts and
   `check_binary_symbols.py` — mechanical.

<details>
<summary>Out of scope (intentional)</summary>

- `tools/build_pytorch_libs.py` (`distutils._msvccompiler._get_vc_env`):
  deferred to a follow-up — the API is private and the replacement is not a
  one-liner.
- `tools/setup_helpers/cmake.py` (`from distutils.version import LooseVersion`)
  and `setup.py` (`setuptools.distutils.log.warn`): both files are deleted
  outright by the scikit-build-core migration (pytorch#180248); fixing them here
  would just create merge conflicts.
- `test/run_test.py:135`'s `strtobool`: deliberately permissive
  (`s.lower() not in {"", "0", "false", "off"}`) and never raises. Switching
  to the strict distutils-style helper would change behavior for callers
  passing non-canonical truthy values such as `TEST_SHOWLOCALS=yeah`.
- Other `str2bool` variants in `benchmarks/operator_benchmark/`,
  `torch/utils/hipify/`, and `.ci/lumen_cli/` do not use `distutils` and are
  not in this PR's scope.

</details>

Replaces pytorch#180241.

Authored with Claude.

Pull Request resolved: pytorch#182120
Approved by: https://github.com/atalman
aperson30 pushed a commit to aperson30/pytorch that referenced this pull request Jun 20, 2026
## Summary

Replace deprecated `distutils` usage in CI scripts and tooling, in preparation
for Python 3.12+ (where `distutils` is removed). Two patterns are handled:

- `distutils.sysconfig.get_python_lib()` → `sysconfig.get_path("purelib")` in
  `.ci/pytorch/macos-test.sh`, `.ci/pytorch/test.sh`, and
  `.ci/pytorch/smoke_test/check_binary_symbols.py`.
- `distutils.util.strtobool` → a small local replacement in
  `tools/strtobool.py`, imported by `.github/scripts/generate_pytorch_version.py`,
  `tools/generate_torch_version.py`, and `tools/alerts/create_alerts.py`.

## Suggested review order

1. `tools/strtobool.py` — the consolidated helper, semantically identical to
   the removed `distutils.util.strtobool`.
2. The three Python call sites that import it. `.github/scripts/...` uses the
   same `sys.path` shim already established in
   `.github/scripts/close_nonexistent_disable_issues.py` for cross-importing
   from `tools/`.
3. The `sysconfig` substitutions in the shell scripts and
   `check_binary_symbols.py` — mechanical.

<details>
<summary>Out of scope (intentional)</summary>

- `tools/build_pytorch_libs.py` (`distutils._msvccompiler._get_vc_env`):
  deferred to a follow-up — the API is private and the replacement is not a
  one-liner.
- `tools/setup_helpers/cmake.py` (`from distutils.version import LooseVersion`)
  and `setup.py` (`setuptools.distutils.log.warn`): both files are deleted
  outright by the scikit-build-core migration (pytorch#180248); fixing them here
  would just create merge conflicts.
- `test/run_test.py:135`'s `strtobool`: deliberately permissive
  (`s.lower() not in {"", "0", "false", "off"}`) and never raises. Switching
  to the strict distutils-style helper would change behavior for callers
  passing non-canonical truthy values such as `TEST_SHOWLOCALS=yeah`.
- Other `str2bool` variants in `benchmarks/operator_benchmark/`,
  `torch/utils/hipify/`, and `.ci/lumen_cli/` do not use `distutils` and are
  not in this PR's scope.

</details>

Replaces pytorch#180241.

Authored with Claude.

Pull Request resolved: pytorch#182120
Approved by: https://github.com/atalman
gplutop7 pushed a commit to gplutop7/pytorch that referenced this pull request Jul 15, 2026
## Summary

Replace deprecated `distutils` usage in CI scripts and tooling, in preparation
for Python 3.12+ (where `distutils` is removed). Two patterns are handled:

- `distutils.sysconfig.get_python_lib()` → `sysconfig.get_path("purelib")` in
  `.ci/pytorch/macos-test.sh`, `.ci/pytorch/test.sh`, and
  `.ci/pytorch/smoke_test/check_binary_symbols.py`.
- `distutils.util.strtobool` → a small local replacement in
  `tools/strtobool.py`, imported by `.github/scripts/generate_pytorch_version.py`,
  `tools/generate_torch_version.py`, and `tools/alerts/create_alerts.py`.

## Suggested review order

1. `tools/strtobool.py` — the consolidated helper, semantically identical to
   the removed `distutils.util.strtobool`.
2. The three Python call sites that import it. `.github/scripts/...` uses the
   same `sys.path` shim already established in
   `.github/scripts/close_nonexistent_disable_issues.py` for cross-importing
   from `tools/`.
3. The `sysconfig` substitutions in the shell scripts and
   `check_binary_symbols.py` — mechanical.

<details>
<summary>Out of scope (intentional)</summary>

- `tools/build_pytorch_libs.py` (`distutils._msvccompiler._get_vc_env`):
  deferred to a follow-up — the API is private and the replacement is not a
  one-liner.
- `tools/setup_helpers/cmake.py` (`from distutils.version import LooseVersion`)
  and `setup.py` (`setuptools.distutils.log.warn`): both files are deleted
  outright by the scikit-build-core migration (pytorch#180248); fixing them here
  would just create merge conflicts.
- `test/run_test.py:135`'s `strtobool`: deliberately permissive
  (`s.lower() not in {"", "0", "false", "off"}`) and never raises. Switching
  to the strict distutils-style helper would change behavior for callers
  passing non-canonical truthy values such as `TEST_SHOWLOCALS=yeah`.
- Other `str2bool` variants in `benchmarks/operator_benchmark/`,
  `torch/utils/hipify/`, and `.ci/lumen_cli/` do not use `distutils` and are
  not in this PR's scope.

</details>

Replaces pytorch#180241.

Authored with Claude.

Pull Request resolved: pytorch#182120
Approved by: https://github.com/atalman
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
## Summary

Replace deprecated `distutils` usage in CI scripts and tooling, in preparation
for Python 3.12+ (where `distutils` is removed). Two patterns are handled:

- `distutils.sysconfig.get_python_lib()` → `sysconfig.get_path("purelib")` in
  `.ci/pytorch/macos-test.sh`, `.ci/pytorch/test.sh`, and
  `.ci/pytorch/smoke_test/check_binary_symbols.py`.
- `distutils.util.strtobool` → a small local replacement in
  `tools/strtobool.py`, imported by `.github/scripts/generate_pytorch_version.py`,
  `tools/generate_torch_version.py`, and `tools/alerts/create_alerts.py`.

## Suggested review order

1. `tools/strtobool.py` — the consolidated helper, semantically identical to
   the removed `distutils.util.strtobool`.
2. The three Python call sites that import it. `.github/scripts/...` uses the
   same `sys.path` shim already established in
   `.github/scripts/close_nonexistent_disable_issues.py` for cross-importing
   from `tools/`.
3. The `sysconfig` substitutions in the shell scripts and
   `check_binary_symbols.py` — mechanical.

<details>
<summary>Out of scope (intentional)</summary>

- `tools/build_pytorch_libs.py` (`distutils._msvccompiler._get_vc_env`):
  deferred to a follow-up — the API is private and the replacement is not a
  one-liner.
- `tools/setup_helpers/cmake.py` (`from distutils.version import LooseVersion`)
  and `setup.py` (`setuptools.distutils.log.warn`): both files are deleted
  outright by the scikit-build-core migration (pytorch#180248); fixing them here
  would just create merge conflicts.
- `test/run_test.py:135`'s `strtobool`: deliberately permissive
  (`s.lower() not in {"", "0", "false", "off"}`) and never raises. Switching
  to the strict distutils-style helper would change behavior for callers
  passing non-canonical truthy values such as `TEST_SHOWLOCALS=yeah`.
- Other `str2bool` variants in `benchmarks/operator_benchmark/`,
  `torch/utils/hipify/`, and `.ci/lumen_cli/` do not use `distutils` and are
  not in this PR's scope.

</details>

Replaces pytorch#180241.

Authored with Claude.

Pull Request resolved: pytorch#182120
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

ciflow/binaries Trigger all binary build and upload jobs on the PR ciflow/trunk Trigger trunk jobs on your pull request Merged 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.

4 participants