Skip to content

Commit 27b3a09

Browse files
committed
feat: configure PyO3 test environment in CI workflows
1 parent 83d88b3 commit 27b3a09

6 files changed

Lines changed: 102 additions & 9 deletions

File tree

.github/workflows/ci.yml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,28 @@ jobs:
3232
- name: Sync development dependencies
3333
run: uv sync --group dev
3434

35+
- name: Configure PyO3 test environment
36+
shell: bash
37+
run: |
38+
PYTHON_BIN="$(uv run --group dev python - <<'PY'
39+
import sys
40+
print(sys.executable)
41+
PY
42+
)"
43+
PYTHON_LIBDIR="$(uv run --group dev python - <<'PY'
44+
import sysconfig
45+
print(sysconfig.get_config_var("LIBDIR") or "")
46+
PY
47+
)"
48+
49+
echo "PYO3_PYTHON=$PYTHON_BIN" >> "$GITHUB_ENV"
50+
if [ -n "$PYTHON_LIBDIR" ]; then
51+
echo "LD_LIBRARY_PATH=$PYTHON_LIBDIR${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" >> "$GITHUB_ENV"
52+
echo "LIBRARY_PATH=$PYTHON_LIBDIR${LIBRARY_PATH:+:$LIBRARY_PATH}" >> "$GITHUB_ENV"
53+
fi
54+
3555
- name: Run Rust tests
36-
run: PYO3_PYTHON="$GITHUB_WORKSPACE/.venv/bin/python3" cargo test --manifest-path rust/Cargo.toml --workspace --tests
56+
run: cargo test --manifest-path rust/Cargo.toml --workspace --tests
3757

3858
- name: Run Python tests
3959
run: uv run --group dev pytest json-tstring/tests toml-tstring/tests yaml-tstring/tests -q

.github/workflows/json-tstring-ci.yml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,26 @@ jobs:
4040
- name: Sync development dependencies
4141
run: uv sync --group dev
4242

43+
- name: Configure PyO3 test environment
44+
shell: bash
45+
run: |
46+
PYTHON_BIN="$(uv run --group dev python - <<'PY'
47+
import sys
48+
print(sys.executable)
49+
PY
50+
)"
51+
PYTHON_LIBDIR="$(uv run --group dev python - <<'PY'
52+
import sysconfig
53+
print(sysconfig.get_config_var("LIBDIR") or "")
54+
PY
55+
)"
56+
57+
echo "PYO3_PYTHON=$PYTHON_BIN" >> "$GITHUB_ENV"
58+
if [ -n "$PYTHON_LIBDIR" ]; then
59+
echo "LD_LIBRARY_PATH=$PYTHON_LIBDIR${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" >> "$GITHUB_ENV"
60+
echo "LIBRARY_PATH=$PYTHON_LIBDIR${LIBRARY_PATH:+:$LIBRARY_PATH}" >> "$GITHUB_ENV"
61+
fi
62+
4363
- name: Check formatting
4464
run: uv run --group dev ruff format --check . ../tstring-core
4565

@@ -53,4 +73,4 @@ jobs:
5373
run: uv run --group dev pytest
5474

5575
- name: Run Rust parser tests
56-
run: PYO3_PYTHON="$GITHUB_WORKSPACE/.venv/bin/python3" cargo test --manifest-path ../rust/Cargo.toml -p tstring-json --tests
76+
run: cargo test --manifest-path ../rust/Cargo.toml -p tstring-json --tests

.github/workflows/publish-python.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,15 @@ jobs:
6565
- os: linux
6666
runner: ubuntu-latest
6767
target: x86_64-unknown-linux-gnu
68+
maturin_args: --release --manifest-path rust/python-bindings/Cargo.toml --out dist --compatibility pypi -i python3.14
6869
- os: macos
6970
runner: macos-14
7071
target: aarch64-apple-darwin
72+
maturin_args: --release --manifest-path rust/python-bindings/Cargo.toml --out dist --compatibility pypi
7173
- os: windows
7274
runner: windows-latest
7375
target: x86_64-pc-windows-msvc
76+
maturin_args: --release --manifest-path rust/python-bindings/Cargo.toml --out dist --compatibility pypi
7477
runs-on: ${{ matrix.runner }}
7578
permissions:
7679
contents: read
@@ -93,7 +96,7 @@ jobs:
9396
uses: PyO3/maturin-action@v1
9497
with:
9598
target: ${{ matrix.target }}
96-
args: --release --manifest-path rust/python-bindings/Cargo.toml --out dist
99+
args: ${{ matrix.maturin_args }}
97100
manylinux: "2_28"
98101
sccache: "true"
99102

.github/workflows/release-check.yml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,15 @@ jobs:
4949
- os: linux
5050
runner: ubuntu-latest
5151
target: x86_64-unknown-linux-gnu
52+
maturin_args: --release --manifest-path rust/python-bindings/Cargo.toml --out dist --compatibility pypi -i python3.14
5253
- os: macos
5354
runner: macos-14
5455
target: aarch64-apple-darwin
56+
maturin_args: --release --manifest-path rust/python-bindings/Cargo.toml --out dist --compatibility pypi
5557
- os: windows
5658
runner: windows-latest
5759
target: x86_64-pc-windows-msvc
60+
maturin_args: --release --manifest-path rust/python-bindings/Cargo.toml --out dist --compatibility pypi
5861
runs-on: ${{ matrix.runner }}
5962
permissions:
6063
contents: read
@@ -84,7 +87,7 @@ jobs:
8487
uses: PyO3/maturin-action@v1
8588
with:
8689
target: ${{ matrix.target }}
87-
args: --release --manifest-path rust/python-bindings/Cargo.toml --out dist
90+
args: ${{ matrix.maturin_args }}
8891
manylinux: "2_28"
8992
sccache: "true"
9093

@@ -95,8 +98,15 @@ jobs:
9598
- name: Smoke test installed wheels
9699
shell: bash
97100
run: |
98-
python -m pip install --upgrade pip
99-
python - <<'PY'
101+
uv venv --python 3.14 .smoke-venv
102+
if [ -x .smoke-venv/bin/python ]; then
103+
PYTHON_BIN=.smoke-venv/bin/python
104+
else
105+
PYTHON_BIN=.smoke-venv/Scripts/python.exe
106+
fi
107+
108+
"$PYTHON_BIN" -m pip install --upgrade pip
109+
"$PYTHON_BIN" - <<'PY'
100110
from pathlib import Path
101111
import subprocess
102112
import sys
@@ -110,4 +120,4 @@ jobs:
110120
check=True,
111121
)
112122
PY
113-
python -c "import json_tstring, toml_tstring, yaml_tstring, tstring_bindings, tstring_core"
123+
"$PYTHON_BIN" -c "import json_tstring, toml_tstring, yaml_tstring, tstring_bindings, tstring_core"

.github/workflows/toml-tstring-ci.yml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,26 @@ jobs:
4040
- name: Sync development dependencies
4141
run: uv sync --group dev
4242

43+
- name: Configure PyO3 test environment
44+
shell: bash
45+
run: |
46+
PYTHON_BIN="$(uv run --group dev python - <<'PY'
47+
import sys
48+
print(sys.executable)
49+
PY
50+
)"
51+
PYTHON_LIBDIR="$(uv run --group dev python - <<'PY'
52+
import sysconfig
53+
print(sysconfig.get_config_var("LIBDIR") or "")
54+
PY
55+
)"
56+
57+
echo "PYO3_PYTHON=$PYTHON_BIN" >> "$GITHUB_ENV"
58+
if [ -n "$PYTHON_LIBDIR" ]; then
59+
echo "LD_LIBRARY_PATH=$PYTHON_LIBDIR${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" >> "$GITHUB_ENV"
60+
echo "LIBRARY_PATH=$PYTHON_LIBDIR${LIBRARY_PATH:+:$LIBRARY_PATH}" >> "$GITHUB_ENV"
61+
fi
62+
4363
- name: Check formatting
4464
run: uv run --group dev ruff format --check . ../tstring-core
4565

@@ -53,4 +73,4 @@ jobs:
5373
run: uv run --group dev pytest
5474

5575
- name: Run Rust parser tests
56-
run: PYO3_PYTHON="$GITHUB_WORKSPACE/.venv/bin/python3" cargo test --manifest-path ../rust/Cargo.toml -p tstring-toml --tests
76+
run: cargo test --manifest-path ../rust/Cargo.toml -p tstring-toml --tests

.github/workflows/yaml-tstring-ci.yml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,26 @@ jobs:
4040
- name: Sync development dependencies
4141
run: uv sync --group dev
4242

43+
- name: Configure PyO3 test environment
44+
shell: bash
45+
run: |
46+
PYTHON_BIN="$(uv run --group dev python - <<'PY'
47+
import sys
48+
print(sys.executable)
49+
PY
50+
)"
51+
PYTHON_LIBDIR="$(uv run --group dev python - <<'PY'
52+
import sysconfig
53+
print(sysconfig.get_config_var("LIBDIR") or "")
54+
PY
55+
)"
56+
57+
echo "PYO3_PYTHON=$PYTHON_BIN" >> "$GITHUB_ENV"
58+
if [ -n "$PYTHON_LIBDIR" ]; then
59+
echo "LD_LIBRARY_PATH=$PYTHON_LIBDIR${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}" >> "$GITHUB_ENV"
60+
echo "LIBRARY_PATH=$PYTHON_LIBDIR${LIBRARY_PATH:+:$LIBRARY_PATH}" >> "$GITHUB_ENV"
61+
fi
62+
4363
- name: Check formatting
4464
run: uv run --group dev ruff format --check . ../tstring-core
4565

@@ -53,4 +73,4 @@ jobs:
5373
run: uv run --group dev pytest
5474

5575
- name: Run Rust parser tests
56-
run: PYO3_PYTHON="$GITHUB_WORKSPACE/.venv/bin/python3" cargo test --manifest-path ../rust/Cargo.toml -p tstring-yaml -p tstring-yaml-pyo3-tests --tests
76+
run: cargo test --manifest-path ../rust/Cargo.toml -p tstring-yaml -p tstring-yaml-pyo3-tests --tests

0 commit comments

Comments
 (0)