From 2b003639fb03360f6cf469857d9cd022ed33e155 Mon Sep 17 00:00:00 2001 From: Remco de Boer <29308176+redeboer@users.noreply.github.com> Date: Wed, 21 Aug 2024 08:10:05 +0200 Subject: [PATCH] Build wheels for Python package (#549) Co-authored-by: Jakub Panek --- .github/workflows/releases.yaml | 76 +++++++++++++++++++++++++++++++++ .gitignore | 6 +++ Cargo.lock | 8 ++-- crates/taplo-cli/Cargo.toml | 4 +- pyproject.toml | 29 +++++++++++++ 5 files changed, 117 insertions(+), 6 deletions(-) create mode 100644 pyproject.toml diff --git a/.github/workflows/releases.yaml b/.github/workflows/releases.yaml index 833d746ab..89be9f930 100644 --- a/.github/workflows/releases.yaml +++ b/.github/workflows/releases.yaml @@ -436,3 +436,79 @@ jobs: working-directory: editors/vscode env: OPEN_VSX_TOKEN: ${{ secrets.OPEN_VSX_TOKEN }} + + pypi_build_taplo_cli: + name: Build python wheels + needs: ["wait_for_ci"] + runs-on: ${{ matrix.os }}-latest + strategy: + fail-fast: false + matrix: + os: [ubuntu, windows, macos] + arch: [x86, x64, aarch64] + exclude: + - os: windows + arch: aarch64 + - os: ubuntu + arch: aarch64 + - os: macos + arch: x86 + steps: + - uses: actions/checkout@v4 + - name: Build sdist + if: matrix.os == 'ubuntu' && matrix.arch == 'x64' + uses: PyO3/maturin-action@v1 + with: + command: sdist + args: --out dist + - name: Build wheels + uses: PyO3/maturin-action@v1 + with: + target: ${{ matrix.arch }} + args: --release --out dist + sccache: "true" + manylinux: auto + - name: Upload wheels + uses: actions/upload-artifact@v4 + with: + name: wheels-${{ matrix.os }}-${{ matrix.arch }} + path: dist + + pypi_test_taplo_cli: + name: Test python wheels + needs: ["pypi_build_taplo_cli"] + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: + - windows-latest + - ubuntu-latest + - macos-latest + steps: + - uses: actions/download-artifact@v4 + with: + pattern: wheels-* + path: wheels + merge-multiple: true + - uses: actions/setup-python@v5 + with: + python-version: "3" + - run: pip install taplo --no-index --find-links wheels/ + - run: taplo help + + pypi_publish_taplo_cli: + name: PyPI publish taplo + runs-on: ubuntu-latest + if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/release-taplo-cli-0') + needs: ["pypi_test_taplo_cli"] + permissions: + id-token: write + steps: + - uses: actions/download-artifact@v4 + with: + pattern: wheels-* + path: dist + merge-multiple: true + - name: Publish to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 diff --git a/.gitignore b/.gitignore index 0f3c0a93e..cc7dff417 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,9 @@ target .vscode/settings.json .cargo/config.toml yarn-error.log + +# Python +__pycache__/ +*venv/ +dist/ +wheels/ diff --git a/Cargo.lock b/Cargo.lock index 863fc8d35..6b98dc3c5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1451,9 +1451,9 @@ checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575" [[package]] name = "openssl" -version = "0.10.63" +version = "0.10.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15c9d69dd87a29568d4d017cfe8ec518706046a05184e5aea92d0af890b803c8" +checksum = "9529f4786b70a3e8c61e11179af17ab6188ad8d0ded78c5529441ed39d4bd9c1" dependencies = [ "bitflags 2.4.2", "cfg-if", @@ -1483,9 +1483,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "openssl-sys" -version = "0.9.99" +version = "0.9.103" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22e1bf214306098e4832460f797824c05d25aacdf896f64a985fb0fd992454ae" +checksum = "7f9e8deee91df40a943c71b917e5874b951d32a802526c85721ce3b776c929d6" dependencies = [ "cc", "libc", diff --git a/crates/taplo-cli/Cargo.toml b/crates/taplo-cli/Cargo.toml index 282d6d3af..19d84810f 100644 --- a/crates/taplo-cli/Cargo.toml +++ b/crates/taplo-cli/Cargo.toml @@ -12,8 +12,8 @@ license = { workspace = true } repository = { workspace = true } [features] -default = ["rustls-tls", "lsp", "toml-test"] -lsp = ["taplo-lsp", "async-ctrlc"] +default = ["lsp", "rustls-tls", "toml-test"] +lsp = ["async-ctrlc", "taplo-lsp"] native-tls = ["taplo-common/native-tls", "taplo-lsp?/native-tls"] rustls-tls = ["taplo-common/rustls-tls", "taplo-lsp?/rustls-tls"] toml-test = [] diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 000000000..7619914fe --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,29 @@ +[build-system] +requires = ["maturin>=1.4"] +build-backend = "maturin" + +[project] +name = "taplo" +requires-python = ">=3.8" +classifiers = [ + "Development Status :: 4 - Beta", + "Intended Audience :: Developers", + "License :: OSI Approved :: MIT License", + "Operating System :: OS Independent", + "Programming Language :: Python :: 3 :: Only", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: Implementation :: CPython", + "Programming Language :: Python :: Implementation :: PyPy", + "Programming Language :: Python", + "Programming Language :: Rust", + "Topic :: Software Development :: Quality Assurance", +] +dynamic = ["version"] + +[tool.maturin] +bindings = "bin" +manifest-path = "crates/taplo-cli/Cargo.toml"