Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support free-threaded Python #165

Merged
merged 14 commits into from
Nov 26, 2024
53 changes: 41 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,19 @@ jobs:

test:
needs: [resolve]
name: test rust-${{ matrix.rust-version }} on ${{ matrix.runs-on }}
name: test rust-${{ matrix.rust-version }} on ${{ matrix.runs-on }}, Python ${{ matrix.python-version }}
strategy:
fail-fast: false
matrix:
rust-version: [stable]
runs-on: [ubuntu, macos]
python-version: ["3.13"]
include:
- rust-version: ${{ needs.resolve.outputs.MSRV }}
runs-on: ubuntu
- rust-version: stable
runs-on: ubuntu
python-version: "3.13t"
- rust-version: nightly
runs-on: ubuntu

Expand All @@ -49,9 +53,9 @@ jobs:
- uses: actions/checkout@v4

- name: set up python
uses: actions/setup-python@v5
uses: quansight-labs/setup-python@v5
with:
python-version: "3.13"
python-version: ${{ matrix.python-version }}

- uses: dtolnay/rust-toolchain@master
with:
Expand All @@ -78,27 +82,32 @@ jobs:
token: ${{ secrets.CODECOV_TOKEN }}

test-python:
name: test jiter-python
name: test jiter-python ${{ matrix.python-version }}

runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
python-version: ["3.13", "3.13t"]

env:
RUNS_ON: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: set up python
uses: actions/setup-python@v5
uses: quansight-labs/setup-python@v5
with:
python-version: "3.13"
python-version: ${{ matrix.python-version }}

- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
- uses: taiki-e/install-action@cargo-llvm-cov

- name: Install python dependencies
run: make python-install
run: pip install -r crates/jiter-python/tests/requirements.txt

- name: Build jiter-python
run: |
Expand Down Expand Up @@ -339,7 +348,7 @@ jobs:
fail-fast: false
matrix:
os: [linux, windows, macos]
interpreter: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13"]
interpreter: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "3.13t"]
include:
# standard runners with override for macos arm
- os: linux
Expand All @@ -360,8 +369,9 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: set up python
uses: actions/setup-python@v5
- id: setup-python
name: set up python
uses: quansight-labs/setup-python@v5
with:
python-version: ${{ matrix.interpreter }}
allow-prereleases: true
Expand All @@ -374,14 +384,33 @@ jobs:

- run: rustc --version --verbose

# linux: builds are done inside manylinux docker images, need to help maturin-action
# find the right path
#
# TODO, would be nice to remove, see
# https://github.com/PyO3/maturin-action/issues/300
- if: ${{ matrix.os == 'linux' }}
id: resolve-interpreter
name: resolve interpreter
run: |
echo python-path=/opt/python/$(python -c "print({
'3.8': 'cp38-cp38',
'3.9': 'cp39-cp39',
'3.10': 'cp310-cp310',
'3.11': 'cp311-cp311',
'3.12': 'cp312-cp312',
'3.13': 'cp313-cp313',
'3.13t': 'cp313-cp313t',
}['${{ matrix.interpreter }}'])")/bin/python >> $GITHUB_OUTPUT

- name: build initial wheel
uses: PyO3/maturin-action@v1
with:
manylinux: auto
args: >
--release
--out pgo-wheel
--interpreter ${{ matrix.interpreter }}
--interpreter ${{ matrix.os == 'linux' && steps.resolve-interpreter.outputs.python-path || steps.setup-python.outputs.python-path }}
rust-toolchain: stable
working-directory: crates/jiter-python
env:
Expand Down Expand Up @@ -412,7 +441,7 @@ jobs:
args: >
--release
--out dist
--interpreter ${{ matrix.interpreter }}
--interpreter ${{ matrix.os == 'linux' && steps.resolve-interpreter.outputs.python-path || steps.setup-python.outputs.python-path }}
rust-toolchain: stable
working-directory: crates/jiter-python
env:
Expand Down
3 changes: 3 additions & 0 deletions crates/jiter-python/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,6 @@ dynamic = ["version"]
module-name = "jiter"
bindings = "pyo3"
features = ["pyo3/extension-module", "pyo3/generate-import-lib"]

[tool.ruff.format]
quote-style = 'single'
10 changes: 5 additions & 5 deletions crates/jiter-python/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub fn get_jiter_version() -> &'static str {
})
}

#[pyo3::pymodule]
#[pyo3::pymodule(gil_used = false)]
#[pyo3(name = "jiter")]
mod jiter_python {
use pyo3::prelude::*;
Expand Down Expand Up @@ -58,13 +58,13 @@ mod jiter_python {
}

#[pyfunction]
pub fn cache_clear(py: Python<'_>) {
jiter::cache_clear(py);
pub fn cache_clear() {
jiter::cache_clear();
}

#[pyfunction]
pub fn cache_usage(py: Python<'_>) -> usize {
jiter::cache_usage(py)
pub fn cache_usage() -> usize {
jiter::cache_usage()
}

#[pymodule_init]
Expand Down
Loading
Loading