From f300c7d644e7d082d885c254950c284fb4882ddc Mon Sep 17 00:00:00 2001 From: TOKUNAGA Hiroyuki <96674+tkng@users.noreply.github.com> Date: Tue, 25 Nov 2025 17:06:07 +0900 Subject: [PATCH] Avoid directly calling setup.py, migrate to pypa/build Direct invocations of setup.py have been deprecated by the Python packaging community and will be unsupported after 2025-Oct-31. This commit migrates the build process to use `python -m build`, which is the new recommended approach. Changes: - Add `build` package to workflow requirements - Replace `build_sdist.sh` script with `python -m build --sdist` - Update README installation instructions to use `python -m build` References: - https://blog.ganssle.io/articles/2021/10/setup-py-deprecated.html - https://setuptools.pypa.io/en/latest/deprecated/commands.html --- .github/workflows/requirements/base.in | 1 + .github/workflows/requirements/base.txt | 5 +++++ .github/workflows/requirements/cibuildwheel.txt | 16 ++++++++++------ .github/workflows/wheel.yml | 3 +-- python/README.md | 9 +++++---- python/build_sdist.sh | 11 ----------- 6 files changed, 22 insertions(+), 23 deletions(-) delete mode 100755 python/build_sdist.sh diff --git a/.github/workflows/requirements/base.in b/.github/workflows/requirements/base.in index d32433c8..79f9d025 100644 --- a/.github/workflows/requirements/base.in +++ b/.github/workflows/requirements/base.in @@ -3,3 +3,4 @@ setuptools wheel twine pytest +build \ No newline at end of file diff --git a/.github/workflows/requirements/base.txt b/.github/workflows/requirements/base.txt index ac85026a..96aa7abd 100644 --- a/.github/workflows/requirements/base.txt +++ b/.github/workflows/requirements/base.txt @@ -8,6 +8,10 @@ backports-tarfile==1.2.0 \ --hash=sha256:77e284d754527b01fb1e6fa8a1afe577858ebe4e9dad8919e34c862cb399bc34 \ --hash=sha256:d75e02c268746e1b8144c278978b6e98e85de6ad16f8e4b0844a154557eca991 # via jaraco-context +build==1.3.0 \ + --hash=sha256:698edd0ea270bde950f53aed21f3a0135672206f3911e0176261a31e0e07b397 \ + --hash=sha256:7145f0b5061ba90a1500d60bd1b13ca0a8a4cebdd0cc16ed8adf1c0e739f43b4 + # via -r base.in certifi==2024.7.4 \ --hash=sha256:5a1e7645bc0ec61a09e26c36f6106dd4cf40c6db3a1fb6352b0244e7fb057c7b \ --hash=sha256:c198e21b1289c2ab85ee4e67bb4b4ef3ead0892059901a8d5b622f24a1101e90 @@ -284,6 +288,7 @@ packaging==24.1 \ --hash=sha256:026ed72c8ed3fcce5bf8950572258698927fd1dbda10a5e981cdf0ac37f4f002 \ --hash=sha256:5b8f2217dbdbd2f7f384c41c628544e6d52f2d0f53c6d0c3ea61aa5d1d7ff124 # via + # build # pytest # twine pluggy==1.5.0 \ diff --git a/.github/workflows/requirements/cibuildwheel.txt b/.github/workflows/requirements/cibuildwheel.txt index 2c35d01f..6103474b 100644 --- a/.github/workflows/requirements/cibuildwheel.txt +++ b/.github/workflows/requirements/cibuildwheel.txt @@ -2,7 +2,7 @@ # This file is autogenerated by pip-compile with Python 3.11 # by the following command: # -# pip-compile --allow-unsafe --generate-hashes .github/workflows/requirements/cibuildwheel.in +# pip-compile --allow-unsafe --generate-hashes cibuildwheel.in # bashlex==0.18 \ --hash=sha256:5bb03a01c6d5676338c36fd1028009c8ad07e7d61d8a1ce3f513b7fff52796ee \ @@ -12,10 +12,12 @@ bracex==2.4 \ --hash=sha256:a27eaf1df42cf561fed58b7a8f3fdf129d1ea16a81e1fadd1d17989bc6384beb \ --hash=sha256:efdc71eff95eaff5e0f8cfebe7d01adf2c8637c8c92edaf63ef348c241a82418 # via cibuildwheel -build==1.2.2.post1 \ - --hash=sha256:1d61c0887fa860c01971625baae8bdd338e517b836a2f70dd1f7aa3a6b2fc5b5 \ - --hash=sha256:b36993e92ca9375a219c99e606a122ff365a760a2d4bba0caa09bd5278b608b7 - # via cibuildwheel +build==1.3.0 \ + --hash=sha256:698edd0ea270bde950f53aed21f3a0135672206f3911e0176261a31e0e07b397 \ + --hash=sha256:7145f0b5061ba90a1500d60bd1b13ca0a8a4cebdd0cc16ed8adf1c0e739f43b4 + # via + # -c base.txt + # cibuildwheel certifi==2024.7.4 \ --hash=sha256:5a1e7645bc0ec61a09e26c36f6106dd4cf40c6db3a1fb6352b0244e7fb057c7b \ --hash=sha256:c198e21b1289c2ab85ee4e67bb4b4ef3ead0892059901a8d5b622f24a1101e90 @@ -57,7 +59,9 @@ pyelftools==0.32 \ pyproject-hooks==1.2.0 \ --hash=sha256:1e859bd5c40fae9448642dd871adf459e5e2084186e8d2c2a79a824c970da1f8 \ --hash=sha256:9e5c6bfa8dcc30091c74b0cf803c81fdd29d94f01992a7707bc97babb1141913 - # via build + # via + # -c base.txt + # build wheel==0.45.1 \ --hash=sha256:661e1abd9198507b1409a20c02106d9670b2576e916d58f520316666abca6729 \ --hash=sha256:708e7481cc80179af0e556bbf0cc00b8444c7321e2700b8d8580231d13017248 diff --git a/.github/workflows/wheel.yml b/.github/workflows/wheel.yml index 185c8476..3b5fef47 100644 --- a/.github/workflows/wheel.yml +++ b/.github/workflows/wheel.yml @@ -82,8 +82,7 @@ jobs: - name: Build sdist archive working-directory: python run: | - python -m pip install setuptools - sh build_sdist.sh + python -m build --sdist - name: Fetch sdist archive uses: tj-actions/glob@2deae40528141fc53131606d56b4e4ce2a486b29 # v22.0.2 diff --git a/python/README.md b/python/README.md index 5b35ba24..c24bbe74 100644 --- a/python/README.md +++ b/python/README.md @@ -27,14 +27,15 @@ To build and install the Python wrapper from source, try the following commands % cmake .. -DSPM_ENABLE_SHARED=OFF -DCMAKE_INSTALL_PREFIX=./root -DSPM_DISABLE_EMBEDDED_DATA=ON % make install % cd ../python -% python setup.py bdist_wheel +% pip install build +% python -m build --wheel % pip install dist/sentencepiece*.whl ``` If you don’t have write permission to the global site-packages directory or don’t want to install into it, please try: ``` -% python setup.py install --user +% pip install --user dist/sentencepiece*.whl ``` For Windows users who want to build from source, you can build and install the Python wrapper using Visual Studio. First, you need to install the `pwsh.exe` (Powershell 7). Use `winget install --id Microsoft.Powershell --source winget` to install directly. Then open the `Developer PowerShell for VS 2022`, and execute the following commands. @@ -47,8 +48,8 @@ cd build cmake .. -DSPM_ENABLE_SHARED=OFF -DCMAKE_INSTALL_PREFIX=".\root" -DSPM_DISABLE_EMBEDDED_DATA=ON cmake --build . --config Release --target install cd ../python -pip install wheel -python setup.py bdist_wheel +pip install build +python -m build --wheel Get-ChildItem .\dist\sentencepiece*.whl | ForEach-Object { pip install $_.FullName } ``` diff --git a/python/build_sdist.sh b/python/build_sdist.sh deleted file mode 100755 index 92da94b5..00000000 --- a/python/build_sdist.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/sh - -mkdir -p sentencepiece - -for i in CMakeLists.txt LICENSE README.md VERSION.txt cmake config.h.in sentencepiece.pc.in src third_party -do - echo "copying ../${i} sentencepiece/${i}" - cp -f -R "../${i}" sentencepiece -done - -python3 setup.py sdist