Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions .github/actions/build-pgo-wheel/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,15 @@ runs:
env:
RUSTFLAGS: '-Cprofile-generate=${{ github.workspace }}/profdata'

- name: detect rust host
run: echo RUST_HOST=$(rustc -Vv | grep host | cut -d ' ' -f 2) >> "$GITHUB_ENV"
shell: bash

- name: generate pgo data
run: |
python -m pip install -U pip
python -m pip install -r tests/requirements.txt
python -m pip install jiter --no-index --no-deps --find-links pgo-wheel --force-reinstall
python bench.py jiter jiter-cache
RUST_HOST=$(rustc -Vv | grep host | cut -d ' ' -f 2)
export RUST_HOST=$(rustc --print host-tuple)
uv sync --group dev --no-install-package jiter
cd crates/jiter-python
uv pip install jiter --no-index --no-deps --find-links pgo-wheel --force-reinstall
uv run bench.py jiter jiter-cache
rustup run ${{ inputs.rust-toolchain }} bash -c 'echo LLVM_PROFDATA=$RUSTUP_HOME/toolchains/$RUSTUP_TOOLCHAIN/lib/rustlib/$RUST_HOST/bin/llvm-profdata >> "$GITHUB_ENV"'
shell: bash
working-directory: crates/jiter-python

- name: merge pgo data
run: ${{ env.LLVM_PROFDATA }} merge -o ${{ github.workspace }}/merged.profdata ${{ github.workspace }}/profdata
Expand Down
86 changes: 43 additions & 43 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.13", "3.13t", "graalpy-25.0"]
python-version: ["3.13", "3.13t", "graalpy3.12"]

env:
RUNS_ON: ubuntu-latest
Expand All @@ -103,28 +103,25 @@ jobs:
- uses: actions/checkout@v5

- name: set up python ${{ matrix.python-version }}
uses: actions/setup-python@v6
uses: astral-sh/setup-uv@v8.0.0
with:
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: pip install -r crates/jiter-python/tests/requirements.txt

- name: Build jiter-python
- name: Install dependencies
run: |
source <(cargo llvm-cov show-env --export-prefix)
cargo llvm-cov clean --workspace --profraw-only
pip install -e crates/jiter-python --config-settings=build-args='--profile dev'
uv sync --group dev --all-packages

- name: Run tests
run: |
source <(cargo llvm-cov show-env --export-prefix)
pytest crates/jiter-python/tests
python crates/jiter-python/bench.py jiter jiter-cache --fast
uv run pytest crates/jiter-python/tests
uv run crates/jiter-python/bench.py jiter jiter-cache --fast
env:
RUST_BACKTRACE: 1

Expand All @@ -143,7 +140,7 @@ jobs:
steps:
- uses: actions/checkout@v5

- uses: actions/setup-python@v6
- uses: astral-sh/setup-uv@v8.0.0
with:
python-version: "3.13"

Expand All @@ -153,7 +150,7 @@ jobs:
cache-target: release
bins: cargo-codspeed

- run: python crates/jiter/benches/generate_big.py
- run: uv run crates/jiter/benches/generate_big.py

- run: cargo codspeed build -F python -p jiter

Expand All @@ -180,7 +177,7 @@ jobs:
- if: steps.cache-rust.outputs.cache-hit != 'true'
run: cargo install cargo-fuzz
- run: |
# cargo fuzz defaults to musl targets, which is seeming incomatible with sanitizers according to CI failures
# cargo fuzz defaults to musl targets, which is seemingly incompatible with sanitizers according to CI failures
RUST_TARGET=$(rustc -Vv | grep host | cut -d ' ' -f 2)
cargo fuzz run --target=$RUST_TARGET --fuzz-dir crates/fuzz compare_to_serde --release -- -max_total_time=300s

Expand All @@ -200,7 +197,7 @@ jobs:
run: cargo install cargo-fuzz

- run: |
# cargo fuzz defaults to musl targets, which is seeming incomatible with sanitizers according to CI failures
# cargo fuzz defaults to musl targets, which is seemingly incompatible with sanitizers according to CI failures
RUST_TARGET=$(rustc -Vv | grep host | cut -d ' ' -f 2)
cargo fuzz run --target=$RUST_TARGET --fuzz-dir crates/fuzz compare_skip --release -- -max_total_time=300s

Expand All @@ -209,11 +206,13 @@ jobs:
steps:
- uses: actions/checkout@v5

- name: set up python
uses: actions/setup-python@v6
- uses: astral-sh/setup-uv@v8.0.0
with:
python-version: "3.13"

- name: Install dependencies
run: uv sync --all-packages --group linting

- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt,clippy
Expand Down Expand Up @@ -380,12 +379,11 @@ jobs:
steps:
- uses: actions/checkout@v5

- id: setup-python
name: set up python
uses: actions/setup-python@v6
- name: set up python
id: setup-python
uses: astral-sh/setup-uv@v8.0.0
with:
python-version: ${{ matrix.interpreter }}
allow-prereleases: true

- name: install rust stable
id: rust-toolchain
Expand Down Expand Up @@ -413,11 +411,11 @@ jobs:
steps:
- uses: actions/checkout@v5

- id: setup-python
name: set up python
uses: actions/setup-python@v6
- name: set up python
id: setup-python
uses: astral-sh/setup-uv@v8.0.0
with:
python-version: 3.12
python-version: '3.12'

- name: install rust nightly
uses: dtolnay/rust-toolchain@master
Expand All @@ -439,10 +437,10 @@ jobs:
actions-cache-folder: emsdk-cache

- name: install deps
run: pip install --upgrade pip maturin
run: uv sync --group dev --all-packages

- name: build wheels
run: maturin build --release --target wasm32-unknown-emscripten --out dist -i 3.12
run: uv run maturin build --release --target wasm32-unknown-emscripten --out dist -i 3.12
working-directory: crates/jiter-python

- uses: actions/setup-node@v4
Expand Down Expand Up @@ -529,24 +527,25 @@ jobs:
install: |
set -x
if command -v apt-get &> /dev/null; then
echo "installing python & pip with apt-get..."
echo "installing python, pip and curl with apt-get..."
apt-get update
apt-get install -y --no-install-recommends python3 python3-pip python3-venv git
apt-get install -y --no-install-recommends python3 python3-pip python3-venv git curl
else
echo "installing python & pip with apk..."
echo "installing python, pip and curl with apk..."
apk update
apk add python3 py3-pip git
apk add python3 py3-pip git curl
fi
env: |
UV_NO_PROGRESS: '1'
run: |
cd crates/jiter-python
set -x
# typing-extensions isn't automatically installed because of `--no-index --no-deps`
python3 -m venv venv
source venv/bin/activate
python3 -m pip install --upgrade pip -r tests/requirements.txt
python3 -m pip install jiter --no-index --no-deps --find-links dist --force-reinstall
python3 -m pytest
python3 -c 'import jiter; print(jiter.__version__)'
curl -LsSf https://astral.sh/uv/install.sh | sh
source $HOME/.local/bin/env # So that uv can be found once installed
uv sync --group dev --no-install-package jiter
cd crates/jiter-python
uv pip install jiter --no-index --no-deps --find-links dist --force-reinstall
uv run --no-sync pytest
uv run --no-sync python -c 'import jiter; print(jiter.__version__)'

test-builds-os:
name: test build on ${{ matrix.os }}
Expand All @@ -562,7 +561,8 @@ jobs:
- uses: actions/checkout@v5

- name: set up python
uses: actions/setup-python@v6
id: setup-python
uses: astral-sh/setup-uv@v8.0.0
with:
python-version: "3.13"

Expand All @@ -575,11 +575,11 @@ jobs:

- name: run tests
run: |
python3 -m pip install --upgrade pip -r tests/requirements.txt
python3 -m pip install jiter --no-index --no-deps --find-links dist --force-reinstall
python3 -m pytest
python3 -c 'import jiter; print(jiter.__version__)'
working-directory: crates/jiter-python
uv sync --group dev --no-install-package jiter
cd crates/jiter-python
uv pip install jiter --no-index --no-deps --find-links dist --force-reinstall
uv run pytest
uv run python -c 'import jiter; print(jiter.__version__)'

# https://github.com/marketplace/actions/alls-green#why used for branch protection checks
check:
Expand Down
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ repos:
types: [rust]
language: system
pass_filenames: false
- id: lint-python
name: Lint python
entry: make lint-python
types: [python]
language: system
pass_filenames: false
- id: check-without-num-bigint
name: Check without num-bigint feature
entry: cargo check --no-default-features --package jiter
Expand Down
18 changes: 14 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
.DEFAULT_GOAL := all
python_sources = crates/jiter/benches/generate_big.py crates/jiter-python/bench.py crates/jiter-python/jiter.pyi crates/jiter-python/tests/test_jiter.py


.PHONY: .uv
.uv:
@uv -V || echo 'Please install uv: https://docs.astral.sh/uv/getting-started/installation/'

.PHONY: format
format:
Expand All @@ -11,30 +17,34 @@ lint:
cargo clippy -- -D warnings
cargo doc

.PHONY: lint-python
lint-python: .uv
uv run ruff check $(python_sources)
uv run ruff format --check $(python_sources)

.PHONY: test
test:
cargo test

.PHONY: python-install
python-install:
pip install -U maturin ujson orjson
pip install -r crates/jiter-python/tests/requirements.txt
uv sync --all-groups --all-packages

.PHONY: python-dev
python-dev:
maturin develop -m crates/jiter-python/Cargo.toml

.PHONY: python-test
python-test: python-dev
pytest crates/jiter-python/tests
uv run pytest crates/jiter-python/tests

.PHONY: python-dev-release
python-dev-release:
maturin develop -m crates/jiter-python/Cargo.toml --release

.PHONY: python-bench
python-bench: python-dev-release
python crates/jiter-python/bench.py
uv run python crates/jiter-python/bench.py

.PHONY: bench
bench:
Expand Down
13 changes: 8 additions & 5 deletions crates/jiter-python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ def from_json(
/,
*,
allow_inf_nan: bool = True,
cache_mode: Literal[True, False, "all", "keys", "none"] = "all",
partial_mode: Literal[True, False, "off", "on", "trailing-strings"] = False,
cache_mode: Literal[True, False, 'all', 'keys', 'none'] = 'all',
partial_mode: Literal[True, False, 'off', 'on', 'trailing-strings'] = False,
catch_duplicate_keys: bool = False,
float_mode: Literal["float", "decimal", "lossless-float"] = "float",
float_mode: Literal['float', 'decimal', 'lossless-float'] = 'float',
) -> Any:
"""
Parse input bytes into a JSON object.
Expand All @@ -42,18 +42,21 @@ def from_json(
Python object built from the JSON input.
"""


def cache_clear() -> None:
"""
Reset the string cache.
"""


def cache_usage() -> int:
"""
get the size of the string cache.

Returns:
Size of the string cache in bytes.
"""

```
## Examples

Expand All @@ -80,7 +83,7 @@ partial_json = b'{"name": "John", "age": 30, "city": "New Yor'
try:
jiter.from_json(partial_json, partial_mode=False)
except ValueError as e:
print(f"Error: {e}")
print(f'Error: {e}')

# Parse incomplete JSON, discarding incomplete last field
result = jiter.from_json(partial_json, partial_mode=True)
Expand Down Expand Up @@ -108,5 +111,5 @@ print(result) # Output: {'foo': 2}
try:
jiter.from_json(json_with_dupes, catch_duplicate_keys=True)
except ValueError as e:
print(f"Error: {e}")
print(f'Error: {e}')
```
Loading
Loading