weaved 0.1.0__tar.gz → 0.2.0__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.
- weaved-0.2.0/.github/workflows/ci.yml +243 -0
- weaved-0.2.0/.github/workflows/conventional-commits.yml +31 -0
- weaved-0.2.0/.github/workflows/performance-history.yml +67 -0
- weaved-0.2.0/.github/workflows/release-pr.yml +32 -0
- weaved-0.2.0/CHANGELOG.md +45 -0
- {weaved-0.1.0 → weaved-0.2.0}/Cargo.lock +1 -1
- {weaved-0.1.0 → weaved-0.2.0}/Cargo.toml +2 -1
- {weaved-0.1.0 → weaved-0.2.0}/PKG-INFO +43 -18
- {weaved-0.1.0 → weaved-0.2.0}/README.md +42 -17
- {weaved-0.1.0 → weaved-0.2.0}/asv.conf.json +5 -0
- weaved-0.2.0/benchmarks/README.md +148 -0
- weaved-0.2.0/benchmarks/asv/bench_merge.py +469 -0
- weaved-0.2.0/benchmarks/performance-data.json +153 -0
- weaved-0.2.0/benchmarks/performance.html +89 -0
- weaved-0.2.0/benchmarks/performance.svg +28 -0
- weaved-0.2.0/benchmarks/update_performance_report.py +179 -0
- {weaved-0.1.0 → weaved-0.2.0}/pyproject.toml +1 -0
- weaved-0.2.0/python/weave/__init__.py +20 -0
- weaved-0.2.0/python/weave/_weave.pyi +5 -0
- weaved-0.2.0/release-plz.toml +27 -0
- weaved-0.2.0/src/lib.rs +52 -0
- weaved-0.2.0/src/merge.rs +486 -0
- {weaved-0.1.0 → weaved-0.2.0}/tests/test_merge.py +204 -22
- {weaved-0.1.0 → weaved-0.2.0}/tests/test_properties.py +47 -13
- {weaved-0.1.0 → weaved-0.2.0}/uv.lock +11 -0
- weaved-0.1.0/.github/workflows/ci.yml +0 -123
- weaved-0.1.0/benchmarks/README.md +0 -35
- weaved-0.1.0/benchmarks/asv/bench_merge.py +0 -154
- weaved-0.1.0/python/weave/__init__.py +0 -5
- weaved-0.1.0/python/weave/_weave.pyi +0 -7
- weaved-0.1.0/src/lib.rs +0 -29
- weaved-0.1.0/src/merge.rs +0 -109
- {weaved-0.1.0 → weaved-0.2.0}/.gitignore +0 -0
- {weaved-0.1.0 → weaved-0.2.0}/benchmarks/asv/__init__.py +0 -0
- {weaved-0.1.0 → weaved-0.2.0}/python/weave/py.typed +0 -0
- {weaved-0.1.0 → weaved-0.2.0}/src/recursion.rs +0 -0
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
workflow_dispatch:
|
|
5
|
+
push:
|
|
6
|
+
branches: ["**"]
|
|
7
|
+
pull_request:
|
|
8
|
+
|
|
9
|
+
permissions:
|
|
10
|
+
contents: read
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
test:
|
|
14
|
+
strategy:
|
|
15
|
+
fail-fast: false
|
|
16
|
+
matrix:
|
|
17
|
+
os: [ubuntu-latest, macos-latest, windows-latest]
|
|
18
|
+
python: ["3.11", "3.14"]
|
|
19
|
+
runs-on: ${{ matrix.os }}
|
|
20
|
+
steps:
|
|
21
|
+
- uses: actions/checkout@v7
|
|
22
|
+
- uses: dtolnay/rust-toolchain@stable
|
|
23
|
+
with:
|
|
24
|
+
components: rustfmt, clippy
|
|
25
|
+
- uses: astral-sh/setup-uv@v10.2.0
|
|
26
|
+
with:
|
|
27
|
+
python-version: ${{ matrix.python }}
|
|
28
|
+
- run: uv sync --locked
|
|
29
|
+
- run: uv run --no-sync pytest
|
|
30
|
+
- run: uv run --no-sync ruff check .
|
|
31
|
+
- run: uv run --no-sync ruff format --check .
|
|
32
|
+
- run: cargo fmt --check
|
|
33
|
+
- run: uv run --no-sync -- cargo clippy --locked --all-targets -- -D warnings
|
|
34
|
+
- run: uv run --no-sync maturin build --release --locked
|
|
35
|
+
if: matrix.os != 'ubuntu-latest'
|
|
36
|
+
- uses: PyO3/maturin-action@v1.51.0
|
|
37
|
+
if: matrix.os == 'ubuntu-latest'
|
|
38
|
+
with:
|
|
39
|
+
maturin-version: 1.15.0
|
|
40
|
+
manylinux: "2_28"
|
|
41
|
+
args: --release --locked -i python${{ matrix.python }} --compatibility pypi --out target/wheels
|
|
42
|
+
- uses: actions/upload-artifact@v7
|
|
43
|
+
if: matrix.os != 'ubuntu-latest'
|
|
44
|
+
with:
|
|
45
|
+
name: wheel-${{ matrix.os }}-py${{ matrix.python }}
|
|
46
|
+
path: target/wheels/*.whl
|
|
47
|
+
- uses: actions/upload-artifact@v7
|
|
48
|
+
if: matrix.os == 'ubuntu-latest'
|
|
49
|
+
with:
|
|
50
|
+
name: wheel-${{ matrix.os }}-py${{ matrix.python }}
|
|
51
|
+
path: target/wheels/*manylinux*.whl
|
|
52
|
+
|
|
53
|
+
performance:
|
|
54
|
+
if: github.event_name == 'pull_request' || github.ref == 'refs/heads/master'
|
|
55
|
+
runs-on: ubuntu-latest
|
|
56
|
+
steps:
|
|
57
|
+
- uses: actions/checkout@v7
|
|
58
|
+
with:
|
|
59
|
+
fetch-depth: 0
|
|
60
|
+
- uses: actions/setup-python@v6
|
|
61
|
+
with:
|
|
62
|
+
python-version: "3.14"
|
|
63
|
+
- uses: dtolnay/rust-toolchain@stable
|
|
64
|
+
- uses: astral-sh/setup-uv@v10.2.0
|
|
65
|
+
- run: uv sync --locked
|
|
66
|
+
- name: Register benchmark runner
|
|
67
|
+
run: |
|
|
68
|
+
os_name="$(. /etc/os-release && echo "$PRETTY_NAME")"
|
|
69
|
+
cpu="$(lscpu | awk -F: '/Model name/ {gsub(/^[[:space:]]+/, "", $2); print $2; exit}')"
|
|
70
|
+
ram="$(awk '/MemTotal/ {printf "%.0fGB", $2 / 1048576}' /proc/meminfo)"
|
|
71
|
+
uv run asv machine --yes \
|
|
72
|
+
--machine "github-${RUNNER_OS}-${RUNNER_ARCH}" \
|
|
73
|
+
--os "$os_name" \
|
|
74
|
+
--arch "$(uname -m)" \
|
|
75
|
+
--cpu "$cpu" \
|
|
76
|
+
--num_cpu "$(nproc)" \
|
|
77
|
+
--ram "$ram"
|
|
78
|
+
- name: Compare base and proposed revision
|
|
79
|
+
env:
|
|
80
|
+
BASE: ${{ github.event.pull_request.base.sha || github.event.before }}
|
|
81
|
+
HEAD: ${{ github.sha }}
|
|
82
|
+
run: |
|
|
83
|
+
if git diff --quiet "$BASE" "$HEAD" -- src python/weave Cargo.toml Cargo.lock pyproject.toml; then
|
|
84
|
+
echo "Skipping ASV: no package implementation changes"
|
|
85
|
+
else
|
|
86
|
+
uv run asv continuous --bench 'time_(flat|wide_mixed_late|medium_mixed_late|copy_subtree(_mixed_late)?|list_replace|list_concat)_weave' --factor 1.15 --interleave-rounds --split "$BASE" "$HEAD"
|
|
87
|
+
fi
|
|
88
|
+
- uses: actions/upload-artifact@v7
|
|
89
|
+
if: always()
|
|
90
|
+
with:
|
|
91
|
+
name: asv-results-${{ github.run_id }}
|
|
92
|
+
path: .asv/results
|
|
93
|
+
if-no-files-found: ignore
|
|
94
|
+
|
|
95
|
+
release-check:
|
|
96
|
+
if: >-
|
|
97
|
+
github.event_name == 'workflow_dispatch' ||
|
|
98
|
+
(github.event_name == 'push' && github.ref == 'refs/heads/master' && github.actor != 'github-actions[bot]')
|
|
99
|
+
runs-on: ubuntu-latest
|
|
100
|
+
outputs:
|
|
101
|
+
should_release: ${{ steps.check.outputs.should_release }}
|
|
102
|
+
version: ${{ steps.check.outputs.version }}
|
|
103
|
+
tag: ${{ steps.check.outputs.tag }}
|
|
104
|
+
steps:
|
|
105
|
+
- uses: actions/checkout@v7
|
|
106
|
+
- name: Check whether Cargo.toml version is untagged
|
|
107
|
+
id: check
|
|
108
|
+
run: |
|
|
109
|
+
VERSION="$(python3 -c 'import tomllib; print(tomllib.load(open("Cargo.toml", "rb"))["package"]["version"])')"
|
|
110
|
+
TAG="v${VERSION}"
|
|
111
|
+
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
|
|
112
|
+
echo "tag=${TAG}" >> "$GITHUB_OUTPUT"
|
|
113
|
+
if git ls-remote --exit-code --tags origin "refs/tags/${TAG}" >/dev/null 2>&1; then
|
|
114
|
+
echo "Tag ${TAG} already exists; skipping release."
|
|
115
|
+
echo "should_release=false" >> "$GITHUB_OUTPUT"
|
|
116
|
+
else
|
|
117
|
+
echo "Tag ${TAG} does not exist yet; preparing release."
|
|
118
|
+
echo "should_release=true" >> "$GITHUB_OUTPUT"
|
|
119
|
+
fi
|
|
120
|
+
|
|
121
|
+
sdist:
|
|
122
|
+
needs: [release-check]
|
|
123
|
+
if: needs.release-check.outputs.should_release == 'true'
|
|
124
|
+
runs-on: ubuntu-latest
|
|
125
|
+
steps:
|
|
126
|
+
- uses: actions/checkout@v7
|
|
127
|
+
- uses: astral-sh/setup-uv@v10.2.0
|
|
128
|
+
- run: uv build --sdist
|
|
129
|
+
- uses: actions/upload-artifact@v7
|
|
130
|
+
with:
|
|
131
|
+
name: source-distribution
|
|
132
|
+
path: dist/*
|
|
133
|
+
|
|
134
|
+
draft-release:
|
|
135
|
+
needs: [release-check, test, sdist]
|
|
136
|
+
if: needs.release-check.outputs.should_release == 'true'
|
|
137
|
+
runs-on: ubuntu-latest
|
|
138
|
+
permissions:
|
|
139
|
+
contents: write
|
|
140
|
+
outputs:
|
|
141
|
+
release_id: ${{ steps.create_draft.outputs.id || steps.create_draft_fallback.outputs.id }}
|
|
142
|
+
steps:
|
|
143
|
+
- uses: actions/checkout@v7
|
|
144
|
+
- uses: actions/download-artifact@v8.0.1
|
|
145
|
+
with:
|
|
146
|
+
pattern: "wheel-*"
|
|
147
|
+
path: dist
|
|
148
|
+
merge-multiple: true
|
|
149
|
+
- uses: actions/download-artifact@v8.0.1
|
|
150
|
+
with:
|
|
151
|
+
name: source-distribution
|
|
152
|
+
path: dist
|
|
153
|
+
- name: Extract release notes from CHANGELOG.md
|
|
154
|
+
id: notes
|
|
155
|
+
env:
|
|
156
|
+
RELEASE_VERSION: ${{ needs.release-check.outputs.version }}
|
|
157
|
+
run: |
|
|
158
|
+
python3 - <<'PY'
|
|
159
|
+
import os, pathlib, re
|
|
160
|
+
|
|
161
|
+
version = os.environ["RELEASE_VERSION"]
|
|
162
|
+
changelog = pathlib.Path("CHANGELOG.md")
|
|
163
|
+
notes = ""
|
|
164
|
+
if changelog.exists():
|
|
165
|
+
text = changelog.read_text(encoding="utf-8")
|
|
166
|
+
pattern = re.compile(
|
|
167
|
+
rf"^## \[?v?{re.escape(version)}\]?[^\n]*\n(.*?)(?=^## |\Z)",
|
|
168
|
+
re.MULTILINE | re.DOTALL,
|
|
169
|
+
)
|
|
170
|
+
match = pattern.search(text)
|
|
171
|
+
if match:
|
|
172
|
+
notes = match.group(1).strip()
|
|
173
|
+
|
|
174
|
+
if notes:
|
|
175
|
+
pathlib.Path("release_notes.md").write_text(notes + "\n", encoding="utf-8")
|
|
176
|
+
with open(os.environ["GITHUB_OUTPUT"], "a", encoding="utf-8") as out:
|
|
177
|
+
out.write("has_notes=true\n")
|
|
178
|
+
else:
|
|
179
|
+
with open(os.environ["GITHUB_OUTPUT"], "a", encoding="utf-8") as out:
|
|
180
|
+
out.write("has_notes=false\n")
|
|
181
|
+
PY
|
|
182
|
+
- name: Create draft GitHub Release
|
|
183
|
+
id: create_draft
|
|
184
|
+
if: steps.notes.outputs.has_notes == 'true'
|
|
185
|
+
uses: softprops/action-gh-release@v3
|
|
186
|
+
with:
|
|
187
|
+
draft: true
|
|
188
|
+
tag_name: ${{ needs.release-check.outputs.tag }}
|
|
189
|
+
name: ${{ needs.release-check.outputs.tag }}
|
|
190
|
+
target_commitish: ${{ github.sha }}
|
|
191
|
+
body_path: release_notes.md
|
|
192
|
+
files: dist/*
|
|
193
|
+
- name: Create draft GitHub Release (generated notes fallback)
|
|
194
|
+
id: create_draft_fallback
|
|
195
|
+
if: steps.notes.outputs.has_notes != 'true'
|
|
196
|
+
uses: softprops/action-gh-release@v3
|
|
197
|
+
with:
|
|
198
|
+
draft: true
|
|
199
|
+
tag_name: ${{ needs.release-check.outputs.tag }}
|
|
200
|
+
name: ${{ needs.release-check.outputs.tag }}
|
|
201
|
+
target_commitish: ${{ github.sha }}
|
|
202
|
+
generate_release_notes: true
|
|
203
|
+
files: dist/*
|
|
204
|
+
|
|
205
|
+
publish:
|
|
206
|
+
needs: [release-check, draft-release]
|
|
207
|
+
if: needs.release-check.outputs.should_release == 'true'
|
|
208
|
+
runs-on: ubuntu-latest
|
|
209
|
+
environment:
|
|
210
|
+
name: pypi
|
|
211
|
+
url: https://pypi.org/project/weaved/
|
|
212
|
+
permissions:
|
|
213
|
+
id-token: write
|
|
214
|
+
steps:
|
|
215
|
+
- uses: actions/download-artifact@v8.0.1
|
|
216
|
+
with:
|
|
217
|
+
pattern: "wheel-*"
|
|
218
|
+
path: dist
|
|
219
|
+
merge-multiple: true
|
|
220
|
+
- uses: actions/download-artifact@v8.0.1
|
|
221
|
+
with:
|
|
222
|
+
name: source-distribution
|
|
223
|
+
path: dist
|
|
224
|
+
- uses: pypa/gh-action-pypi-publish@release/v1
|
|
225
|
+
|
|
226
|
+
seal-release:
|
|
227
|
+
needs: [release-check, draft-release, publish]
|
|
228
|
+
if: needs.release-check.outputs.should_release == 'true'
|
|
229
|
+
runs-on: ubuntu-latest
|
|
230
|
+
permissions:
|
|
231
|
+
contents: write
|
|
232
|
+
steps:
|
|
233
|
+
- name: Publish draft release and create tag
|
|
234
|
+
env:
|
|
235
|
+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
236
|
+
RELEASE_ID: ${{ needs.draft-release.outputs.release_id }}
|
|
237
|
+
TARGET_SHA: ${{ github.sha }}
|
|
238
|
+
run: |
|
|
239
|
+
gh api \
|
|
240
|
+
--method PATCH \
|
|
241
|
+
"repos/${GITHUB_REPOSITORY}/releases/${RELEASE_ID}" \
|
|
242
|
+
-F draft=false \
|
|
243
|
+
-f target_commitish="${TARGET_SHA}"
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
name: Conventional Commits
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
pull_request:
|
|
5
|
+
types:
|
|
6
|
+
- opened
|
|
7
|
+
- edited
|
|
8
|
+
- synchronize
|
|
9
|
+
- reopened
|
|
10
|
+
|
|
11
|
+
permissions:
|
|
12
|
+
contents: read
|
|
13
|
+
pull-requests: read
|
|
14
|
+
|
|
15
|
+
jobs:
|
|
16
|
+
pr-title:
|
|
17
|
+
name: Validate PR title
|
|
18
|
+
runs-on: ubuntu-latest
|
|
19
|
+
steps:
|
|
20
|
+
- uses: amannn/action-semantic-pull-request@v6
|
|
21
|
+
env:
|
|
22
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
23
|
+
|
|
24
|
+
commits:
|
|
25
|
+
name: Validate commit messages
|
|
26
|
+
runs-on: ubuntu-latest
|
|
27
|
+
steps:
|
|
28
|
+
- uses: actions/checkout@v7
|
|
29
|
+
with:
|
|
30
|
+
fetch-depth: 0
|
|
31
|
+
- uses: wagoid/commitlint-github-action@v6
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
name: Performance history
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [master]
|
|
6
|
+
paths-ignore:
|
|
7
|
+
- benchmarks/performance-data.json
|
|
8
|
+
- benchmarks/performance.html
|
|
9
|
+
|
|
10
|
+
permissions:
|
|
11
|
+
contents: write
|
|
12
|
+
|
|
13
|
+
jobs:
|
|
14
|
+
record:
|
|
15
|
+
runs-on: ubuntu-latest
|
|
16
|
+
timeout-minutes: 30
|
|
17
|
+
steps:
|
|
18
|
+
- uses: actions/checkout@v7
|
|
19
|
+
with:
|
|
20
|
+
fetch-depth: 0
|
|
21
|
+
- uses: actions/setup-python@v6
|
|
22
|
+
with:
|
|
23
|
+
python-version: "3.14"
|
|
24
|
+
- uses: dtolnay/rust-toolchain@stable
|
|
25
|
+
- uses: astral-sh/setup-uv@v10.2.0
|
|
26
|
+
- run: uv sync --locked
|
|
27
|
+
- name: Register benchmark runner
|
|
28
|
+
run: |
|
|
29
|
+
os_name="$(. /etc/os-release && echo "$PRETTY_NAME")"
|
|
30
|
+
cpu="$(lscpu | awk -F: '/Model name/ {gsub(/^[[:space:]]+/, "", $2); print $2; exit}')"
|
|
31
|
+
ram="$(awk '/MemTotal/ {printf "%.0fGB", $2 / 1048576}' /proc/meminfo)"
|
|
32
|
+
uv run asv machine --yes \
|
|
33
|
+
--machine github-ubuntu-x64 \
|
|
34
|
+
--os "$os_name" --arch "$(uname -m)" --cpu "$cpu" \
|
|
35
|
+
--num_cpu "$(nproc)" --ram "$ram"
|
|
36
|
+
- name: Benchmark merged revision
|
|
37
|
+
env:
|
|
38
|
+
COMMIT: ${{ github.sha }}
|
|
39
|
+
run: >-
|
|
40
|
+
uv run asv run "${COMMIT}^!"
|
|
41
|
+
--bench 'time_(flat|wide_mixed_late|medium_mixed_late|copy_subtree(_mixed_late)?|list_replace|list_concat)_(weave|python|mergedeep)'
|
|
42
|
+
--interleave-rounds --machine github-ubuntu-x64
|
|
43
|
+
- name: Update and commit the report
|
|
44
|
+
env:
|
|
45
|
+
COMMIT: ${{ github.sha }}
|
|
46
|
+
run: |
|
|
47
|
+
git fetch origin master
|
|
48
|
+
git checkout -B master origin/master
|
|
49
|
+
git config user.name github-actions[bot]
|
|
50
|
+
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
|
|
51
|
+
find .asv/results -maxdepth 4 -type f -print
|
|
52
|
+
for attempt in 1 2 3 4 5; do
|
|
53
|
+
python benchmarks/update_performance_report.py "$COMMIT"
|
|
54
|
+
git add benchmarks/performance-data.json benchmarks/performance.html
|
|
55
|
+
if git diff --cached --quiet; then
|
|
56
|
+
echo "Benchmark history already contains $COMMIT"
|
|
57
|
+
exit 0
|
|
58
|
+
fi
|
|
59
|
+
git commit -m "chore(bench): record ASV benchmark history"
|
|
60
|
+
if git push origin master; then
|
|
61
|
+
exit 0
|
|
62
|
+
fi
|
|
63
|
+
git fetch origin master
|
|
64
|
+
git reset --hard origin/master
|
|
65
|
+
done
|
|
66
|
+
echo "Could not push benchmark history after five attempts" >&2
|
|
67
|
+
exit 1
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
name: Release PR
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- master
|
|
7
|
+
paths-ignore:
|
|
8
|
+
- benchmarks/performance-data.json
|
|
9
|
+
- benchmarks/performance.html
|
|
10
|
+
|
|
11
|
+
permissions:
|
|
12
|
+
contents: write
|
|
13
|
+
pull-requests: write
|
|
14
|
+
|
|
15
|
+
concurrency:
|
|
16
|
+
group: release-pr-${{ github.ref }}
|
|
17
|
+
cancel-in-progress: true
|
|
18
|
+
|
|
19
|
+
jobs:
|
|
20
|
+
release-pr:
|
|
21
|
+
name: Create or update release PR
|
|
22
|
+
runs-on: ubuntu-latest
|
|
23
|
+
steps:
|
|
24
|
+
- uses: actions/checkout@v7
|
|
25
|
+
with:
|
|
26
|
+
fetch-depth: 0
|
|
27
|
+
- uses: dtolnay/rust-toolchain@stable
|
|
28
|
+
- uses: release-plz/action@v0.5.148
|
|
29
|
+
with:
|
|
30
|
+
command: release-pr
|
|
31
|
+
env:
|
|
32
|
+
GITHUB_TOKEN: ${{ secrets.RELEASE_PLZ_TOKEN || secrets.GITHUB_TOKEN }}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
## [0.2.0](https://github.com/cetanu/weaved/compare/v0.1.0...v0.2.0) - 2026-11-23
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- [**breaking**] replace concat_lists with MergeFlag and add TYPESAFE
|
|
15
|
+
- support variadic dictionary inputs in merge()
|
|
16
|
+
|
|
17
|
+
### CI
|
|
18
|
+
|
|
19
|
+
- *(release)* add release-plz, GitHub releases, and conventional commit checks
|
|
20
|
+
- log result files in ASV history workflow
|
|
21
|
+
- focus ASV gate on high-signal workloads
|
|
22
|
+
- limit ASV gate to native timings
|
|
23
|
+
|
|
24
|
+
### Fixed
|
|
25
|
+
|
|
26
|
+
- preserve custom key hashing on bulk updates
|
|
27
|
+
- handle late containers in bulk merges
|
|
28
|
+
|
|
29
|
+
### Performance
|
|
30
|
+
|
|
31
|
+
- use shorter prefix for mixed medium merges
|
|
32
|
+
- use raw scan for smaller wide merges
|
|
33
|
+
- use raw scan for medium wide merges
|
|
34
|
+
- skip scalar update scan for tiny merges
|
|
35
|
+
- scan copied dictionaries without wrapping scalar entries
|
|
36
|
+
- scan copied lists without scalar wrapper values
|
|
37
|
+
- skip key checks for nested small merges
|
|
38
|
+
- scan bulk merge values with CPython dict iteration
|
|
39
|
+
- bulk update small scalar-only merges
|
|
40
|
+
- bulk update large scalar-only merges
|
|
41
|
+
|
|
42
|
+
### Styling
|
|
43
|
+
|
|
44
|
+
- *(bench)* format performance report generator
|
|
45
|
+
- format scan optimization and record subtree benchmarks
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "weave"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.2.0"
|
|
4
4
|
edition = "2024"
|
|
5
5
|
rust-version = "1.85"
|
|
6
|
+
publish = false
|
|
6
7
|
description = "Fast, non-mutating deep merges for Python dictionaries"
|
|
7
8
|
readme = "README.md"
|
|
8
9
|
repository = "https://github.com/cetanu/weaved"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: weaved
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.0
|
|
4
4
|
Classifier: Development Status :: 3 - Alpha
|
|
5
5
|
Classifier: Programming Language :: Rust
|
|
6
6
|
Classifier: Programming Language :: Python :: 3
|
|
@@ -28,29 +28,47 @@ extension uses [PyO3](https://pyo3.rs/) and is built with
|
|
|
28
28
|
[maturin](https://www.maturin.rs/).
|
|
29
29
|
|
|
30
30
|
```python
|
|
31
|
-
from weave import merge
|
|
31
|
+
from weave import CONCAT_LISTS, TYPESAFE, merge
|
|
32
32
|
|
|
33
33
|
defaults = {"server": {"host": "localhost", "port": 8000}, "plugins": ["logging"]}
|
|
34
|
-
|
|
34
|
+
env = {"server": {"port": 9000}, "plugins": ["metrics"]}
|
|
35
|
+
cli = {"server": {"tls": True}, "plugins": ["tracing"]}
|
|
35
36
|
|
|
36
|
-
merge(defaults,
|
|
37
|
-
# {"server": {"host": "localhost", "port": 9000}, "plugins": ["
|
|
37
|
+
merge(defaults, env, cli)
|
|
38
|
+
# {"server": {"host": "localhost", "port": 9000, "tls": True}, "plugins": ["tracing"]}
|
|
38
39
|
|
|
39
|
-
merge(defaults,
|
|
40
|
-
# {"server": {"host": "localhost", "port": 9000}, "plugins": ["logging", "metrics"]}
|
|
40
|
+
merge(defaults, env, cli, flags=CONCAT_LISTS)
|
|
41
|
+
# {"server": {"host": "localhost", "port": 9000, "tls": True}, "plugins": ["logging", "metrics", "tracing"]}
|
|
42
|
+
|
|
43
|
+
merge(defaults, env, cli, flags=CONCAT_LISTS | TYPESAFE)
|
|
44
|
+
# Raises TypeError if conflicting keys have mismatched types
|
|
41
45
|
```
|
|
42
46
|
|
|
43
47
|
## Merge semantics
|
|
44
48
|
|
|
45
|
-
`merge(
|
|
49
|
+
`merge(*dicts, flags=0) -> dict`
|
|
50
|
+
|
|
51
|
+
`flags` is a bitmask of `MergeFlag` (`enum.IntFlag`) values, combinable with `|`
|
|
52
|
+
(similar to Python's `re` module flags):
|
|
53
|
+
|
|
54
|
+
- `NONE` (`0o0`): default behavior — recursively merge dictionaries, replace
|
|
55
|
+
other conflicts with the rightmost value.
|
|
56
|
+
- `CONCAT_LISTS` (`0o1`): concatenate consecutive lists at a key in
|
|
57
|
+
left-to-right order at every dictionary depth. Duplicates remain; elements
|
|
58
|
+
are not merged by index.
|
|
59
|
+
- `TYPESAFE` (`0o2`): raise `TypeError` when conflicting values at the same key
|
|
60
|
+
do not have the exact same Python type (`type(a) is not type(b)`).
|
|
46
61
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
-
|
|
50
|
-
|
|
51
|
-
|
|
62
|
+
Additional guarantees:
|
|
63
|
+
|
|
64
|
+
- Accepts zero or more dictionaries (subclasses are accepted). `merge()` returns
|
|
65
|
+
`{}`; `merge(d)` returns an independent copy of `d`'s dict/list containers.
|
|
66
|
+
- Dictionaries merge from left to right. When consecutive values at a key are
|
|
67
|
+
dictionaries, they merge recursively.
|
|
68
|
+
- Without `TYPESAFE`, the rightmost value wins, including `None` and empty values.
|
|
69
|
+
- Invalid flag bits raise `ValueError`.
|
|
52
70
|
- Every dictionary and list reached through dictionary values or list elements
|
|
53
|
-
is copied. Changing those containers in the result does not change
|
|
71
|
+
is copied. Changing those containers in the result does not change any input.
|
|
54
72
|
Container subclasses become plain dictionaries and lists, using their stored
|
|
55
73
|
contents rather than overridden Python methods.
|
|
56
74
|
- Keys and other objects (including tuples, sets, and custom instances) retain
|
|
@@ -58,8 +76,9 @@ merge(defaults, overrides, concat_lists=True)
|
|
|
58
76
|
For example, a list inside an opaque tuple remains shared.
|
|
59
77
|
- Repeated references to the same container are copied separately; alias
|
|
60
78
|
relationships are not preserved.
|
|
61
|
-
- Existing keys retain
|
|
62
|
-
|
|
79
|
+
- Existing keys retain the insertion order and key identity of the leftmost
|
|
80
|
+
dictionary that introduced them. New keys are appended in order. All hashable
|
|
81
|
+
Python keys are supported.
|
|
63
82
|
- Traversed cycles or more than 256 nested dictionary/list levels raise
|
|
64
83
|
`RecursionError`; Python's own stack guard can stop traversal earlier.
|
|
65
84
|
Overwritten values are not traversed.
|
|
@@ -90,7 +109,8 @@ The merge walks Python containers directly through PyO3, with native dictionary
|
|
|
90
109
|
copies and list concatenation. Scalar leaves stay as Python objects; there is no
|
|
91
110
|
JSON encoding, deserialization, or conversion to Rust maps.
|
|
92
111
|
|
|
93
|
-
Run the Airspeed Velocity benchmarks against an equivalent Python implementation
|
|
112
|
+
Run the Airspeed Velocity benchmarks against an equivalent Python implementation
|
|
113
|
+
and [`mergedeep`](https://pypi.org/project/mergedeep/):
|
|
94
114
|
|
|
95
115
|
```sh
|
|
96
116
|
uv sync
|
|
@@ -99,7 +119,8 @@ uv run asv continuous --factor 1.15 --interleave-rounds --split HEAD^ HEAD
|
|
|
99
119
|
|
|
100
120
|
Benchmarks check matching results before timing and cover flat dictionaries,
|
|
101
121
|
nested configuration, deep dictionaries, large lists, and list concatenation.
|
|
102
|
-
|
|
122
|
+
Weave and the Python reference copy dict/list containers and share opaque leaves,
|
|
123
|
+
while `mergedeep` is benchmarked in non-mutating mode (`mergedeep.merge({}, left, right, ...)`). ASV
|
|
103
124
|
stores results in `.asv/results`; CI compares each pull request against its base
|
|
104
125
|
revision on the same runner and uploads the result files as a workflow artifact.
|
|
105
126
|
The 15% threshold filters small variations. Use release builds and measure your
|
|
@@ -108,3 +129,7 @@ own workload; Python allocation and key hashing still determine much of the cost
|
|
|
108
129
|
See [local benchmark results](benchmarks/README.md) for measured timings and
|
|
109
130
|
the machine and sampling conditions.
|
|
110
131
|
|
|
132
|
+
The merge-to-merge timing report is generated at
|
|
133
|
+
[`benchmarks/performance.html`](benchmarks/performance.html). Download the file
|
|
134
|
+
and open it in a browser to view the interactive charts.
|
|
135
|
+
|
|
@@ -14,29 +14,47 @@ extension uses [PyO3](https://pyo3.rs/) and is built with
|
|
|
14
14
|
[maturin](https://www.maturin.rs/).
|
|
15
15
|
|
|
16
16
|
```python
|
|
17
|
-
from weave import merge
|
|
17
|
+
from weave import CONCAT_LISTS, TYPESAFE, merge
|
|
18
18
|
|
|
19
19
|
defaults = {"server": {"host": "localhost", "port": 8000}, "plugins": ["logging"]}
|
|
20
|
-
|
|
20
|
+
env = {"server": {"port": 9000}, "plugins": ["metrics"]}
|
|
21
|
+
cli = {"server": {"tls": True}, "plugins": ["tracing"]}
|
|
21
22
|
|
|
22
|
-
merge(defaults,
|
|
23
|
-
# {"server": {"host": "localhost", "port": 9000}, "plugins": ["
|
|
23
|
+
merge(defaults, env, cli)
|
|
24
|
+
# {"server": {"host": "localhost", "port": 9000, "tls": True}, "plugins": ["tracing"]}
|
|
24
25
|
|
|
25
|
-
merge(defaults,
|
|
26
|
-
# {"server": {"host": "localhost", "port": 9000}, "plugins": ["logging", "metrics"]}
|
|
26
|
+
merge(defaults, env, cli, flags=CONCAT_LISTS)
|
|
27
|
+
# {"server": {"host": "localhost", "port": 9000, "tls": True}, "plugins": ["logging", "metrics", "tracing"]}
|
|
28
|
+
|
|
29
|
+
merge(defaults, env, cli, flags=CONCAT_LISTS | TYPESAFE)
|
|
30
|
+
# Raises TypeError if conflicting keys have mismatched types
|
|
27
31
|
```
|
|
28
32
|
|
|
29
33
|
## Merge semantics
|
|
30
34
|
|
|
31
|
-
`merge(
|
|
35
|
+
`merge(*dicts, flags=0) -> dict`
|
|
36
|
+
|
|
37
|
+
`flags` is a bitmask of `MergeFlag` (`enum.IntFlag`) values, combinable with `|`
|
|
38
|
+
(similar to Python's `re` module flags):
|
|
39
|
+
|
|
40
|
+
- `NONE` (`0o0`): default behavior — recursively merge dictionaries, replace
|
|
41
|
+
other conflicts with the rightmost value.
|
|
42
|
+
- `CONCAT_LISTS` (`0o1`): concatenate consecutive lists at a key in
|
|
43
|
+
left-to-right order at every dictionary depth. Duplicates remain; elements
|
|
44
|
+
are not merged by index.
|
|
45
|
+
- `TYPESAFE` (`0o2`): raise `TypeError` when conflicting values at the same key
|
|
46
|
+
do not have the exact same Python type (`type(a) is not type(b)`).
|
|
32
47
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
-
|
|
36
|
-
|
|
37
|
-
|
|
48
|
+
Additional guarantees:
|
|
49
|
+
|
|
50
|
+
- Accepts zero or more dictionaries (subclasses are accepted). `merge()` returns
|
|
51
|
+
`{}`; `merge(d)` returns an independent copy of `d`'s dict/list containers.
|
|
52
|
+
- Dictionaries merge from left to right. When consecutive values at a key are
|
|
53
|
+
dictionaries, they merge recursively.
|
|
54
|
+
- Without `TYPESAFE`, the rightmost value wins, including `None` and empty values.
|
|
55
|
+
- Invalid flag bits raise `ValueError`.
|
|
38
56
|
- Every dictionary and list reached through dictionary values or list elements
|
|
39
|
-
is copied. Changing those containers in the result does not change
|
|
57
|
+
is copied. Changing those containers in the result does not change any input.
|
|
40
58
|
Container subclasses become plain dictionaries and lists, using their stored
|
|
41
59
|
contents rather than overridden Python methods.
|
|
42
60
|
- Keys and other objects (including tuples, sets, and custom instances) retain
|
|
@@ -44,8 +62,9 @@ merge(defaults, overrides, concat_lists=True)
|
|
|
44
62
|
For example, a list inside an opaque tuple remains shared.
|
|
45
63
|
- Repeated references to the same container are copied separately; alias
|
|
46
64
|
relationships are not preserved.
|
|
47
|
-
- Existing keys retain
|
|
48
|
-
|
|
65
|
+
- Existing keys retain the insertion order and key identity of the leftmost
|
|
66
|
+
dictionary that introduced them. New keys are appended in order. All hashable
|
|
67
|
+
Python keys are supported.
|
|
49
68
|
- Traversed cycles or more than 256 nested dictionary/list levels raise
|
|
50
69
|
`RecursionError`; Python's own stack guard can stop traversal earlier.
|
|
51
70
|
Overwritten values are not traversed.
|
|
@@ -76,7 +95,8 @@ The merge walks Python containers directly through PyO3, with native dictionary
|
|
|
76
95
|
copies and list concatenation. Scalar leaves stay as Python objects; there is no
|
|
77
96
|
JSON encoding, deserialization, or conversion to Rust maps.
|
|
78
97
|
|
|
79
|
-
Run the Airspeed Velocity benchmarks against an equivalent Python implementation
|
|
98
|
+
Run the Airspeed Velocity benchmarks against an equivalent Python implementation
|
|
99
|
+
and [`mergedeep`](https://pypi.org/project/mergedeep/):
|
|
80
100
|
|
|
81
101
|
```sh
|
|
82
102
|
uv sync
|
|
@@ -85,7 +105,8 @@ uv run asv continuous --factor 1.15 --interleave-rounds --split HEAD^ HEAD
|
|
|
85
105
|
|
|
86
106
|
Benchmarks check matching results before timing and cover flat dictionaries,
|
|
87
107
|
nested configuration, deep dictionaries, large lists, and list concatenation.
|
|
88
|
-
|
|
108
|
+
Weave and the Python reference copy dict/list containers and share opaque leaves,
|
|
109
|
+
while `mergedeep` is benchmarked in non-mutating mode (`mergedeep.merge({}, left, right, ...)`). ASV
|
|
89
110
|
stores results in `.asv/results`; CI compares each pull request against its base
|
|
90
111
|
revision on the same runner and uploads the result files as a workflow artifact.
|
|
91
112
|
The 15% threshold filters small variations. Use release builds and measure your
|
|
@@ -93,3 +114,7 @@ own workload; Python allocation and key hashing still determine much of the cost
|
|
|
93
114
|
|
|
94
115
|
See [local benchmark results](benchmarks/README.md) for measured timings and
|
|
95
116
|
the machine and sampling conditions.
|
|
117
|
+
|
|
118
|
+
The merge-to-merge timing report is generated at
|
|
119
|
+
[`benchmarks/performance.html`](benchmarks/performance.html). Download the file
|
|
120
|
+
and open it in a browser to view the interactive charts.
|