From 363d2b5446993782711bc1af8b4dc5126c8c1475 Mon Sep 17 00:00:00 2001 From: user Date: Thu, 21 Aug 2025 14:41:06 -0400 Subject: [PATCH 1/2] Optimize the workflow for python CI This is a simplification for the python build and test workflow for linux and macos. This also updates some of the setup.py to use the more up to date `python -m build` method --- .github/workflows/python.yml | 70 ++++--------------- payjoin-ffi/python/README.md | 6 +- payjoin-ffi/python/pyproject.toml | 2 +- .../python/scripts/bindgen_generate.sh | 10 --- .../python/scripts/generate_bindings.sh | 54 ++++++++++++++ payjoin-ffi/python/scripts/generate_linux.sh | 22 ------ payjoin-ffi/python/scripts/generate_macos.sh | 32 --------- 7 files changed, 69 insertions(+), 127 deletions(-) delete mode 100644 payjoin-ffi/python/scripts/bindgen_generate.sh create mode 100644 payjoin-ffi/python/scripts/generate_bindings.sh delete mode 100755 payjoin-ffi/python/scripts/generate_linux.sh delete mode 100644 payjoin-ffi/python/scripts/generate_macos.sh diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 95fea93e5..804e79f22 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -11,20 +11,15 @@ env: RUSTUP_TOOLCHAIN: 1.85 jobs: - build-wheels-and-test: - name: "Build and test Linux" - runs-on: ubuntu-latest + build-python-and-test: + name: "Build and test python" + runs-on: ${{ matrix.os }} defaults: run: working-directory: payjoin-ffi/python strategy: matrix: - include: - - python: "3.9" - - python: "3.10" - - python: "3.11" - - python: "3.12" - - python: "3.13" + os: [ubuntu-latest, macos-latest] steps: - name: "Checkout" uses: actions/checkout@v4 @@ -35,20 +30,13 @@ jobs: - name: "Install Python" uses: actions/setup-python@v4 with: - python-version: ${{ matrix.python }} - - - name: "Install build dependencies" - run: | - sudo apt update - sudo apt install -y build-essential python3-dev + python-version: 3.12 - name: "Use cache" uses: Swatinem/rust-cache@v2 - name: "Generate payjoin-ffi.py and binaries" - run: | - PYBIN=$(dirname $(which python)) - PYBIN="$PYBIN" bash ./scripts/generate_linux.sh + run: bash ./scripts/generate_bindings.sh - name: "Build wheel" run: python setup.py bdist_wheel --verbose @@ -56,45 +44,11 @@ jobs: - name: "Install wheel" run: pip install ./dist/*.whl - - name: "Run tests" - run: python -m unittest -v - - build-macos: - name: "Build and test macOS" - runs-on: macos-13 - defaults: - run: - working-directory: payjoin-ffi/python - strategy: - matrix: - python: - - "3.12" - steps: - - name: "Checkout" - uses: actions/checkout@v4 - with: - submodules: true - - - name: "Install Rust 1.85.0" - uses: dtolnay/rust-toolchain@1.85.0 - - - name: "Install Python" - uses: actions/setup-python@v4 - with: - python-version: ${{ matrix.python }} - - - name: "Use cache" - uses: Swatinem/rust-cache@v2 - - - name: "Generate payjoin-ffi.py and binaries" - run: bash ./scripts/generate_macos.sh - - - name: "Build wheel" - run: python3 setup.py bdist_wheel --verbose - - - name: "Install wheel" - run: pip3 install ./dist/*.whl - - name: "Run tests" # Skip integration test on macOS due to Docker issues - run: python3 -m unittest -v test/test_payjoin_unit_test.py + run: | + if [[ "${{ matrix.os }}" = "macos-latest" ]]; then + python -m unittest test/test_payjoin_unit_test.py -v + else + python -m unittest -v + fi diff --git a/payjoin-ffi/python/README.md b/payjoin-ffi/python/README.md index 600ccfcf5..8509f58ef 100644 --- a/payjoin-ffi/python/README.md +++ b/payjoin-ffi/python/README.md @@ -23,8 +23,7 @@ cd rust-payjoin/payjoin-ffi/python python -m venv venv source venv/bin/activate -# Generate the bindings (use the script appropriate for your platform) -PYBIN="./venv/bin/" bash ./scripts/generate_.sh +PYBIN="./venv/bin/" bash ./scripts/generate_bindings.sh # Build the wheel python setup.py bdist_wheel --verbose @@ -46,8 +45,7 @@ You can [filter which tests](https://docs.python.org/3/library/unittest.html#com python -m venv venv source venv/bin/activate -# Generate the bindings (use the script appropriate for your platform) -PYBIN="./venv/bin/" bash ./scripts/generate_.sh +PYBIN="./venv/bin/" bash ./scripts/generate_bindings.sh # Build the wheel python setup.py --verbose bdist_wheel diff --git a/payjoin-ffi/python/pyproject.toml b/payjoin-ffi/python/pyproject.toml index 2012f16d6..903f3acdc 100644 --- a/payjoin-ffi/python/pyproject.toml +++ b/payjoin-ffi/python/pyproject.toml @@ -4,4 +4,4 @@ requires = ["setuptools", "wheel", "setuptools-rust"] [tool.pytest.ini_options] pythonpath = [ "." -] \ No newline at end of file +] diff --git a/payjoin-ffi/python/scripts/bindgen_generate.sh b/payjoin-ffi/python/scripts/bindgen_generate.sh deleted file mode 100644 index e32043c5e..000000000 --- a/payjoin-ffi/python/scripts/bindgen_generate.sh +++ /dev/null @@ -1,10 +0,0 @@ - - -#!/bin/bash -chmod +x ./scripts/generate_linux.sh -chmod +x ./scripts/generate_macos.sh - - -# Run each script -scripts/generate_linux.sh -scripts/generate_macos.sh diff --git a/payjoin-ffi/python/scripts/generate_bindings.sh b/payjoin-ffi/python/scripts/generate_bindings.sh new file mode 100644 index 000000000..7d191d6ca --- /dev/null +++ b/payjoin-ffi/python/scripts/generate_bindings.sh @@ -0,0 +1,54 @@ +#!/usr/bin/env bash +set -euo pipefail + +OS=$(uname -s) + +echo "Running on $OS" + +# Install Rust targets if on macOS +if [[ "$OS" == "Darwin" ]]; then + LIBNAME=libpayjoin_ffi.dylib + python3 --version + pip install -r requirements.txt -r requirements-dev.txt +elif [[ "$OS" == "Linux" ]]; then + sudo apt update + sudo apt install -y build-essential python3-dev + LIBNAME=libpayjoin_ffi.so + PYBIN=$(dirname $(which python)) + PYBIN="$PYBIN" + ${PYBIN}/python --version + ${PYBIN}/pip install -r requirements.txt -r requirements-dev.txt +else + echo "Unsupported os: $OS" + exit 1 +fi + +cd ../ +# This is a test script the actual release should not include the test utils feature +cargo build --features _test-utils --profile release +cargo run --features _test-utils --profile release --bin uniffi-bindgen generate --library target/release/$LIBNAME --language python --out-dir python/src/payjoin/ + +if [[ "$OS" == "Darwin" ]]; then + echo "Generating native binaries..." + rustup target add aarch64-apple-darwin x86_64-apple-darwin + # This is a test script the actual release should not include the test utils feature + cargo build --profile release-smaller --target aarch64-apple-darwin --features _test-utils & + cargo build --profile release-smaller --target x86_64-apple-darwin --features _test-utils & + wait + + echo "Building macos fat library" + lipo -create -output python/src/payjoin/$LIBNAME \ + target/aarch64-apple-darwin/release-smaller/$LIBNAME \ + target/x86_64-apple-darwin/release-smaller/$LIBNAME + +else + echo "Generating native binaries..." + rustup target add x86_64-unknown-linux-gnu + # This is a test script the actual release should not include the test utils feature + cargo build --profile release-smaller --target x86_64-unknown-linux-gnu --features _test-utils + + echo "Copying payjoin_ffi binary" + cp target/x86_64-unknown-linux-gnu/release-smaller/$LIBNAME python/src/payjoin/$LIBNAME +fi + +echo "All done!" diff --git a/payjoin-ffi/python/scripts/generate_linux.sh b/payjoin-ffi/python/scripts/generate_linux.sh deleted file mode 100755 index ffda52558..000000000 --- a/payjoin-ffi/python/scripts/generate_linux.sh +++ /dev/null @@ -1,22 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail -${PYBIN}/python --version -${PYBIN}/pip install -r requirements.txt -r requirements-dev.txt -LIBNAME=libpayjoin_ffi.so -LINUX_TARGET=x86_64-unknown-linux-gnu - -echo "Generating payjoin_ffi.py..." -cd ../ -# This is a test script the actual release should not include the test utils feature -cargo build --profile release --features _test-utils -cargo run --profile release --features _test-utils --bin uniffi-bindgen generate --library target/release/$LIBNAME --language python --out-dir python/src/payjoin/ - -echo "Generating native binaries..." -rustup target add $LINUX_TARGET -# This is a test script the actual release should not include the test utils feature -cargo build --profile release-smaller --target $LINUX_TARGET --features _test-utils - -echo "Copying linux payjoin_ffi.so" -cp target/$LINUX_TARGET/release-smaller/$LIBNAME python/src/payjoin/$LIBNAME - -echo "All done!" diff --git a/payjoin-ffi/python/scripts/generate_macos.sh b/payjoin-ffi/python/scripts/generate_macos.sh deleted file mode 100644 index 4efb52d9e..000000000 --- a/payjoin-ffi/python/scripts/generate_macos.sh +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/env bash - -set -euo pipefail -python3 --version -pip install -r requirements.txt -r requirements-dev.txt -LIBNAME=libpayjoin_ffi.dylib - -echo "Generating payjoin_ffi.py..." -cd ../ -# This is a test script the actual release should not include the test utils feature -cargo build --features _test-utils --profile release -cargo run --features _test-utils --profile release --bin uniffi-bindgen generate --library target/release/$LIBNAME --language python --out-dir python/src/payjoin/ - -echo "Generating native binaries..." -rustup target add aarch64-apple-darwin x86_64-apple-darwin - -# This is a test script the actual release should not include the test utils feature -cargo build --profile release-smaller --target aarch64-apple-darwin --features _test-utils -echo "Done building aarch64-apple-darwin" - -# This is a test script the actual release should not include the test utils feature -cargo build --profile release-smaller --target x86_64-apple-darwin --features _test-utils -echo "Done building x86_64-apple-darwin" - -echo "Building macos fat library" - -lipo -create -output python/src/payjoin/$LIBNAME \ - target/aarch64-apple-darwin/release-smaller/$LIBNAME \ - target/x86_64-apple-darwin/release-smaller/$LIBNAME - - -echo "All done!" From cff82bbd2c6e561d722314062ad6871bcd9a6e39 Mon Sep 17 00:00:00 2001 From: user Date: Thu, 21 Aug 2025 15:47:54 -0400 Subject: [PATCH 2/2] Remove the direct use of setup.py setup.py is deprecated for use directly asa build tool --- .github/workflows/python.yml | 2 +- payjoin-ffi/python/README.md | 4 ++-- payjoin-ffi/python/pyproject.toml | 16 +++++++++++++++- payjoin-ffi/python/requirements.txt | 1 + 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 804e79f22..b0679360a 100644 --- a/.github/workflows/python.yml +++ b/.github/workflows/python.yml @@ -39,7 +39,7 @@ jobs: run: bash ./scripts/generate_bindings.sh - name: "Build wheel" - run: python setup.py bdist_wheel --verbose + run: python -m build --wheel - name: "Install wheel" run: pip install ./dist/*.whl diff --git a/payjoin-ffi/python/README.md b/payjoin-ffi/python/README.md index 8509f58ef..6fbc98995 100644 --- a/payjoin-ffi/python/README.md +++ b/payjoin-ffi/python/README.md @@ -26,7 +26,7 @@ source venv/bin/activate PYBIN="./venv/bin/" bash ./scripts/generate_bindings.sh # Build the wheel -python setup.py bdist_wheel --verbose +python -m build --wheel # Force reinstall payjoin pip install ./dist/payjoin-.whl --force-reinstall @@ -48,6 +48,6 @@ source venv/bin/activate PYBIN="./venv/bin/" bash ./scripts/generate_bindings.sh # Build the wheel -python setup.py --verbose bdist_wheel +python -m build --wheel ``` diff --git a/payjoin-ffi/python/pyproject.toml b/payjoin-ffi/python/pyproject.toml index 903f3acdc..897ce722b 100644 --- a/payjoin-ffi/python/pyproject.toml +++ b/payjoin-ffi/python/pyproject.toml @@ -1,5 +1,19 @@ [build-system] -requires = ["setuptools", "wheel", "setuptools-rust"] +requires = ["setuptools>=62", "wheel", "toml"] +build-backend = "setuptools.build_meta" + +[project] +name = "payjoin" +description = "The Python language bindings for the Payjoin Dev Kit" +readme = "README.md" +requires-python = ">=3.8" +license = "MIT" +dynamic = ["version"] + +[tool.setuptools] +packages = ["payjoin"] +package-dir = { "payjoin" = "src/payjoin" } +include-package-data = true [tool.pytest.ini_options] pythonpath = [ diff --git a/payjoin-ffi/python/requirements.txt b/payjoin-ffi/python/requirements.txt index 872c30539..268effb04 100644 --- a/payjoin-ffi/python/requirements.txt +++ b/payjoin-ffi/python/requirements.txt @@ -2,3 +2,4 @@ semantic-version==2.9.0 typing_extensions==4.0.1 setuptools==78.1.1 wheel==0.38.4 +build==1.3.0