diff --git a/.ci/docker/requirements-ci.txt b/.ci/docker/requirements-ci.txt index d4bdd9b2a9cb..aeb2807c74e5 100644 --- a/.ci/docker/requirements-ci.txt +++ b/.ci/docker/requirements-ci.txt @@ -363,10 +363,11 @@ pwlf==2.2.1 #Pinned versions: 2.2.1 #test that import: test_sac_estimator.py -# To build PyTorch itself +# To build PyTorch itself (see also pyproject.toml) +packaging>=24.2 pyyaml pyzstd -setuptools>=70.1.0 +setuptools>=77.0.0 six scons==4.5.2 ; platform_machine == "aarch64" diff --git a/.ci/pytorch/build.sh b/.ci/pytorch/build.sh index 65f97389324a..8099eeeb902c 100755 --- a/.ci/pytorch/build.sh +++ b/.ci/pytorch/build.sh @@ -243,6 +243,10 @@ if [[ "$BUILD_ENVIRONMENT" == *-bazel-* ]]; then tools/bazel build --config=no-tty "${BAZEL_MEM_LIMIT}" "${BAZEL_CPU_LIMIT}" //... fi else + # Install build-system requirements before running setup.py commands + # We need manage the build environment manually because we are not using build isolation + python -m pip install -r requirements-build.txt + # check that setup.py would fail with bad arguments echo "The next three invocations are expected to fail with invalid command error messages." ( ! get_exit_code python setup.py bad_argument ) diff --git a/.ci/pytorch/macos-build.sh b/.ci/pytorch/macos-build.sh index d7447e7d4858..f8d8a6f23b80 100755 --- a/.ci/pytorch/macos-build.sh +++ b/.ci/pytorch/macos-build.sh @@ -33,6 +33,10 @@ if which sccache > /dev/null; then export PATH="${tmp_dir}:$PATH" fi +# Install build-system requirements before running setup.py commands +# We need manage the build environment manually because we are not using build isolation +python -m pip install -r requirements-build.txt + print_cmake_info if [[ ${BUILD_ENVIRONMENT} == *"distributed"* ]]; then # Needed for inductor benchmarks, as lots of HF networks make `torch.distribtued` calls diff --git a/.ci/pytorch/macos-test.sh b/.ci/pytorch/macos-test.sh index c9d926a5df37..dcd557a70616 100755 --- a/.ci/pytorch/macos-test.sh +++ b/.ci/pytorch/macos-test.sh @@ -16,17 +16,31 @@ popd # enable debug asserts in serialization export TORCH_SERIALIZATION_DEBUG=1 +export __TEST_PYTHON_HAS_SETUP='' + setup_test_python() { + if [[ -n "${__TEST_PYTHON_HAS_SETUP}" ]]; then + return + fi + # The CircleCI worker hostname doesn't resolve to an address. # This environment variable makes ProcessGroupGloo default to # using the address associated with the loopback interface. export GLOO_SOCKET_IFNAME=lo0 - echo "Ninja version: $(ninja --version)" echo "Python version: $(which python) ($(python --version))" + python -m pip install -qr requirements-build.txt + + echo "CMake version: $(cmake --version)" + echo "Ninja version: $(ninja --version)" + + echo "Python packages:" + python -m pip freeze # Set the limit on open file handles to 16384 # might help with intermittent compiler test failures ulimit -n 16384 + + export __TEST_PYTHON_HAS_SETUP=1 } test_python_all() { @@ -184,6 +198,8 @@ checkout_install_torchbench() { } torchbench_setup_macos() { + setup_test_python + git clone --recursive https://github.com/pytorch/vision torchvision git clone --recursive https://github.com/pytorch/audio torchaudio brew install jpeg-turbo libpng diff --git a/.ci/pytorch/win-test-helpers/build_pytorch.bat b/.ci/pytorch/win-test-helpers/build_pytorch.bat index 7ceb425ce2d1..2e0c798d042a 100644 --- a/.ci/pytorch/win-test-helpers/build_pytorch.bat +++ b/.ci/pytorch/win-test-helpers/build_pytorch.bat @@ -126,6 +126,12 @@ if "%USE_CUDA%"=="1" ( set CMAKE_CUDA_COMPILER_LAUNCHER=%TMP_DIR%/bin/randomtemp.exe;%TMP_DIR%\bin\sccache.exe ) +:: Install build-system requirements before running setup.py commands +:: We need manage the build environment manually because we are not using build isolation +python -m pip install -r requirements-build.txt +if errorlevel 1 goto fail +if not errorlevel 0 goto fail + :: Print all existing environment variable for debugging set diff --git a/.ci/pytorch/windows/setup_build.bat b/.ci/pytorch/windows/setup_build.bat index 9b492eef664d..bdab16f0e594 100644 --- a/.ci/pytorch/windows/setup_build.bat +++ b/.ci/pytorch/windows/setup_build.bat @@ -7,6 +7,7 @@ call "internal\install_python.bat" %PYTHON_EXEC% --version set "PATH=%CD%\Python\Lib\site-packages\cmake\data\bin;%CD%\Python\Scripts;%CD%\Python;%PATH%" + if "%DESIRED_PYTHON%" == "3.13t" %PYTHON_EXEC% -m pip install numpy==2.2.1 cmake if "%DESIRED_PYTHON%" == "3.13" %PYTHON_EXEC% -m pip install numpy==2.1.2 cmake if "%DESIRED_PYTHON%" == "3.12" %PYTHON_EXEC% -m pip install numpy==2.0.2 cmake @@ -16,7 +17,7 @@ if "%DESIRED_PYTHON%" == "3.9" %PYTHON_EXEC% -m pip install numpy==2.0.2 cmake %PYTHON_EXEC% -m pip install pyyaml %PYTHON_EXEC% -m pip install mkl-include mkl-static -%PYTHON_EXEC% -m pip install boto3 ninja typing_extensions setuptools==72.1.0 +%PYTHON_EXEC% -m pip install boto3 ninja typing-extensions setuptools packaging where cmake.exe diff --git a/.ci/wheel/build_wheel.sh b/.ci/wheel/build_wheel.sh index b90e6f38e911..40b74d3e92b1 100755 --- a/.ci/wheel/build_wheel.sh +++ b/.ci/wheel/build_wheel.sh @@ -127,7 +127,7 @@ export INSTALL_TEST=0 # dont install test binaries into site-packages export MACOSX_DEPLOYMENT_TARGET=10.15 export CMAKE_PREFIX_PATH=${CONDA_PREFIX:-"$(dirname $(which conda))/../"} -SETUPTOOLS_PINNED_VERSION="==70.1.0" +SETUPTOOLS_PINNED_VERSION="==77.0.0" PYYAML_PINNED_VERSION="=5.3" EXTRA_CONDA_INSTALL_FLAGS="" CONDA_ENV_CREATE_FLAGS="" @@ -135,7 +135,7 @@ RENAME_WHEEL=true case $desired_python in 3.13t) echo "Using 3.13 deps" - SETUPTOOLS_PINNED_VERSION=">=70.1.0" + SETUPTOOLS_PINNED_VERSION=">=77.0.0" PYYAML_PINNED_VERSION=">=6.0.1" NUMPY_PINNED_VERSION="=2.1.0" CONDA_ENV_CREATE_FLAGS="python-freethreading" @@ -145,31 +145,31 @@ case $desired_python in ;; 3.13) echo "Using 3.13 deps" - SETUPTOOLS_PINNED_VERSION=">=70.1.0" + SETUPTOOLS_PINNED_VERSION=">=77.0.0" PYYAML_PINNED_VERSION=">=6.0.1" NUMPY_PINNED_VERSION="=2.1.0" ;; 3.12) echo "Using 3.12 deps" - SETUPTOOLS_PINNED_VERSION=">=70.1.0" + SETUPTOOLS_PINNED_VERSION=">=77.0.0" PYYAML_PINNED_VERSION=">=6.0.1" NUMPY_PINNED_VERSION="=2.0.2" ;; 3.11) echo "Using 3.11 deps" - SETUPTOOLS_PINNED_VERSION=">=70.1.0" + SETUPTOOLS_PINNED_VERSION=">=77.0.0" PYYAML_PINNED_VERSION=">=5.3" NUMPY_PINNED_VERSION="=2.0.2" ;; 3.10) echo "Using 3.10 deps" - SETUPTOOLS_PINNED_VERSION=">=70.1.0" + SETUPTOOLS_PINNED_VERSION=">=77.0.0" PYYAML_PINNED_VERSION=">=5.3" NUMPY_PINNED_VERSION="=2.0.2" ;; 3.9) echo "Using 3.9 deps" - SETUPTOOLS_PINNED_VERSION=">=70.1.0" + SETUPTOOLS_PINNED_VERSION=">=77.0.0" PYYAML_PINNED_VERSION=">=5.3" NUMPY_PINNED_VERSION="=2.0.2" ;; diff --git a/.github/requirements/pip-requirements-macOS.txt b/.github/requirements/pip-requirements-macOS.txt index 224835188d87..dda7e37a7680 100644 --- a/.github/requirements/pip-requirements-macOS.txt +++ b/.github/requirements/pip-requirements-macOS.txt @@ -12,7 +12,7 @@ numba==0.59.0 numpy==1.26.4 opt-einsum>=3.3 optree==0.13.0 -packaging==23.1 +packaging==25.0 parameterized==0.8.1 pillow==10.3.0 protobuf==5.29.4 @@ -26,7 +26,7 @@ pytest-xdist==3.3.1 pytest==7.3.2 pyyaml==6.0.2 scipy==1.12.0 -setuptools==72.1.0 +setuptools==80.9.0 sympy==1.13.3 tlparse==0.3.30 tensorboard==2.13.0 diff --git a/pyproject.toml b/pyproject.toml index a911a2a723b1..f84a73d1c86a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,13 +2,13 @@ [build-system] requires = [ - # 70.1.0: min version for integrated bdist_wheel command from wheel package # 77.0.0: min version for SPDX expression support for project.license - "setuptools>=70.1.0,<80.0", + "setuptools>=77.0.0,<80.0", "cmake>=3.27", "ninja", "numpy", - "packaging", + # 24.2: min version required by setuptools for SPDX expression support + "packaging>=24.2", "pyyaml", "requests", "six", # dependency chain: NNPACK -> PeachPy -> six @@ -21,11 +21,7 @@ name = "torch" description = "Tensors and Dynamic neural networks in Python with strong GPU acceleration" readme = "README.md" requires-python = ">=3.9" -# TODO: change to `license = "BSD-3-Clause"` and enable PEP 639 after pinning setuptools>=77 -# FIXME: As of 2025.06.20, it is hard to ensure the minimum version of setuptools in our CI environment. -# TOML-table-based license deprecated in setuptools>=77, and the deprecation warning will be changed -# to an error on 2026.02.18. See also: https://github.com/pypa/setuptools/issues/4903 -license = { text = "BSD-3-Clause" } +license = "BSD-3-Clause" authors = [{ name = "PyTorch Team", email = "packages@pytorch.org" }] keywords = ["pytorch", "machine learning"] classifiers = [ diff --git a/requirements-build.txt b/requirements-build.txt index be19d987f73d..90b79e402404 100644 --- a/requirements-build.txt +++ b/requirements-build.txt @@ -1,9 +1,9 @@ -# Build System requirements -setuptools>=70.1.0,<80.0 # setuptools develop deprecated on 80.0 +# Build System requirements (see also: pyproject.toml) +setuptools>=77.0.0,<80.0 # setuptools develop deprecated on 80.0 cmake>=3.27 ninja numpy -packaging +packaging>=24.2 pyyaml requests six # dependency chain: NNPACK -> PeachPy -> six