rufee 0.2.0__tar.gz → 0.2.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {rufee-0.2.0 → rufee-0.2.1}/.github/workflows/ci.yml +9 -7
- rufee-0.2.1/.github/workflows/coverage.yml +94 -0
- {rufee-0.2.0 → rufee-0.2.1}/.github/workflows/release.yml +6 -6
- {rufee-0.2.0 → rufee-0.2.1}/CHANGELOG.md +21 -0
- {rufee-0.2.0 → rufee-0.2.1}/Cargo.lock +1 -1
- {rufee-0.2.0 → rufee-0.2.1}/Cargo.toml +1 -1
- {rufee-0.2.0 → rufee-0.2.1}/PKG-INFO +34 -19
- {rufee-0.2.0 → rufee-0.2.1}/README.md +32 -18
- {rufee-0.2.0 → rufee-0.2.1}/docs/installation.md +24 -16
- rufee-0.2.1/docs/migration-guide.md +252 -0
- {rufee-0.2.0 → rufee-0.2.1}/pyproject.toml +2 -1
- {rufee-0.2.0 → rufee-0.2.1}/python/rufee/_context.py +115 -12
- {rufee-0.2.0 → rufee-0.2.1}/tests/conftest.py +1 -0
- {rufee-0.2.0 → rufee-0.2.1}/tests/test_shim.py +135 -3
- {rufee-0.2.0 → rufee-0.2.1}/.gitignore +0 -0
- {rufee-0.2.0 → rufee-0.2.1}/LICENSE +0 -0
- {rufee-0.2.0 → rufee-0.2.1}/Makefile +0 -0
- {rufee-0.2.0 → rufee-0.2.1}/docker-compose.yml +0 -0
- {rufee-0.2.0 → rufee-0.2.1}/python/rufee/__init__.py +0 -0
- {rufee-0.2.0 → rufee-0.2.1}/scripts/bench.py +0 -0
- {rufee-0.2.0 → rufee-0.2.1}/scripts/known_failures/mysql.txt +0 -0
- {rufee-0.2.0 → rufee-0.2.1}/scripts/known_failures/sqlite.txt +0 -0
- {rufee-0.2.0 → rufee-0.2.1}/scripts/run_peewee_tests.py +0 -0
- {rufee-0.2.0 → rufee-0.2.1}/src/classes.rs +0 -0
- {rufee-0.2.0 → rufee-0.2.1}/src/ctx.rs +0 -0
- {rufee-0.2.0 → rufee-0.2.1}/src/lib.rs +0 -0
- {rufee-0.2.0 → rufee-0.2.1}/src/nodes/basic.rs +0 -0
- {rufee-0.2.0 → rufee-0.2.1}/src/nodes/function.rs +0 -0
- {rufee-0.2.0 → rufee-0.2.1}/src/nodes/json.rs +0 -0
- {rufee-0.2.0 → rufee-0.2.1}/src/nodes/mod.rs +0 -0
- {rufee-0.2.0 → rufee-0.2.1}/src/nodes/query.rs +0 -0
- {rufee-0.2.0 → rufee-0.2.1}/src/nodes/source.rs +0 -0
- {rufee-0.2.0 → rufee-0.2.1}/src/nodes/write.rs +0 -0
- {rufee-0.2.0 → rufee-0.2.1}/tests/known_gaps.py +0 -0
- {rufee-0.2.0 → rufee-0.2.1}/tests/test_asyncio.py +0 -0
- {rufee-0.2.0 → rufee-0.2.1}/tests/test_bench.py +0 -0
- {rufee-0.2.0 → rufee-0.2.1}/tests/test_differential.py +0 -0
- {rufee-0.2.0 → rufee-0.2.1}/tests/test_options.py +0 -0
|
@@ -13,7 +13,7 @@ jobs:
|
|
|
13
13
|
rust:
|
|
14
14
|
runs-on: ubuntu-latest
|
|
15
15
|
steps:
|
|
16
|
-
- uses: actions/checkout@
|
|
16
|
+
- uses: actions/checkout@v7
|
|
17
17
|
- uses: dtolnay/rust-toolchain@stable
|
|
18
18
|
with:
|
|
19
19
|
components: rustfmt, clippy
|
|
@@ -26,13 +26,14 @@ jobs:
|
|
|
26
26
|
runs-on: ubuntu-latest
|
|
27
27
|
strategy:
|
|
28
28
|
matrix:
|
|
29
|
-
python: ["3.11", "3.12", "3.13"]
|
|
29
|
+
python: ["3.11", "3.12", "3.13", "3.14"]
|
|
30
30
|
steps:
|
|
31
|
-
- uses: actions/checkout@
|
|
31
|
+
- uses: actions/checkout@v7
|
|
32
32
|
- uses: dtolnay/rust-toolchain@stable
|
|
33
33
|
- uses: Swatinem/rust-cache@v2
|
|
34
|
-
- uses: astral-sh/setup-uv@
|
|
34
|
+
- uses: astral-sh/setup-uv@v10.4.0
|
|
35
35
|
with:
|
|
36
|
+
cache-dependency-glob: pyproject.toml
|
|
36
37
|
python-version: ${{ matrix.python }}
|
|
37
38
|
- run: uv venv --clear .venv
|
|
38
39
|
- run: uv pip install -p .venv/bin/python -e ".[dev]"
|
|
@@ -54,11 +55,12 @@ jobs:
|
|
|
54
55
|
--health-cmd "mysqladmin ping -uroot -ppeewee --silent"
|
|
55
56
|
--health-interval 2s --health-timeout 2s --health-retries 30
|
|
56
57
|
steps:
|
|
57
|
-
- uses: actions/checkout@
|
|
58
|
+
- uses: actions/checkout@v7
|
|
58
59
|
- uses: dtolnay/rust-toolchain@stable
|
|
59
60
|
- uses: Swatinem/rust-cache@v2
|
|
60
|
-
- uses: astral-sh/setup-uv@
|
|
61
|
+
- uses: astral-sh/setup-uv@v10.4.0
|
|
61
62
|
with:
|
|
63
|
+
cache-dependency-glob: pyproject.toml
|
|
62
64
|
python-version: "3.11"
|
|
63
65
|
- run: uv venv --clear .venv
|
|
64
66
|
- run: uv pip install -p .venv/bin/python -e ".[dev]"
|
|
@@ -82,7 +84,7 @@ jobs:
|
|
|
82
84
|
d = json.load(open(f"strict-{e}.json")); c = d["counts"]
|
|
83
85
|
print(f"| {e} | {d['pass_rate']:.1%} | {c['pass']} | {c['unsupported']} | {c['fail']} | {c['error']} |")
|
|
84
86
|
PY
|
|
85
|
-
- uses: actions/upload-artifact@
|
|
87
|
+
- uses: actions/upload-artifact@v7
|
|
86
88
|
with:
|
|
87
89
|
name: strict-reports
|
|
88
90
|
path: strict-*.json
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
name: Coverage
|
|
2
|
+
|
|
3
|
+
# Line coverage of the Rust renderer and the Python shim, measured by running
|
|
4
|
+
# rufee's own tests and peewee's suite (sqlite, strict) against an
|
|
5
|
+
# instrumented build. On main, the result is published as a shields.io
|
|
6
|
+
# endpoint file on the `badges` branch, which the README badge reads.
|
|
7
|
+
#
|
|
8
|
+
# Kept out of ci.yml on purpose: release.yml reuses ci.yml, and this job needs
|
|
9
|
+
# `contents: write` on main to update the badge.
|
|
10
|
+
|
|
11
|
+
on:
|
|
12
|
+
push:
|
|
13
|
+
branches: [main]
|
|
14
|
+
pull_request:
|
|
15
|
+
|
|
16
|
+
env:
|
|
17
|
+
CARGO_TERM_COLOR: always
|
|
18
|
+
|
|
19
|
+
jobs:
|
|
20
|
+
coverage:
|
|
21
|
+
runs-on: ubuntu-latest
|
|
22
|
+
permissions:
|
|
23
|
+
contents: write
|
|
24
|
+
steps:
|
|
25
|
+
- uses: actions/checkout@v7
|
|
26
|
+
- uses: dtolnay/rust-toolchain@stable
|
|
27
|
+
with:
|
|
28
|
+
components: llvm-tools-preview
|
|
29
|
+
- uses: taiki-e/install-action@v2
|
|
30
|
+
with:
|
|
31
|
+
tool: cargo-llvm-cov
|
|
32
|
+
- uses: astral-sh/setup-uv@v10.4.0
|
|
33
|
+
with:
|
|
34
|
+
cache-dependency-glob: pyproject.toml
|
|
35
|
+
python-version: "3.11"
|
|
36
|
+
- run: uv venv --clear .venv
|
|
37
|
+
- run: uv pip install -p .venv/bin/python -e ".[dev]" coverage
|
|
38
|
+
- run: make peewee-src
|
|
39
|
+
|
|
40
|
+
- name: instrumented build + tests
|
|
41
|
+
# The PyO3 recipe: build the extension with cargo-llvm-cov's
|
|
42
|
+
# environment, run the Python tests against it, then report. A debug
|
|
43
|
+
# build, so the benchmark test (marked slow) is skipped.
|
|
44
|
+
run: |
|
|
45
|
+
source <(cargo llvm-cov show-env --export-prefix)
|
|
46
|
+
export CARGO_TARGET_DIR=$CARGO_LLVM_COV_TARGET_DIR
|
|
47
|
+
cargo llvm-cov clean --workspace
|
|
48
|
+
VIRTUAL_ENV=$PWD/.venv .venv/bin/maturin develop
|
|
49
|
+
.venv/bin/python -m coverage run --source=python/rufee -m pytest -q -m "not slow"
|
|
50
|
+
.venv/bin/python -m coverage run --append --source=python/rufee \
|
|
51
|
+
scripts/run_peewee_tests.py -e sqlite --strict
|
|
52
|
+
cargo llvm-cov report --json --summary-only --output-path rust-coverage.json
|
|
53
|
+
.venv/bin/python -m coverage json -o python-coverage.json
|
|
54
|
+
|
|
55
|
+
- name: summarise
|
|
56
|
+
run: |
|
|
57
|
+
python3 - <<'PY'
|
|
58
|
+
import json, os
|
|
59
|
+
|
|
60
|
+
rust = json.load(open("rust-coverage.json"))["data"][0]["totals"]["lines"]
|
|
61
|
+
py = json.load(open("python-coverage.json"))["totals"]
|
|
62
|
+
parts = {
|
|
63
|
+
"Rust": (rust["covered"], rust["count"]),
|
|
64
|
+
"Python": (py["covered_lines"], py["num_statements"]),
|
|
65
|
+
}
|
|
66
|
+
covered = sum(c for c, _ in parts.values())
|
|
67
|
+
total = sum(t for _, t in parts.values())
|
|
68
|
+
percent = 100 * covered / total
|
|
69
|
+
|
|
70
|
+
with open(os.environ["GITHUB_STEP_SUMMARY"], "a") as out:
|
|
71
|
+
print("| part | covered lines | total | coverage |", file=out)
|
|
72
|
+
print("|---|---|---|---|", file=out)
|
|
73
|
+
for name, (c, t) in {**parts, "total": (covered, total)}.items():
|
|
74
|
+
print(f"| {name} | {c} | {t} | {100 * c / t:.1f}% |", file=out)
|
|
75
|
+
|
|
76
|
+
color = ("brightgreen" if percent >= 90 else "green" if percent >= 80
|
|
77
|
+
else "yellow" if percent >= 70 else "orange" if percent >= 60 else "red")
|
|
78
|
+
json.dump({"schemaVersion": 1, "label": "coverage",
|
|
79
|
+
"message": f"{percent:.0f}%", "color": color},
|
|
80
|
+
open("coverage-badge.json", "w"))
|
|
81
|
+
print(open("coverage-badge.json").read())
|
|
82
|
+
PY
|
|
83
|
+
|
|
84
|
+
- name: publish badge
|
|
85
|
+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
|
|
86
|
+
run: |
|
|
87
|
+
mkdir badges && cp coverage-badge.json badges/coverage.json
|
|
88
|
+
cd badges
|
|
89
|
+
git init -q -b badges
|
|
90
|
+
git config user.name "github-actions[bot]"
|
|
91
|
+
git config user.email "41898283+github-actions[bot]@users.noreply.github.com"
|
|
92
|
+
git add coverage.json
|
|
93
|
+
git commit -q -m "coverage badge for ${GITHUB_SHA::7}"
|
|
94
|
+
git push -q --force "https://x-access-token:${{ github.token }}@github.com/${GITHUB_REPOSITORY}.git" badges
|
|
@@ -28,13 +28,13 @@ jobs:
|
|
|
28
28
|
target: aarch64
|
|
29
29
|
runs-on: ${{ matrix.os }}
|
|
30
30
|
steps:
|
|
31
|
-
- uses: actions/checkout@
|
|
31
|
+
- uses: actions/checkout@v7
|
|
32
32
|
- uses: PyO3/maturin-action@v1
|
|
33
33
|
with:
|
|
34
34
|
target: ${{ matrix.target }}
|
|
35
35
|
args: --release --out dist
|
|
36
36
|
manylinux: auto
|
|
37
|
-
- uses: actions/upload-artifact@
|
|
37
|
+
- uses: actions/upload-artifact@v7
|
|
38
38
|
with:
|
|
39
39
|
name: wheels-${{ matrix.os }}-${{ matrix.target }}
|
|
40
40
|
path: dist
|
|
@@ -43,7 +43,7 @@ jobs:
|
|
|
43
43
|
needs: [ci]
|
|
44
44
|
runs-on: ubuntu-latest
|
|
45
45
|
steps:
|
|
46
|
-
- uses: actions/checkout@
|
|
46
|
+
- uses: actions/checkout@v7
|
|
47
47
|
- name: tag matches pyproject version
|
|
48
48
|
run: |
|
|
49
49
|
version=$(python3 -c 'import tomllib; print(tomllib.load(open("pyproject.toml", "rb"))["project"]["version"])')
|
|
@@ -52,7 +52,7 @@ jobs:
|
|
|
52
52
|
with:
|
|
53
53
|
command: sdist
|
|
54
54
|
args: --out dist
|
|
55
|
-
- uses: actions/upload-artifact@
|
|
55
|
+
- uses: actions/upload-artifact@v7
|
|
56
56
|
with:
|
|
57
57
|
name: wheels-sdist
|
|
58
58
|
path: dist
|
|
@@ -66,7 +66,7 @@ jobs:
|
|
|
66
66
|
permissions:
|
|
67
67
|
id-token: write
|
|
68
68
|
steps:
|
|
69
|
-
- uses: actions/download-artifact@
|
|
69
|
+
- uses: actions/download-artifact@v8
|
|
70
70
|
with:
|
|
71
71
|
pattern: wheels-*
|
|
72
72
|
merge-multiple: true
|
|
@@ -86,7 +86,7 @@ jobs:
|
|
|
86
86
|
GH_TOKEN: ${{ github.token }}
|
|
87
87
|
GH_REPO: ${{ github.repository }}
|
|
88
88
|
steps:
|
|
89
|
-
- uses: actions/download-artifact@
|
|
89
|
+
- uses: actions/download-artifact@v8
|
|
90
90
|
with:
|
|
91
91
|
pattern: wheels-*
|
|
92
92
|
merge-multiple: true
|
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.2.1
|
|
4
|
+
|
|
5
|
+
Observability for shadow-mode rollouts. Rendering is unchanged.
|
|
6
|
+
|
|
7
|
+
- Shadow mismatches are logged with a fixed message, `rufee: shadow mismatch`,
|
|
8
|
+
and their details in `record.rufee`: query class, the application call site
|
|
9
|
+
(first frame outside peewee / playhouse / rufee), and either both full SQL
|
|
10
|
+
strings with an excerpt around the first difference, or the position, count
|
|
11
|
+
and type of the first differing parameter. **Parameter values are no longer
|
|
12
|
+
logged**; 0.2.0 printed both parameter lists.
|
|
13
|
+
- `RUFEE_LOG_SQL=0` / `rufee.configure(log_sql=False)` leaves the SQL strings
|
|
14
|
+
out of mismatch logs too. They normally hold placeholders, not values, but an
|
|
15
|
+
application that inlines values, or a Rust bug that does, puts them there.
|
|
16
|
+
- A Rust error on a query peewee renders fine is logged at WARNING as
|
|
17
|
+
`rufee: renderer error` (query class, call site, exception). It was DEBUG
|
|
18
|
+
only. Errors peewee raises too stay at DEBUG.
|
|
19
|
+
- `rufee.stats.snapshot()` returns all counters in one read.
|
|
20
|
+
- New [`docs/migration-guide.md`](docs/migration-guide.md): shadow → rust
|
|
21
|
+
rollout, what rufee logs and counts, exporting the counters, mismatch triage,
|
|
22
|
+
rollback.
|
|
23
|
+
|
|
3
24
|
## 0.2.0
|
|
4
25
|
|
|
5
26
|
**Targets peewee 4.5.3. peewee 3.x is no longer supported**; stay on rufee
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: rufee
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.1
|
|
4
4
|
Classifier: Programming Language :: Rust
|
|
5
5
|
Classifier: Programming Language :: Python :: 3
|
|
6
6
|
Classifier: Programming Language :: Python :: 3.11
|
|
7
7
|
Classifier: Programming Language :: Python :: 3.12
|
|
8
8
|
Classifier: Programming Language :: Python :: 3.13
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
9
10
|
Classifier: License :: OSI Approved :: MIT License
|
|
10
11
|
Classifier: Topic :: Database
|
|
11
12
|
Requires-Dist: peewee>=4.5.3,<4.6
|
|
@@ -25,6 +26,15 @@ Project-URL: Repository, https://github.com/yoshonabee/rufee
|
|
|
25
26
|
|
|
26
27
|
# rufee
|
|
27
28
|
|
|
29
|
+
[](https://pypi.org/project/rufee/)
|
|
30
|
+
[](https://pypi.org/project/rufee/)
|
|
31
|
+
[](https://github.com/coleifer/peewee)
|
|
32
|
+
[](#peewees-own-test-suite-as-the-spec)
|
|
33
|
+
[](#peewees-own-test-suite-as-the-spec)
|
|
34
|
+
[](https://github.com/yoshonabee/rufee/actions/workflows/ci.yml?query=branch%3Amain)
|
|
35
|
+
[](https://github.com/yoshonabee/rufee/actions/workflows/coverage.yml?query=branch%3Amain)
|
|
36
|
+
[](LICENSE)
|
|
37
|
+
|
|
28
38
|
A drop-in replacement for [peewee](https://github.com/coleifer/peewee)'s SQL
|
|
29
39
|
rendering `Context`, implemented in Rust.
|
|
30
40
|
|
|
@@ -39,9 +49,8 @@ string and parameter list.
|
|
|
39
49
|
|
|
40
50
|
Status: **renders peewee 4.5.3's entire test-suite byte-identically** (strict
|
|
41
51
|
mode 100% on sqlite and MySQL, including peewee's asyncio tests, see below).
|
|
42
|
-
peewee 3.x is no longer supported; use rufee `v0.1.0` for peewee 3.17.
|
|
43
|
-
|
|
44
|
-
install from a wheel or from source, see
|
|
52
|
+
peewee 3.x is no longer supported; use rufee `v0.1.0` for peewee 3.17.
|
|
53
|
+
Install with `pip install rufee`; other options are in
|
|
45
54
|
[`docs/installation.md`](docs/installation.md). The API may still move.
|
|
46
55
|
|
|
47
56
|
## How it plugs in
|
|
@@ -75,9 +84,11 @@ synchronous `context_class` path inside a greenlet, so rufee needs nothing
|
|
|
75
84
|
async-specific.
|
|
76
85
|
|
|
77
86
|
Full instructions — wheels, building from source, the Docker recipe, the
|
|
78
|
-
`RUFEE_MODE` / `RUFEE_FALLBACK` / `RUFEE_FORCE` knobs
|
|
79
|
-
|
|
80
|
-
|
|
87
|
+
`RUFEE_MODE` / `RUFEE_FALLBACK` / `RUFEE_FORCE` knobs and how to verify the
|
|
88
|
+
install — are in [`docs/installation.md`](docs/installation.md). To put it in
|
|
89
|
+
front of production traffic, go through shadow mode first:
|
|
90
|
+
[`docs/migration-guide.md`](docs/migration-guide.md) covers the rollout, what
|
|
91
|
+
rufee logs and counts, and how to read a mismatch.
|
|
81
92
|
|
|
82
93
|
## Design
|
|
83
94
|
|
|
@@ -97,8 +108,9 @@ and how to roll it out through shadow mode — are in
|
|
|
97
108
|
1. *Whole-query fallback*: any node type the Rust side does not support, and
|
|
98
109
|
any Rust-side error, makes the whole query re-render through peewee's
|
|
99
110
|
original `Context`. Incomplete coverage is slower, never wrong.
|
|
100
|
-
2. *Shadow mode*: render both ways, log any mismatch (SQL string or params
|
|
101
|
-
|
|
111
|
+
2. *Shadow mode*: render both ways, log any mismatch (SQL string or params,
|
|
112
|
+
never parameter values) with the application call site, and return
|
|
113
|
+
peewee's result. Meant for production traffic before switching over.
|
|
102
114
|
3. *Version gate*: rufee reads peewee's private attributes (`_from_list`,
|
|
103
115
|
`_where`, `_returning`, `Join._on`, ...). It targets peewee **4.5.x**;
|
|
104
116
|
on any other version it degrades to a pure pass-through.
|
|
@@ -183,12 +195,13 @@ make mysql-up && make peewee-tests ARGS="-e mysql --strict"
|
|
|
183
195
|
make peewee-tests ARGS="-e sqlite --baseline" # unmodified peewee
|
|
184
196
|
```
|
|
185
197
|
|
|
186
|
-
### rufee's own tests (`tests
|
|
198
|
+
### rufee's own tests (`tests/`)
|
|
187
199
|
|
|
188
200
|
1. **Shim behaviour** (`test_shim.py`): fallback triggers (unsupported node,
|
|
189
201
|
Rust error, Rust panic) never leak exceptions; shadow mode logs mismatches
|
|
190
|
-
|
|
191
|
-
initial state and every
|
|
202
|
+
with their call site and without parameter values, and returns peewee's
|
|
203
|
+
result; version gate degrades to pass-through; the initial state and every
|
|
204
|
+
context option are forwarded.
|
|
192
205
|
2. **Differential testing** (`test_differential.py`, hypothesis): random query
|
|
193
206
|
trees from a small grammar (selects, joins, subqueries, compound selects,
|
|
194
207
|
inserts, updates, deletes, functions, windows, CASE) rendered with both
|
|
@@ -234,10 +247,11 @@ Ordered. Done items are kept for the record.
|
|
|
234
247
|
`CompoundSelectQuery`, `BitField` flags. Every node type peewee's suite
|
|
235
248
|
exercises now renders in Rust.
|
|
236
249
|
8. **Docs**: installation / user guide done — [`docs/installation.md`](docs/installation.md)
|
|
237
|
-
(install, `context_class`, configuration, verification,
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
250
|
+
(install, `context_class`, configuration, verification, version gate,
|
|
251
|
+
troubleshooting) and [`docs/migration-guide.md`](docs/migration-guide.md)
|
|
252
|
+
(shadow → rust rollout, logs and counters, mismatch triage, rollback).
|
|
253
|
+
Still to write: a contributor guide (how to add a node type: Rust match arm
|
|
254
|
+
+ hypothesis rule + which peewee tests it unlocks).
|
|
241
255
|
9. ~~**Performance pass**~~ Done. Join select went from 14.7 to 9.8 µs
|
|
242
256
|
(7.3x → 11.0x), `insert_many` ×100 from 275 to 195 µs, by: keeping the
|
|
243
257
|
dialect options off the per-scope state so a scope change clones seven
|
|
@@ -250,8 +264,9 @@ Ordered. Done items are kept for the record.
|
|
|
250
264
|
the C API and calling each field's `db_value` converter, both required for
|
|
251
265
|
byte-identical output. Going further means not reading the Python tree at
|
|
252
266
|
all, which is the rejected "AST in Rust" design.
|
|
253
|
-
10.
|
|
254
|
-
|
|
267
|
+
10. ~~**Release**~~ Done: a `v*` tag runs CI, builds wheels and the sdist,
|
|
268
|
+
publishes to PyPI (trusted publishing) and attaches them to the GitHub
|
|
269
|
+
release.
|
|
255
270
|
11. ~~**peewee 4.5.3**~~ Done (0.2.0): State / `_query_type` interface,
|
|
256
271
|
ordering and window quoting, compound selects, FOR UPDATE, MySQL `CONCAT()`,
|
|
257
272
|
sub-selects as operands and sources, JSON paths, asyncio coverage.
|
|
@@ -275,7 +290,7 @@ Configuration at runtime: `RUFEE_MODE=rust|shadow|off` (default `rust`),
|
|
|
275
290
|
`RUFEE_FALLBACK=1|0` (default `1`; `0` makes unsupported nodes raise
|
|
276
291
|
`rufee.Unsupported`), or `rufee.configure(mode=..., fallback=...)`. Counters
|
|
277
292
|
live in `rufee.stats`; shadow-mode mismatches are logged on the `rufee`
|
|
278
|
-
logger at WARNING.
|
|
293
|
+
logger at WARNING (see [`docs/migration-guide.md`](docs/migration-guide.md)).
|
|
279
294
|
|
|
280
295
|
## License
|
|
281
296
|
|
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# rufee
|
|
2
2
|
|
|
3
|
+
[](https://pypi.org/project/rufee/)
|
|
4
|
+
[](https://pypi.org/project/rufee/)
|
|
5
|
+
[](https://github.com/coleifer/peewee)
|
|
6
|
+
[](#peewees-own-test-suite-as-the-spec)
|
|
7
|
+
[](#peewees-own-test-suite-as-the-spec)
|
|
8
|
+
[](https://github.com/yoshonabee/rufee/actions/workflows/ci.yml?query=branch%3Amain)
|
|
9
|
+
[](https://github.com/yoshonabee/rufee/actions/workflows/coverage.yml?query=branch%3Amain)
|
|
10
|
+
[](LICENSE)
|
|
11
|
+
|
|
3
12
|
A drop-in replacement for [peewee](https://github.com/coleifer/peewee)'s SQL
|
|
4
13
|
rendering `Context`, implemented in Rust.
|
|
5
14
|
|
|
@@ -14,9 +23,8 @@ string and parameter list.
|
|
|
14
23
|
|
|
15
24
|
Status: **renders peewee 4.5.3's entire test-suite byte-identically** (strict
|
|
16
25
|
mode 100% on sqlite and MySQL, including peewee's asyncio tests, see below).
|
|
17
|
-
peewee 3.x is no longer supported; use rufee `v0.1.0` for peewee 3.17.
|
|
18
|
-
|
|
19
|
-
install from a wheel or from source, see
|
|
26
|
+
peewee 3.x is no longer supported; use rufee `v0.1.0` for peewee 3.17.
|
|
27
|
+
Install with `pip install rufee`; other options are in
|
|
20
28
|
[`docs/installation.md`](docs/installation.md). The API may still move.
|
|
21
29
|
|
|
22
30
|
## How it plugs in
|
|
@@ -50,9 +58,11 @@ synchronous `context_class` path inside a greenlet, so rufee needs nothing
|
|
|
50
58
|
async-specific.
|
|
51
59
|
|
|
52
60
|
Full instructions — wheels, building from source, the Docker recipe, the
|
|
53
|
-
`RUFEE_MODE` / `RUFEE_FALLBACK` / `RUFEE_FORCE` knobs
|
|
54
|
-
|
|
55
|
-
|
|
61
|
+
`RUFEE_MODE` / `RUFEE_FALLBACK` / `RUFEE_FORCE` knobs and how to verify the
|
|
62
|
+
install — are in [`docs/installation.md`](docs/installation.md). To put it in
|
|
63
|
+
front of production traffic, go through shadow mode first:
|
|
64
|
+
[`docs/migration-guide.md`](docs/migration-guide.md) covers the rollout, what
|
|
65
|
+
rufee logs and counts, and how to read a mismatch.
|
|
56
66
|
|
|
57
67
|
## Design
|
|
58
68
|
|
|
@@ -72,8 +82,9 @@ and how to roll it out through shadow mode — are in
|
|
|
72
82
|
1. *Whole-query fallback*: any node type the Rust side does not support, and
|
|
73
83
|
any Rust-side error, makes the whole query re-render through peewee's
|
|
74
84
|
original `Context`. Incomplete coverage is slower, never wrong.
|
|
75
|
-
2. *Shadow mode*: render both ways, log any mismatch (SQL string or params
|
|
76
|
-
|
|
85
|
+
2. *Shadow mode*: render both ways, log any mismatch (SQL string or params,
|
|
86
|
+
never parameter values) with the application call site, and return
|
|
87
|
+
peewee's result. Meant for production traffic before switching over.
|
|
77
88
|
3. *Version gate*: rufee reads peewee's private attributes (`_from_list`,
|
|
78
89
|
`_where`, `_returning`, `Join._on`, ...). It targets peewee **4.5.x**;
|
|
79
90
|
on any other version it degrades to a pure pass-through.
|
|
@@ -158,12 +169,13 @@ make mysql-up && make peewee-tests ARGS="-e mysql --strict"
|
|
|
158
169
|
make peewee-tests ARGS="-e sqlite --baseline" # unmodified peewee
|
|
159
170
|
```
|
|
160
171
|
|
|
161
|
-
### rufee's own tests (`tests
|
|
172
|
+
### rufee's own tests (`tests/`)
|
|
162
173
|
|
|
163
174
|
1. **Shim behaviour** (`test_shim.py`): fallback triggers (unsupported node,
|
|
164
175
|
Rust error, Rust panic) never leak exceptions; shadow mode logs mismatches
|
|
165
|
-
|
|
166
|
-
initial state and every
|
|
176
|
+
with their call site and without parameter values, and returns peewee's
|
|
177
|
+
result; version gate degrades to pass-through; the initial state and every
|
|
178
|
+
context option are forwarded.
|
|
167
179
|
2. **Differential testing** (`test_differential.py`, hypothesis): random query
|
|
168
180
|
trees from a small grammar (selects, joins, subqueries, compound selects,
|
|
169
181
|
inserts, updates, deletes, functions, windows, CASE) rendered with both
|
|
@@ -209,10 +221,11 @@ Ordered. Done items are kept for the record.
|
|
|
209
221
|
`CompoundSelectQuery`, `BitField` flags. Every node type peewee's suite
|
|
210
222
|
exercises now renders in Rust.
|
|
211
223
|
8. **Docs**: installation / user guide done — [`docs/installation.md`](docs/installation.md)
|
|
212
|
-
(install, `context_class`, configuration, verification,
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
224
|
+
(install, `context_class`, configuration, verification, version gate,
|
|
225
|
+
troubleshooting) and [`docs/migration-guide.md`](docs/migration-guide.md)
|
|
226
|
+
(shadow → rust rollout, logs and counters, mismatch triage, rollback).
|
|
227
|
+
Still to write: a contributor guide (how to add a node type: Rust match arm
|
|
228
|
+
+ hypothesis rule + which peewee tests it unlocks).
|
|
216
229
|
9. ~~**Performance pass**~~ Done. Join select went from 14.7 to 9.8 µs
|
|
217
230
|
(7.3x → 11.0x), `insert_many` ×100 from 275 to 195 µs, by: keeping the
|
|
218
231
|
dialect options off the per-scope state so a scope change clones seven
|
|
@@ -225,8 +238,9 @@ Ordered. Done items are kept for the record.
|
|
|
225
238
|
the C API and calling each field's `db_value` converter, both required for
|
|
226
239
|
byte-identical output. Going further means not reading the Python tree at
|
|
227
240
|
all, which is the rejected "AST in Rust" design.
|
|
228
|
-
10.
|
|
229
|
-
|
|
241
|
+
10. ~~**Release**~~ Done: a `v*` tag runs CI, builds wheels and the sdist,
|
|
242
|
+
publishes to PyPI (trusted publishing) and attaches them to the GitHub
|
|
243
|
+
release.
|
|
230
244
|
11. ~~**peewee 4.5.3**~~ Done (0.2.0): State / `_query_type` interface,
|
|
231
245
|
ordering and window quoting, compound selects, FOR UPDATE, MySQL `CONCAT()`,
|
|
232
246
|
sub-selects as operands and sources, JSON paths, asyncio coverage.
|
|
@@ -250,7 +264,7 @@ Configuration at runtime: `RUFEE_MODE=rust|shadow|off` (default `rust`),
|
|
|
250
264
|
`RUFEE_FALLBACK=1|0` (default `1`; `0` makes unsupported nodes raise
|
|
251
265
|
`rufee.Unsupported`), or `rufee.configure(mode=..., fallback=...)`. Counters
|
|
252
266
|
live in `rufee.stats`; shadow-mode mismatches are logged on the `rufee`
|
|
253
|
-
logger at WARNING.
|
|
267
|
+
logger at WARNING (see [`docs/migration-guide.md`](docs/migration-guide.md)).
|
|
254
268
|
|
|
255
269
|
## License
|
|
256
270
|
|
|
@@ -9,7 +9,7 @@ assignment to `Database.context_class`.
|
|
|
9
9
|
|
|
10
10
|
| | |
|
|
11
11
|
|---|---|
|
|
12
|
-
| Python | CPython 3.11, 3.12 or 3.
|
|
12
|
+
| Python | CPython 3.11, 3.12, 3.13 or 3.14. Wheels are built `abi3-py311`, so one wheel per platform covers all of them. |
|
|
13
13
|
| peewee | **4.5.x** (developed against 4.5.3). rufee reads peewee's private attributes; on any other version it turns itself off — see [Version gate](#version-gate). For peewee 3.17 use rufee 0.1.0. |
|
|
14
14
|
| Platform | Linux `x86_64` / `aarch64`, macOS `arm64`. Anywhere else, build from source — you need a Rust stable toolchain. |
|
|
15
15
|
|
|
@@ -46,8 +46,12 @@ pip install --no-deps rufee-0.2.0-cp311-abi3-manylinux_2_17_x86_64.whl
|
|
|
46
46
|
|
|
47
47
|
### From PyPI
|
|
48
48
|
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
```sh
|
|
50
|
+
pip install rufee # or: uv add rufee
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
PyPI has the same wheels as the GitHub release, plus the sdist (which builds
|
|
54
|
+
from source, so it needs Rust) for other platforms.
|
|
51
55
|
|
|
52
56
|
### From source
|
|
53
57
|
|
|
@@ -152,13 +156,14 @@ through rufee on sqlite and MySQL.
|
|
|
152
156
|
|
|
153
157
|
## Configure
|
|
154
158
|
|
|
155
|
-
|
|
159
|
+
Four environment variables, all read **once at import time**:
|
|
156
160
|
|
|
157
161
|
| Variable | Default | Meaning |
|
|
158
162
|
|---|---|---|
|
|
159
163
|
| `RUFEE_MODE` | `rust` | `rust` renders in Rust; `shadow` renders both ways, logs any difference and returns peewee's result; `off` is a pure pass-through. An unrecognised value warns and falls back to `rust`. |
|
|
160
164
|
| `RUFEE_FALLBACK` | `1` | `0` / `false` / `no` makes an unsupported node raise `rufee.Unsupported` instead of re-rendering with peewee. Strict mode — for tests, not for production. |
|
|
161
165
|
| `RUFEE_FORCE` | unset | `1` runs rufee against an unsupported peewee version anyway. See below. |
|
|
166
|
+
| `RUFEE_LOG_SQL` | `1` | `0` / `false` / `no` leaves the SQL strings out of shadow-mismatch logs. The strings normally hold placeholders, not values; see [Do the logs contain user data?](migration-guide.md#do-the-logs-contain-user-data). |
|
|
162
167
|
|
|
163
168
|
Because they are read at import, setting `RUFEE_MODE` after `import rufee` has
|
|
164
169
|
no effect. Change it at runtime through the API instead:
|
|
@@ -166,11 +171,16 @@ no effect. Change it at runtime through the API instead:
|
|
|
166
171
|
```python
|
|
167
172
|
rufee.configure(mode='shadow') # or mode='rust' / 'off'
|
|
168
173
|
rufee.configure(fallback=False) # strict
|
|
174
|
+
rufee.configure(log_sql=False) # no SQL strings in mismatch logs
|
|
169
175
|
```
|
|
170
176
|
|
|
171
177
|
Counters live in `rufee.stats` (`rust`, `fallback`, `errors`, `shadow`,
|
|
172
|
-
`mismatch
|
|
173
|
-
|
|
178
|
+
`mismatch`; `snapshot()` reads them all, `reset()` zeroes them), and rufee
|
|
179
|
+
logs on the `rufee` logger: shadow mismatches and Rust errors on queries peewee
|
|
180
|
+
renders fine at `WARNING`, every fallback at `DEBUG`. The WARNING records carry
|
|
181
|
+
their details in `record.rufee`; see
|
|
182
|
+
[the migration guide](migration-guide.md#what-rufee-reports) for the fields and
|
|
183
|
+
for exporting the counters.
|
|
174
184
|
|
|
175
185
|
```python
|
|
176
186
|
import logging
|
|
@@ -199,15 +209,11 @@ If `rufee.stats` stays all-zero, rufee is installed but not rendering: either
|
|
|
199
209
|
|
|
200
210
|
## Rolling out
|
|
201
211
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
3. With no mismatches over real traffic, switch to `RUFEE_MODE=rust`.
|
|
208
|
-
|
|
209
|
-
Keep `RUFEE_FALLBACK=1` (the default) in both steps: an unsupported node then
|
|
210
|
-
re-renders through peewee, so incomplete coverage is slow, never wrong.
|
|
212
|
+
Go through shadow mode first: deploy with `RUFEE_MODE=shadow`, where every
|
|
213
|
+
query is rendered both ways and peewee's result is the one executed, watch for
|
|
214
|
+
mismatches, then switch to `RUFEE_MODE=rust`. The full procedure, what to
|
|
215
|
+
monitor, when to switch and how to roll back, is in
|
|
216
|
+
[`migration-guide.md`](migration-guide.md).
|
|
211
217
|
|
|
212
218
|
## Version gate
|
|
213
219
|
|
|
@@ -232,7 +238,9 @@ import?
|
|
|
232
238
|
|
|
233
239
|
**`stats.fallback` is climbing.** Some node type is not implemented in Rust, or
|
|
234
240
|
the render raised. Both are logged at `DEBUG` on the `rufee` logger with the
|
|
235
|
-
query class and the reason; turn that on to see which.
|
|
241
|
+
query class and the reason; turn that on to see which. A Rust error on a query
|
|
242
|
+
peewee renders fine is also logged at `WARNING` as `rufee: renderer error`,
|
|
243
|
+
with the application's `callsite`.
|
|
236
244
|
|
|
237
245
|
**pip: "not a supported wheel on this platform".** The wheel was built for a
|
|
238
246
|
different platform tag — for `--compatibility linux` wheels, build and install
|