Skip to content

Commit 0dbb128

Browse files
committed
Modernize project setup using uv
Migrate to uv Apply Python linting
1 parent 8ece8a4 commit 0dbb128

File tree

15 files changed

+883
-118
lines changed

15 files changed

+883
-118
lines changed

.github/actions/build-pgo-wheel/action.yml

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,15 @@ runs:
3434
env:
3535
RUSTFLAGS: '-Cprofile-generate=${{ github.workspace }}/profdata'
3636

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

5247
- name: merge pgo data
5348
run: ${{ env.LLVM_PROFDATA }} merge -o ${{ github.workspace }}/merged.profdata ${{ github.workspace }}/profdata

.github/workflows/ci.yml

Lines changed: 41 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ jobs:
9494
strategy:
9595
fail-fast: false
9696
matrix:
97-
python-version: ["3.13", "3.13t", "graalpy-25.0"]
97+
python-version: ["3.13", "3.13t", "graalpy3.12"]
9898

9999
env:
100100
RUNS_ON: ubuntu-latest
@@ -103,28 +103,25 @@ jobs:
103103
- uses: actions/checkout@v5
104104

105105
- name: set up python ${{ matrix.python-version }}
106-
uses: actions/setup-python@v6
106+
uses: astral-sh/setup-uv@v8.0.0
107107
with:
108108
python-version: ${{ matrix.python-version }}
109109

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

114-
- name: Install python dependencies
115-
run: pip install -r crates/jiter-python/tests/requirements.txt
116-
117-
- name: Build jiter-python
114+
- name: Install dependencies
118115
run: |
119116
source <(cargo llvm-cov show-env --export-prefix)
120117
cargo llvm-cov clean --workspace --profraw-only
121-
pip install -e crates/jiter-python --config-settings=build-args='--profile dev'
118+
uv sync --group dev --all-packages
122119
123120
- name: Run tests
124121
run: |
125122
source <(cargo llvm-cov show-env --export-prefix)
126-
pytest crates/jiter-python/tests
127-
python crates/jiter-python/bench.py jiter jiter-cache --fast
123+
uv run pytest crates/jiter-python/tests
124+
uv run crates/jiter-python/bench.py jiter jiter-cache --fast
128125
env:
129126
RUST_BACKTRACE: 1
130127

@@ -143,7 +140,7 @@ jobs:
143140
steps:
144141
- uses: actions/checkout@v5
145142

146-
- uses: actions/setup-python@v6
143+
- uses: astral-sh/setup-uv@v8.0.0
147144
with:
148145
python-version: "3.13"
149146

@@ -153,7 +150,7 @@ jobs:
153150
cache-target: release
154151
bins: cargo-codspeed
155152

156-
- run: python crates/jiter/benches/generate_big.py
153+
- run: uv run crates/jiter/benches/generate_big.py
157154

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

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

202199
- run: |
203-
# cargo fuzz defaults to musl targets, which is seeming incomatible with sanitizers according to CI failures
200+
# cargo fuzz defaults to musl targets, which is seemingly incompatible with sanitizers according to CI failures
204201
RUST_TARGET=$(rustc -Vv | grep host | cut -d ' ' -f 2)
205202
cargo fuzz run --target=$RUST_TARGET --fuzz-dir crates/fuzz compare_skip --release -- -max_total_time=300s
206203
@@ -209,11 +206,13 @@ jobs:
209206
steps:
210207
- uses: actions/checkout@v5
211208

212-
- name: set up python
213-
uses: actions/setup-python@v6
209+
- uses: astral-sh/setup-uv@v8.0.0
214210
with:
215211
python-version: "3.13"
216212

213+
- name: Install dependencies
214+
run: uv sync --all-packages --group linting
215+
217216
- uses: dtolnay/rust-toolchain@stable
218217
with:
219218
components: rustfmt,clippy
@@ -380,12 +379,11 @@ jobs:
380379
steps:
381380
- uses: actions/checkout@v5
382381

383-
- id: setup-python
384-
name: set up python
385-
uses: actions/setup-python@v6
382+
- name: set up python
383+
id: setup-python
384+
uses: astral-sh/setup-uv@v8.0.0
386385
with:
387386
python-version: ${{ matrix.interpreter }}
388-
allow-prereleases: true
389387

390388
- name: install rust stable
391389
id: rust-toolchain
@@ -413,11 +411,11 @@ jobs:
413411
steps:
414412
- uses: actions/checkout@v5
415413

416-
- id: setup-python
417-
name: set up python
418-
uses: actions/setup-python@v6
414+
- name: set up python
415+
id: setup-python
416+
uses: astral-sh/setup-uv@v8.0.0
419417
with:
420-
python-version: 3.12
418+
python-version: '3.12'
421419

422420
- name: install rust nightly
423421
uses: dtolnay/rust-toolchain@master
@@ -439,10 +437,10 @@ jobs:
439437
actions-cache-folder: emsdk-cache
440438

441439
- name: install deps
442-
run: pip install --upgrade pip maturin
440+
run: uv sync --group dev --all-packages
443441

444442
- name: build wheels
445-
run: maturin build --release --target wasm32-unknown-emscripten --out dist -i 3.12
443+
run: uv run maturin build --release --target wasm32-unknown-emscripten --out dist -i 3.12
446444
working-directory: crates/jiter-python
447445

448446
- uses: actions/setup-node@v4
@@ -529,24 +527,23 @@ jobs:
529527
install: |
530528
set -x
531529
if command -v apt-get &> /dev/null; then
532-
echo "installing python & pip with apt-get..."
530+
echo "installing python, pip and curl with apt-get..."
533531
apt-get update
534-
apt-get install -y --no-install-recommends python3 python3-pip python3-venv git
532+
apt-get install -y --no-install-recommends python3 python3-pip python3-venv git curl
535533
else
536-
echo "installing python & pip with apk..."
534+
echo "installing python, pip and curl with apk..."
537535
apk update
538-
apk add python3 py3-pip git
536+
apk add python3 py3-pip git curl
539537
fi
540538
run: |
541-
cd crates/jiter-python
542539
set -x
543-
# typing-extensions isn't automatically installed because of `--no-index --no-deps`
544-
python3 -m venv venv
545-
source venv/bin/activate
546-
python3 -m pip install --upgrade pip -r tests/requirements.txt
547-
python3 -m pip install jiter --no-index --no-deps --find-links dist --force-reinstall
548-
python3 -m pytest
549-
python3 -c 'import jiter; print(jiter.__version__)'
540+
curl -LsSf https://astral.sh/uv/install.sh | sh
541+
source $HOME/.local/bin/env # So that uv can be found once installed
542+
uv sync --group dev --no-install-package jiter
543+
cd crates/jiter-python
544+
uv pip install jiter --no-index --no-deps --find-links dist --force-reinstall
545+
uv run pytest
546+
uv run python -c 'import jiter; print(jiter.__version__)'
550547
551548
test-builds-os:
552549
name: test build on ${{ matrix.os }}
@@ -562,7 +559,8 @@ jobs:
562559
- uses: actions/checkout@v5
563560

564561
- name: set up python
565-
uses: actions/setup-python@v6
562+
id: setup-python
563+
uses: astral-sh/setup-uv@v8.0.0
566564
with:
567565
python-version: "3.13"
568566

@@ -575,11 +573,11 @@ jobs:
575573

576574
- name: run tests
577575
run: |
578-
python3 -m pip install --upgrade pip -r tests/requirements.txt
579-
python3 -m pip install jiter --no-index --no-deps --find-links dist --force-reinstall
580-
python3 -m pytest
581-
python3 -c 'import jiter; print(jiter.__version__)'
582-
working-directory: crates/jiter-python
576+
uv sync --group dev --no-install-package jiter
577+
uv pip install jiter --no-index --no-deps --find-links dist --force-reinstall
578+
cd crates/jiter-python
579+
uv run pytest
580+
uv run python -c 'import jiter; print(jiter.__version__)'
583581
584582
# https://github.com/marketplace/actions/alls-green#why used for branch protection checks
585583
check:

.pre-commit-config.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ repos:
2525
types: [rust]
2626
language: system
2727
pass_filenames: false
28+
- id: lint-python
29+
name: Lint python
30+
entry: make lint-python
31+
types: [python]
32+
language: system
33+
pass_filenames: false
2834
- id: check-without-num-bigint
2935
name: Check without num-bigint feature
3036
entry: cargo check --no-default-features --package jiter

Makefile

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
.DEFAULT_GOAL := all
2+
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
3+
4+
5+
.PHONY: .uv
6+
.uv:
7+
@uv -V || echo 'Please install uv: https://docs.astral.sh/uv/getting-started/installation/'
28

39
.PHONY: format
410
format:
@@ -11,30 +17,34 @@ lint:
1117
cargo clippy -- -D warnings
1218
cargo doc
1319

20+
.PHONY: lint-python
21+
lint-python: .uv
22+
uv run ruff check $(python_sources)
23+
uv run ruff format --check $(python_sources)
24+
1425
.PHONY: test
1526
test:
1627
cargo test
1728

1829
.PHONY: python-install
1930
python-install:
20-
pip install -U maturin ujson orjson
21-
pip install -r crates/jiter-python/tests/requirements.txt
31+
uv sync --all-groups --all-packages
2232

2333
.PHONY: python-dev
2434
python-dev:
2535
maturin develop -m crates/jiter-python/Cargo.toml
2636

2737
.PHONY: python-test
2838
python-test: python-dev
29-
pytest crates/jiter-python/tests
39+
uv run pytest crates/jiter-python/tests
3040

3141
.PHONY: python-dev-release
3242
python-dev-release:
3343
maturin develop -m crates/jiter-python/Cargo.toml --release
3444

3545
.PHONY: python-bench
3646
python-bench: python-dev-release
37-
python crates/jiter-python/bench.py
47+
uv run python crates/jiter-python/bench.py
3848

3949
.PHONY: bench
4050
bench:

crates/jiter-python/README.md

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ def from_json(
1515
/,
1616
*,
1717
allow_inf_nan: bool = True,
18-
cache_mode: Literal[True, False, "all", "keys", "none"] = "all",
19-
partial_mode: Literal[True, False, "off", "on", "trailing-strings"] = False,
18+
cache_mode: Literal[True, False, 'all', 'keys', 'none'] = 'all',
19+
partial_mode: Literal[True, False, 'off', 'on', 'trailing-strings'] = False,
2020
catch_duplicate_keys: bool = False,
21-
float_mode: Literal["float", "decimal", "lossless-float"] = "float",
21+
float_mode: Literal['float', 'decimal', 'lossless-float'] = 'float',
2222
) -> Any:
2323
"""
2424
Parse input bytes into a JSON object.
@@ -42,18 +42,21 @@ def from_json(
4242
Python object built from the JSON input.
4343
"""
4444

45+
4546
def cache_clear() -> None:
4647
"""
4748
Reset the string cache.
4849
"""
4950

51+
5052
def cache_usage() -> int:
5153
"""
5254
get the size of the string cache.
5355
5456
Returns:
5557
Size of the string cache in bytes.
5658
"""
59+
5760
```
5861
## Examples
5962

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

8588
# Parse incomplete JSON, discarding incomplete last field
8689
result = jiter.from_json(partial_json, partial_mode=True)
@@ -108,5 +111,5 @@ print(result) # Output: {'foo': 2}
108111
try:
109112
jiter.from_json(json_with_dupes, catch_duplicate_keys=True)
110113
except ValueError as e:
111-
print(f"Error: {e}")
114+
print(f'Error: {e}')
112115
```

0 commit comments

Comments
 (0)