Skip to content

Commit 140451e

Browse files
authored
Merge pull request #858 from tnull/2026-03-switch-to-uv-python-build
Switch to `uv` python build system
2 parents 3aef2b3 + 0a7ae2b commit 140451e

File tree

7 files changed

+81
-27
lines changed

7 files changed

+81
-27
lines changed

.github/workflows/python.yml

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,15 @@ jobs:
1717
- name: Checkout repository
1818
uses: actions/checkout@v4
1919

20-
- name: Setup Python
21-
uses: actions/setup-python@v4
22-
with:
23-
python-version: '3.10'
20+
- name: Install uv
21+
uses: astral-sh/setup-uv@v7
2422

2523
- name: Generate Python bindings
2624
run: ./scripts/uniffi_bindgen_generate_python.sh
2725

2826
- name: Start bitcoind and electrs
2927
run: docker compose up -d
3028

31-
- name: Install testing prerequisites
32-
run: |
33-
pip3 install requests
34-
3529
- name: Run Python unit tests
3630
env:
3731
BITCOIN_CLI_BIN: "docker exec ldk-node-bitcoin-1 bitcoin-cli"
@@ -40,4 +34,4 @@ jobs:
4034
ESPLORA_ENDPOINT: "http://127.0.0.1:3002"
4135
run: |
4236
cd $LDK_NODE_PYTHON_DIR
43-
python3 -m unittest discover -s src/ldk_node
37+
uv run --group dev python -m unittest discover -s src/ldk_node

bindings/python/hatch_build.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from hatchling.builders.hooks.plugin.interface import BuildHookInterface
2+
3+
4+
class CustomBuildHook(BuildHookInterface):
5+
def initialize(self, version, build_data):
6+
build_data["pure_python"] = False
7+
build_data["infer_tag"] = True

bindings/python/pyproject.toml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1+
[build-system]
2+
requires = ["hatchling"]
3+
build-backend = "hatchling.build"
4+
15
[project]
26
name = "ldk_node"
37
version = "0.7.0"
48
authors = [
59
{ name="Elias Rohrer", email="dev@tnull.de" },
610
]
711
description = "A ready-to-go Lightning node library built using LDK and BDK."
8-
readme = "README.md"
9-
requires-python = ">=3.6"
12+
readme = "../../README.md"
13+
requires-python = ">=3.8"
1014
classifiers = [
1115
"Topic :: Software Development :: Libraries",
1216
"Topic :: Security :: Cryptography",
@@ -19,3 +23,11 @@ classifiers = [
1923
"Homepage" = "https://lightningdevkit.org/"
2024
"Github" = "https://github.com/lightningdevkit/ldk-node"
2125
"Bug Tracker" = "https://github.com/lightningdevkit/ldk-node/issues"
26+
27+
[dependency-groups]
28+
dev = ["requests"]
29+
30+
[tool.hatch.build.targets.wheel]
31+
packages = ["src/ldk_node"]
32+
33+
[tool.hatch.build.hooks.custom]

bindings/python/setup.cfg

Lines changed: 0 additions & 13 deletions
This file was deleted.

scripts/python_build_wheel.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash
2+
# Build a Python wheel for the current platform.
3+
#
4+
# This script compiles the Rust library, generates Python bindings via UniFFI,
5+
# and builds a platform-specific wheel using uv + hatchling.
6+
#
7+
# Run this on each target platform (Linux, macOS) to collect wheels, then use
8+
# scripts/python_publish_package.sh to publish them.
9+
10+
set -e
11+
12+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
13+
REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
14+
15+
cd "$REPO_ROOT"
16+
17+
# Generate bindings and compile the native library
18+
echo "Generating Python bindings..."
19+
./scripts/uniffi_bindgen_generate_python.sh
20+
21+
# Build the wheel
22+
echo "Building wheel..."
23+
cd bindings/python
24+
uv build --wheel
25+
26+
echo ""
27+
echo "Wheel built successfully:"
28+
ls -1 dist/*.whl
29+
echo ""
30+
echo "Collect wheels from all target platforms into dist/, then run:"
31+
echo " ./scripts/python_publish_package.sh"

scripts/python_create_package.sh

Lines changed: 0 additions & 3 deletions
This file was deleted.

scripts/python_publish_package.sh

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/bash
2+
# Publish Python wheels to PyPI (or TestPyPI).
3+
#
4+
# Usage:
5+
# ./scripts/python_publish_package.sh # publish to PyPI
6+
# ./scripts/python_publish_package.sh --index testpypi # publish to TestPyPI
7+
#
8+
# Before running, collect wheels from all target platforms into bindings/python/dist/.
9+
10+
set -e
11+
12+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
13+
REPO_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
14+
DIST_DIR="$REPO_ROOT/bindings/python/dist"
15+
16+
if [ ! -d "$DIST_DIR" ] || [ -z "$(ls -A "$DIST_DIR"/*.whl 2>/dev/null)" ]; then
17+
echo "Error: No wheels found in $DIST_DIR"
18+
echo "Run ./scripts/python_build_wheel.sh on each target platform first."
19+
exit 1
20+
fi
21+
22+
echo "Wheels to publish:"
23+
ls -1 "$DIST_DIR"/*.whl
24+
echo ""
25+
26+
uv publish "$@" "$DIST_DIR"/*.whl

0 commit comments

Comments
 (0)