diff --git a/.github/workflows/python.yml b/.github/workflows/python.yml index 95fea93e5..b0679360a 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,66 +30,25 @@ 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 + run: python -m build --wheel - 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..6fbc98995 100644 --- a/payjoin-ffi/python/README.md +++ b/payjoin-ffi/python/README.md @@ -23,11 +23,10 @@ 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 +python -m build --wheel # Force reinstall payjoin pip install ./dist/payjoin-.whl --force-reinstall @@ -46,10 +45,9 @@ 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 +python -m build --wheel ``` diff --git a/payjoin-ffi/python/pyproject.toml b/payjoin-ffi/python/pyproject.toml index 2012f16d6..897ce722b 100644 --- a/payjoin-ffi/python/pyproject.toml +++ b/payjoin-ffi/python/pyproject.toml @@ -1,7 +1,21 @@ [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 = [ "." -] \ No newline at end of file +] 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 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!"