mirror of
https://github.com/pytorch/pytorch.git
synced 2026-10-25 18:53:39 +08:00
With the build fully driven by scikit-build-core (#180247), the setuptools path is dead code. Remove the setuptools build helpers (build_pytorch_libs, setup_helpers.{cmake,cmake_utils,env}, test_cmake) and replace setup.py with a small shim that forwards `install` and `develop` to pip and fails with instructions for everything else. Retain a minimal build_libtorch.py -- it calls cmake directly and is still used by the libtorch build path. ## Why a phased sunset instead of outright removal? pip and `python -m build` never execute setup.py; the only way it still runs is a direct `python setup.py <cmd>` invocation. For `install` and `develop` we have redirected to pip since #152276; the shim keeps that contract intact for two more releases so existing scripts keep working while they migrate. Every other command (`build`, `bdist_wheel`, `clean`, `sdist`, ...) used to fall through into the setuptools machinery this PR deletes; emulating that interface is not worth it (setuptools itself deprecated it in 2021), so those commands now fail immediately, printing the replacement commands and the sunset schedule -- a more helpful failure mode than `can't open file 'setup.py'` while still surfacing not-yet-migrated callers. The schedule is stated in the shim header and printed on every invocation: - PyTorch 2.14-2.15: `install`/`develop` forward to pip; all other commands fail with instructions - PyTorch 2.16-2.17: all commands fail with instructions - PyTorch 2.18: setup.py is removed ## Test plan - [x] **Wheel byte-identical to parent #180247**: empty manifest diff, +10 B zip-timestamp noise. Removing the dead setuptools machinery does not change wheel content (it is never shipped, and scikit-build-core does not use it). The shim cannot change this: nothing installs the root setup.py into the wheel. ``` diff <(unzip -Z1 247.whl | sort) <(unzip -Z1 248.whl | sort) # empty ``` - [x] **Shim forwarding**: `install`/`develop` forward to pip with the exact #152276 command line, extra arguments are dropped with a warning, and pip's exit code is propagated (verified with a stub pip that prints its argv and exits 3): ``` python setup.py develop --user # pip install -v --no-build-isolation -e ., warns about dropped --user python setup.py install # pip install -v --no-build-isolation . ``` - [x] **Shim guard**: every other command fails with exit code 1, printing the replacement commands and the sunset schedule: ``` python setup.py bdist_wheel ``` - [x] **No dangling references** to the removed modules (`build_pytorch_libs`, `setup_helpers.{cmake,cmake_utils,env}`, `test_cmake`); the remaining `tools/setup_helpers` references point to surviving files (`generate_code.py`, `gen_version_header.py`, `generate_linker_script.py`). ``` grep -rE 'build_pytorch_libs|setup_helpers\.(cmake|env)' --include='*.py' . ``` - [x] **0 build failures** across the matrix -- the removed path was genuinely dead. Co-Generated with [Claude Code](https://claude.com/claude-code) Pull Request resolved: https://github.com/pytorch/pytorch/pull/180248 Approved by: https://github.com/albanD, https://github.com/atalman
65 lines
2.3 KiB
Python
65 lines
2.3 KiB
Python
# PyTorch is built with scikit-build-core through the PEP 517 interface
|
|
# declared in pyproject.toml; pip and `python -m build` never run this
|
|
# file. It exists only for direct `python setup.py <command>` calls:
|
|
# install and develop are forwarded to pip, everything else fails with
|
|
# instructions (#180248).
|
|
#
|
|
# Deprecation schedule:
|
|
# PyTorch 2.14-2.15: install and develop forward to pip
|
|
# PyTorch 2.16-2.17: all commands fail with instructions
|
|
# PyTorch 2.18: this file is removed
|
|
#
|
|
# See https://github.com/pytorch/pytorch/issues/152276 for background.
|
|
|
|
import shlex
|
|
import subprocess
|
|
import sys
|
|
import warnings
|
|
|
|
|
|
PIP_INSTALL = [sys.executable, "-m", "pip", "install", "-v", "--no-build-isolation"]
|
|
FORWARDS = {
|
|
"install": [*PIP_INSTALL, "."],
|
|
"develop": [*PIP_INSTALL, "-e", "."],
|
|
}
|
|
|
|
DEPRECATION_NOTICE = """\
|
|
`python setup.py {command}` is deprecated: PyTorch is built with
|
|
scikit-build-core via the standard PEP 517 interface (pyproject.toml),
|
|
and setup.py is no longer part of the build.
|
|
|
|
Deprecation schedule:
|
|
PyTorch 2.14-2.15: install and develop forward to pip
|
|
(current behavior); other commands fail
|
|
PyTorch 2.16-2.17: all commands fail with instructions
|
|
PyTorch 2.18: setup.py is removed
|
|
|
|
Replacement commands:
|
|
install: spin install (or: pip install --no-build-isolation -v .)
|
|
editable install: spin develop (or: pip install --no-build-isolation -v -e .)
|
|
wheel: python -m build --wheel --no-isolation
|
|
sdist: python -m build --sdist
|
|
|
|
Build customization through environment variables (DEBUG=1, USE_CUDA=0,
|
|
MAX_JOBS=..., etc.) works unchanged with the replacement commands. See
|
|
the "From Source" section of README.md for details and
|
|
https://github.com/pytorch/pytorch/issues/152276 for background.
|
|
"""
|
|
|
|
|
|
def main() -> int:
|
|
command = sys.argv[1] if len(sys.argv) > 1 else "<command>"
|
|
notice = DEPRECATION_NOTICE.format(command=command)
|
|
replacement = FORWARDS.get(command)
|
|
if replacement is None:
|
|
raise SystemExit(f"error: {notice}")
|
|
warnings.warn(notice, DeprecationWarning)
|
|
if len(sys.argv) > 2:
|
|
warnings.warn(f"ignoring extra arguments: {shlex.join(sys.argv[2:])}")
|
|
print(f"Forwarding to `{shlex.join(replacement)}`.", file=sys.stderr)
|
|
return subprocess.run(replacement).returncode
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|