-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathjustfile
More file actions
executable file
·2170 lines (1904 loc) · 83.4 KB
/
Copy pathjustfile
File metadata and controls
executable file
·2170 lines (1904 loc) · 83.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Copyright (c) typedef int GmbH, Germany, 2025. All rights reserved.
# -----------------------------------------------------------------------------
# -- just global configuration
# -----------------------------------------------------------------------------
set unstable := true
set positional-arguments := true
set script-interpreter := ['uv', 'run', '--script']
# uv env vars (see: https://docs.astral.sh/uv/reference/environment/)
# Project base directory
PROJECT_DIR := justfile_directory()
# Tell uv to use project-local cache directory
export UV_CACHE_DIR := './.uv-cache'
# Use this common single directory for all uv venvs
VENV_DIR := './.venvs'
# Define supported Python environments
ENVS := 'cpy314 cpy313 cpy312 cpy311 pypy311'
# Package version files, kept in sync (CalVer YY.M.PATCH[.devN], PEP 440).
PY_VERSION_FILE := 'src/zlmdb/_version.py'
TOML_VERSION_FILE := 'pyproject.toml'
# Default recipe: show project header and list all recipes
default:
#!/usr/bin/env bash
set -e
VERSION=$(grep '^version' pyproject.toml | head -1 | sed 's/.*= *"\(.*\)"/\1/')
GIT_REV=$(git rev-parse --short HEAD 2>/dev/null || echo "unknown")
echo ""
echo "==============================================================================="
echo " zLMDB "
echo ""
echo " Object-relational in-memory database layer based on LMDB "
echo ""
echo " Python Package: zlmdb "
echo " Python Package Version: ${VERSION} "
echo " Git Version: ${GIT_REV} "
echo " Protocol Specification: https://wamp-proto.org/ "
echo " Documentation: https://zlmdb.readthedocs.io "
echo " Package Releases: https://pypi.org/project/zlmdb/ "
echo " Nightly/Dev Releases: https://github.com/crossbario/zlmdb/releases "
echo " Source Code: https://github.com/crossbario/zlmdb "
echo " Copyright: typedef int GmbH (Germany/EU) "
echo " License: MIT License "
echo ""
echo " >>> Created by The WAMP/Autobahn/Crossbar.io OSS Project <<< "
echo "==============================================================================="
echo ""
just --list
echo ""
# Internal helper to map Python version short name to full uv version
_get-spec short_name:
#!/usr/bin/env bash
set -e
case {{short_name}} in
cpy314) echo "cpython-3.14";;
cpy314t) echo "cpython-3.14t";; # CPython 3.14 free-threaded (no-GIL); reserved for #124 Part 2
cpy313) echo "cpython-3.13";;
cpy312) echo "cpython-3.12";;
cpy311) echo "cpython-3.11";;
pypy311) echo "pypy-3.11";;
*) echo "Unknown environment: {{short_name}}" >&2; exit 1;;
esac
# Assert the venv interpreter's ABI (GIL vs free-threaded) matches the env name, so a wheel
# is never published with the wrong ABI tag -- e.g. a free-threaded cp314t wheel in the GIL
# cp314 slot, which shipped on aarch64 in 26.6.1 when an older uv resolved `cpython-3.14` to
# the free-threaded interpreter (zlmdb #124 / autobahn #1875). The wheel ABI tag is fixed by
# the building interpreter, so checking the interpreter catches the mismatch at build time.
_check-venv-abi venv:
#!/usr/bin/env bash
set -e
VENV_NAME="{{ venv }}"
VENV_PYTHON=$(just --quiet _get-venv-python "${VENV_NAME}")
case "${VENV_NAME}" in
pypy*) echo "==> ABI check skipped for '${VENV_NAME}' (PyPy)"; exit 0 ;;
*t) EXPECT_FT=1 ;; # e.g. cpy314t -> free-threaded (no-GIL)
*) EXPECT_FT=0 ;; # e.g. cpy314 -> GIL
esac
ACTUAL_FT=$(${VENV_PYTHON} -c "import sysconfig; print(1 if sysconfig.get_config_var('Py_GIL_DISABLED') else 0)")
if [ "${ACTUAL_FT}" != "${EXPECT_FT}" ]; then
echo "ERROR: interpreter ABI mismatch for '${VENV_NAME}': Py_GIL_DISABLED=${ACTUAL_FT}, expected free-threaded=${EXPECT_FT}." >&2
echo " Building would emit a wrong-ABI wheel (e.g. cp314t in the cp314 slot). Aborting." >&2
exit 1
fi
echo "==> ABI check OK: '${VENV_NAME}' interpreter free-threaded=${ACTUAL_FT} (expected ${EXPECT_FT})"
# Internal helper that calculates and prints the system-matching venv name
_get-system-venv-name:
#!/usr/bin/env bash
set -e
SYSTEM_VERSION=$(/usr/bin/python3 -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')")
ENV_NAME="cpy$(echo ${SYSTEM_VERSION} | tr -d '.')"
if ! echo "{{ ENVS }}" | grep -q -w "${ENV_NAME}"; then
echo "Error: System Python (${SYSTEM_VERSION}) maps to '${ENV_NAME}', which is not a supported environment." >&2
exit 1
fi
echo "${ENV_NAME}"
# Helper recipe to get the python executable path for a venv
_get-venv-python venv="":
#!/usr/bin/env bash
set -e
VENV_NAME="{{ venv }}"
if [ -z "${VENV_NAME}" ]; then
VENV_NAME=$(just --quiet _get-system-venv-name)
fi
VENV_PATH="{{PROJECT_DIR}}/.venvs/${VENV_NAME}"
if [[ "$OS" == "Windows_NT" ]]; then
echo "${VENV_PATH}/Scripts/python.exe"
else
echo "${VENV_PATH}/bin/python3"
fi
# -----------------------------------------------------------------------------
# -- General/global helper recipes
# -----------------------------------------------------------------------------
# Setup bash tab completion for the current user (to activate: `source ~/.config/bash_completion`).
setup-completion:
#!/usr/bin/env bash
set -e
COMPLETION_FILE="${XDG_CONFIG_HOME:-$HOME/.config}/bash_completion"
MARKER="# --- Just completion ---"
echo "==> Setting up bash tab completion for 'just'..."
if [ -f "${COMPLETION_FILE}" ] && grep -q "${MARKER}" "${COMPLETION_FILE}"; then
echo "--> 'just' completion is already configured."
exit 0
fi
echo "--> Configuration not found. Adding it now..."
mkdir -p "$(dirname "${COMPLETION_FILE}")"
echo "" >> "${COMPLETION_FILE}"
echo "${MARKER}" >> "${COMPLETION_FILE}"
just --completions bash >> "${COMPLETION_FILE}"
echo "--> Successfully added completion logic to ${COMPLETION_FILE}."
echo ""
echo "==> Setup complete. Please restart your shell or run:"
echo " source \"${COMPLETION_FILE}\""
# Remove ALL generated files, including venvs, caches, and build artifacts
distclean: clean-build clean-pyc clean-test
#!/usr/bin/env bash
set -e
echo "==> Performing a deep clean (distclean)..."
echo "--> Removing venvs, cache, and build/dist directories..."
rm -rf {{UV_CACHE_DIR}} {{VENV_DIR}} build/ dist/ .pytest_cache/ .ruff_cache/ .ty/
rm -rf docs/_build/
echo "--> Searching for and removing nested Python caches..."
find . -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true
echo "--> Searching for and removing compiled Python files..."
find . -type f -name "*.pyc" -delete 2>/dev/null || true
find . -type f -name "*.pyo" -delete 2>/dev/null || true
echo "--> Searching for and removing setuptools egg-info directories..."
find . -type d -name "*.egg-info" -exec rm -rf {} + 2>/dev/null || true
echo "--> Removing CFFI build artifacts..."
rm -f src/zlmdb/_lmdb_vendor/_lmdb_cffi.c src/zlmdb/_lmdb_vendor/_lmdb_cffi.o src/zlmdb/_lmdb_vendor/_lmdb_cffi*.so src/zlmdb/_lmdb_vendor/_lmdb_cffi*.pyd
echo "==> Distclean complete. The project is now pristine."
# -----------------------------------------------------------------------------
# -- Python virtual environments
# -----------------------------------------------------------------------------
# List all Python virtual environments
list-all:
#!/usr/bin/env bash
set -e
echo ""
echo "Available CPython run-times:"
echo "============================"
echo ""
uv python list --all-platforms cpython
echo ""
echo "Available PyPy run-times:"
echo "========================="
echo ""
uv python list --all-platforms pypy
echo ""
echo "Mapped Python run-time shortname => full version:"
echo "================================================="
echo ""
for env in {{ENVS}}; do
spec=$(just --quiet _get-spec "$env")
echo " - $env => $spec"
done
echo ""
echo "Create a Python venv using: just create <shortname>"
# Create a single Python virtual environment (usage: `just create cpy314` or `just create`)
create venv="":
#!/usr/bin/env bash
set -e
VENV_NAME="{{ venv }}"
if [ -z "${VENV_NAME}" ]; then
echo "==> No venv name specified. Auto-detecting from system Python..."
VENV_NAME=$(just --quiet _get-system-venv-name)
echo "==> Defaulting to venv: '${VENV_NAME}'"
fi
VENV_PATH="{{ VENV_DIR }}/${VENV_NAME}"
VENV_PYTHON=$(just --quiet _get-venv-python "${VENV_NAME}")
if [ ! -d "${VENV_PATH}" ]; then
PYTHON_SPEC=$(just --quiet _get-spec "${VENV_NAME}")
# For a GIL env, drop free-threaded CPython dirs (…t/bin, e.g. cp314t) that
# manylinux images pre-install on PATH ahead of the GIL build, so uv does not
# resolve e.g. cpy314 to a free-threaded cp314t interpreter (#124). The dedicated
# cpy314t env is used to build free-threaded wheels. No-op off manylinux.
CREATE_PATH="${PATH}"
if [[ "${VENV_NAME}" != *t ]]; then
CREATE_PATH="$(printf '%s' "${PATH}" | tr ':' '\n' | grep -vE '/opt/python/[^/]*t/bin$' | paste -sd: -)"
fi
echo "==> Creating Python virtual environment '${VENV_NAME}' using ${PYTHON_SPEC}..."
mkdir -p "{{ VENV_DIR }}"
PATH="${CREATE_PATH}" uv venv --seed --python "${PYTHON_SPEC}" "${VENV_PATH}"
echo "==> Successfully created venv '${VENV_NAME}'."
else
echo "==> Python virtual environment '${VENV_NAME}' already exists."
fi
${VENV_PYTHON} -V
${VENV_PYTHON} -m pip -V
echo "==> Activate with: source ${VENV_PATH}/bin/activate"
# Create all Python virtual environments
create-all:
#!/usr/bin/env bash
for venv in {{ENVS}}; do
just create ${venv}
done
# Get the version of a single virtual environment's Python
version venv="":
#!/usr/bin/env bash
set -e
VENV_NAME="{{ venv }}"
if [ -z "${VENV_NAME}" ]; then
VENV_NAME=$(just --quiet _get-system-venv-name)
fi
if [ -d "{{ VENV_DIR }}/${VENV_NAME}" ]; then
echo "==> Python virtual environment '${VENV_NAME}' exists:"
"{{VENV_DIR}}/${VENV_NAME}/bin/python" -V
else
echo "==> Python virtual environment '${VENV_NAME}' does not exist."
fi
# Get versions of all Python virtual environments
version-all:
#!/usr/bin/env bash
for venv in {{ENVS}}; do
just version ${venv}
done
# -----------------------------------------------------------------------------
# -- Package version management (CalVer YY.M.PATCH[.devN], PEP 440)
# -----------------------------------------------------------------------------
# Replicated from crossbar's version-management recipes to align the WAMP
# projects. Deviation: this repo does not track uv.lock, so (unlike crossbar)
# bump-next does not refresh or commit a lockfile.
# Display the current package version from both version files
file-version:
@echo "Python file: $(grep '__version__' {{PY_VERSION_FILE}} | cut -d ' ' -f 3)"
@echo "TOML file: $(grep '^version =' {{TOML_VERSION_FILE}} | cut -d ' ' -f 3)"
# Prepare for a stable release: strip the .devN suffix from the version files
prep-release:
@echo "Cleaning version for stable release..."
sed -i 's/\.dev[0-9]*//' {{PY_VERSION_FILE}}
sed -i 's/\.dev[0-9]*//' {{TOML_VERSION_FILE}}
@just file-version
@echo ''
@echo 'Now (maintainer, on the dev PC only -- tags are never created by AI):'
@echo ' 1. Commit: git add . && git commit -m "version bump for stable release"'
@echo ' 2. Tag: git tag -a v<VERSION> -m "tagged stable release"'
@echo ' 3. Push tag: git push upstream v<VERSION>'
@echo ' 4. Next dev: just bump-next <NEXT-VERSION>.dev1'
@echo ''
# Auto-bump to the next dev version for the current month (CalVer: YY.M.1.dev1)
bump-dev:
#!/usr/bin/env bash
set -e
NEXT="$(date +%-y).$(date +%-m).1.dev1"
echo "Auto-computed next dev version: ${NEXT}"
just bump-next "${NEXT}"
# Set a specific next version (e.g. `just bump-next 26.7.2.dev1`)
bump-next next_version:
@echo "Bumping version to {{next_version}}..."
sed -i 's/__version__ = .*/__version__ = "{{next_version}}"/' {{PY_VERSION_FILE}}
sed -i 's/^version = .*/version = "{{next_version}}"/' {{TOML_VERSION_FILE}}
git add {{PY_VERSION_FILE}} {{TOML_VERSION_FILE}}
git commit -m "chore: bump version to {{next_version}}"
@echo "Branch is now at {{next_version}} and ready for development."
# -----------------------------------------------------------------------------
# -- Installation
# -----------------------------------------------------------------------------
# Install zlmdb with runtime dependencies
install venv="": (create venv)
#!/usr/bin/env bash
set -e
VENV_NAME="{{ venv }}"
if [ -z "${VENV_NAME}" ]; then
VENV_NAME=$(just --quiet _get-system-venv-name)
fi
VENV_PYTHON=$(just --quiet _get-venv-python "${VENV_NAME}")
echo "==> Installing zlmdb in ${VENV_NAME}..."
${VENV_PYTHON} -m pip install .
# Install zlmdb in development (editable) mode
install-dev venv="": (create venv)
#!/usr/bin/env bash
set -e
VENV_NAME="{{ venv }}"
if [ -z "${VENV_NAME}" ]; then
VENV_NAME=$(just --quiet _get-system-venv-name)
fi
VENV_PYTHON=$(just --quiet _get-venv-python "${VENV_NAME}")
echo "==> Installing zlmdb in editable mode in ${VENV_NAME}..."
${VENV_PYTHON} -m pip install -e .
# Prepare LMDB sources for editable installs (build hooks don't run for -e)
if [ ! -d "build/lmdb-src" ]; then
echo "==> Preparing LMDB sources for editable install..."
${VENV_PYTHON} build_lmdb.py
fi
# Install with locally editable WAMP packages for cross-repo development (usage: `just install-dev-local cpy312`)
install-dev-local venv="": (create venv)
#!/usr/bin/env bash
set -e
VENV_NAME="{{ venv }}"
if [ -z "${VENV_NAME}" ]; then
VENV_NAME=$(just --quiet _get-system-venv-name)
fi
VENV_PYTHON=$(just --quiet _get-venv-python "${VENV_NAME}")
echo "==> Installing WAMP packages in editable mode from local repos..."
echo "==> Looking for sibling repos (../txaio, ../autobahn-python)..."
# Install local WAMP packages in editable mode
# txaio - no extras needed
if [ -d "../txaio" ]; then
echo " ✓ Installing txaio from ../txaio"
${VENV_PYTHON} -m pip install -e "../txaio"
else
echo " ⚠ Warning: ../txaio not found, skipping"
fi
# autobahn-python - install with twisted extra
if [ -d "../autobahn-python" ]; then
echo " ✓ Installing autobahn-python with [twisted] from ../autobahn-python"
${VENV_PYTHON} -m pip install -e "../autobahn-python[twisted]"
else
echo " ⚠ Warning: ../autobahn-python not found, skipping"
fi
echo "==> Installing zlmdb in editable mode with [dev] extras..."
${VENV_PYTHON} -m pip install -e .[dev] --upgrade --upgrade-strategy only-if-needed
# Prepare LMDB sources for editable installs
if [ ! -d "build/lmdb-src" ]; then
echo "==> Preparing LMDB sources for editable install..."
${VENV_PYTHON} build_lmdb.py
fi
# Install all environments
install-all:
#!/usr/bin/env bash
for venv in {{ENVS}}; do
just install ${venv}
done
# Meta-recipe to run `install-dev` on all environments
install-dev-all:
#!/usr/bin/env bash
for venv in {{ENVS}}; do
just install-dev ${venv}
done
# Upgrade dependencies in a single environment (usage: `just upgrade cpy314`)
upgrade venv="": (create venv)
#!/usr/bin/env bash
set -e
VENV_NAME="{{ venv }}"
if [ -z "${VENV_NAME}" ]; then
VENV_NAME=$(just --quiet _get-system-venv-name)
fi
VENV_PYTHON=$(just --quiet _get-venv-python "${VENV_NAME}")
echo "==> Upgrading dependencies in ${VENV_NAME}..."
${VENV_PYTHON} -m pip install --upgrade pip
${VENV_PYTHON} -m pip install --upgrade -e .[dev]
echo "==> Dependencies upgraded in ${VENV_NAME}."
# Meta-recipe to run `upgrade` on all environments
upgrade-all:
#!/usr/bin/env bash
set -e
for venv in {{ENVS}}; do
just upgrade ${venv}
done
# Install development tools (ruff, mypy, sphinx, etc.)
install-tools venv="": (create venv)
#!/usr/bin/env bash
set -e
VENV_NAME="{{ venv }}"
if [ -z "${VENV_NAME}" ]; then
VENV_NAME=$(just --quiet _get-system-venv-name)
fi
VENV_PYTHON=$(just --quiet _get-venv-python "${VENV_NAME}")
echo "==> Installing development tools in ${VENV_NAME}..."
${VENV_PYTHON} -m pip install -e .[dev]
# Meta-recipe to run `install-tools` on all environments
install-tools-all:
#!/usr/bin/env bash
set -e
for venv in {{ENVS}}; do
just install-tools ${venv}
done
# Install minimal build tools for building wheels
install-build-tools venv="": (create venv)
#!/usr/bin/env bash
set -e
VENV_NAME="{{ venv }}"
if [ -z "${VENV_NAME}" ]; then
VENV_NAME=$(just --quiet _get-system-venv-name)
fi
VENV_PYTHON=$(just --quiet _get-venv-python "${VENV_NAME}")
echo "==> Installing minimal build tools in ${VENV_NAME}..."
# setuptools is required by CFFI's extension build / ffi.verify() on Python >= 3.12
${VENV_PYTHON} -m pip install build wheel cffi setuptools auditwheel
# -----------------------------------------------------------------------------
# -- Testing
# -----------------------------------------------------------------------------
# Test namespace isolation (verify lmdb import behavior)
test-import venv="": (install venv)
#!/usr/bin/env bash
set -e
VENV_NAME="{{ venv }}"
if [ -z "${VENV_NAME}" ]; then
VENV_NAME=$(just --quiet _get-system-venv-name)
fi
VENV_PYTHON=$(just --quiet _get-venv-python "${VENV_NAME}")
echo "==> Testing namespace isolation in ${VENV_NAME}..."
echo ""
# Test 1: 'import lmdb' should FAIL
echo "Test 1: Verifying 'import lmdb' raises ModuleNotFoundError..."
if ${VENV_PYTHON} -c "import lmdb" 2>/dev/null; then
echo " ❌ FAIL: 'import lmdb' succeeded (should have failed)"
exit 1
else
echo " ✓ PASS: 'import lmdb' correctly raises ModuleNotFoundError"
fi
echo ""
# Test 2: 'import zlmdb.lmdb as lmdb' should SUCCEED
echo "Test 2: Verifying 'import zlmdb.lmdb as lmdb' works..."
if ${VENV_PYTHON} -c "import zlmdb.lmdb as lmdb; print(' Version:', lmdb.version())" 2>&1; then
echo " ✓ PASS: 'import zlmdb.lmdb as lmdb' works"
else
echo " ❌ FAIL: 'import zlmdb.lmdb as lmdb' failed"
exit 1
fi
echo ""
# Test 3: 'from zlmdb import lmdb' should SUCCEED
echo "Test 3: Verifying 'from zlmdb import lmdb' works..."
if ${VENV_PYTHON} -c "from zlmdb import lmdb; print(' Version:', lmdb.version())" 2>&1; then
echo " ✓ PASS: 'from zlmdb import lmdb' works"
else
echo " ❌ FAIL: 'from zlmdb import lmdb' failed"
exit 1
fi
echo ""
# Test 4: Check version attributes
echo "Test 4: Verifying version attributes..."
${VENV_PYTHON} -c "import zlmdb; print(' zlmdb.__version__:', zlmdb.__version__)"
# LMDB 0.9.33 Release (2024/05/21)
#
# - Development happens on mdb.master (version 0.9.70).
# - Releases are backported/committed to mdb.RE/0.9.
# - Tagging happens on mdb.RE/0.9.
#
# Thus we want to track the tip of the mdb.RE/0.9 branch.
#
# See:
# - https://github.com/LMDB/lmdb/blob/mdb.RE/0.9/libraries/liblmdb/CHANGES
# - https://github.com/LMDB/lmdb/blob/mdb.master/libraries/liblmdb/lmdb.h
# - https://github.com/LMDB/lmdb/commit/3a29a24777c82a0165de813ae696a5068b5add30
#
# MDB_VERSION_MAJOR 0 // Library major version
# MDB_VERSION_MINOR 9 // Library minor version
# MDB_VERSION_PATCH 33 // Library patch version
# Test 4b: Verify zlmdb.lmdb does NOT have __version__
echo ""
echo "Test 4b: Verifying zlmdb.lmdb has NO __version__ (only zlmdb has version)..."
if ${VENV_PYTHON} -c "import zlmdb.lmdb as lmdb; lmdb.__version__" 2>/dev/null; then
echo " ❌ FAIL: zlmdb.lmdb.__version__ exists (should not exist)"
exit 1
else
echo " ✓ PASS: zlmdb.lmdb has no __version__ attribute (correct)"
fi
echo ""
echo "Test 5: Verifying zlmdb.lmdb.version()..."
${VENV_PYTHON} -c "import zlmdb; print(f' zlmdb.lmdb.version(): {zlmdb.lmdb.version()}')"
echo ""
# For a production or stable project (like zlmdb), the recommended approach is to strictly
# use and track the Latest Named Tag, not Development:
#
# cd deps/flatbuffers && git checkout $(git describe --tags --abbrev=0) && git describe --tags
echo "Test 6: Verifying zlmdb.flatbuffers.__version__..."
${VENV_PYTHON} -c "import zlmdb; print(f' zlmdb.flatbuffers.__version__: {zlmdb.flatbuffers.__version__}')"
echo ""
echo "Test 7: Verifying zlmdb.flatbuffers._git_version__..."
${VENV_PYTHON} -c "import zlmdb; print(f' zlmdb.flatbuffers.__git_version__: {zlmdb.flatbuffers.__git_version__}')"
echo ""
echo "Test 8: Verifying zlmdb.flatbuffers.version()..."
${VENV_PYTHON} -c "import zlmdb; print(f' zlmdb.flatbuffers.version(): {zlmdb.flatbuffers.version()}')"
echo ""
echo "========================================================================"
echo "✅ ALL NAMESPACE ISOLATION TESTS PASSED"
echo "========================================================================"
# Test flatbuffers reflection imports (verifies vendored reflection module works)
# This is the test that cfxdb, wamp-xbr, and crossbar depend on - they use Schema.GetRootAs()
# to load .bfbs files for dynamic FlatBuffers access.
# See: https://github.com/crossbario/zlmdb/issues/102
test-reflection venv="": (install venv)
#!/usr/bin/env bash
set -e
VENV_NAME="{{ venv }}"
if [ -z "${VENV_NAME}" ]; then
VENV_NAME=$(just --quiet _get-system-venv-name)
fi
VENV_PYTHON=$(just --quiet _get-venv-python "${VENV_NAME}")
echo "==> Testing flatbuffers reflection imports in ${VENV_NAME}..."
echo ""
# Run the reflection test script
${VENV_PYTHON} "{{ PROJECT_DIR }}/scripts/test_reflection.py"
echo ""
echo "========================================================================"
echo "✅ ALL REFLECTION IMPORT TESTS PASSED"
echo "========================================================================"
# Test bundled flatc compiler (verifies flatc binary is bundled and works)
test-bundled-flatc venv="": (install venv)
#!/usr/bin/env bash
set -e
VENV_NAME="{{ venv }}"
if [ -z "${VENV_NAME}" ]; then
VENV_NAME=$(just --quiet _get-system-venv-name)
fi
VENV_PATH="{{ VENV_DIR }}/${VENV_NAME}"
VENV_PYTHON=$(just --quiet _get-venv-python "${VENV_NAME}")
echo "==> Testing bundled flatc compiler in ${VENV_NAME}..."
echo ""
# Test 1: flatc console script works
echo "Test 1: Verifying 'flatc --version' works via console script..."
FLATC_VERSION=$("${VENV_PATH}/bin/flatc" --version 2>&1)
if [ $? -eq 0 ]; then
echo " ✓ PASS: flatc console script works"
echo " Version: ${FLATC_VERSION}"
else
echo " ❌ FAIL: flatc console script failed"
exit 1
fi
echo ""
# Test 2: Python API get_flatc_path() works
echo "Test 2: Verifying zlmdb._flatc.get_flatc_path() works..."
FLATC_PATH=$(${VENV_PYTHON} -c "from zlmdb._flatc import get_flatc_path; print(get_flatc_path())")
if [ -x "${FLATC_PATH}" ]; then
echo " ✓ PASS: get_flatc_path() returns executable path"
echo " Path: ${FLATC_PATH}"
else
echo " ❌ FAIL: get_flatc_path() returned non-executable: ${FLATC_PATH}"
exit 1
fi
echo ""
# Test 3: Python API run_flatc() works
echo "Test 3: Verifying zlmdb._flatc.run_flatc() works..."
RET=$(${VENV_PYTHON} -c "from zlmdb._flatc import run_flatc; exit(run_flatc(['--version']))")
if [ $? -eq 0 ]; then
echo " ✓ PASS: run_flatc(['--version']) works"
else
echo " ❌ FAIL: run_flatc() failed"
exit 1
fi
echo ""
# Test 4: reflection.fbs is accessible
echo "Test 4: Verifying reflection.fbs is accessible at runtime..."
FBS_PATH=$(${VENV_PYTHON} -c 'import zlmdb.flatbuffers; from pathlib import Path; p = Path(zlmdb.flatbuffers.__file__).parent / "reflection.fbs"; print(p) if p.exists() else exit(1)')
if [ $? -eq 0 ]; then
FBS_SIZE=$(stat -c%s "${FBS_PATH}" 2>/dev/null || stat -f%z "${FBS_PATH}")
echo " ✓ PASS: reflection.fbs found at ${FBS_PATH}"
echo " Size: ${FBS_SIZE} bytes"
else
echo " ❌ FAIL: reflection.fbs not found"
exit 1
fi
echo ""
# Test 5: reflection.bfbs is accessible
echo "Test 5: Verifying reflection.bfbs is accessible at runtime..."
BFBS_PATH=$(${VENV_PYTHON} -c 'import zlmdb.flatbuffers; from pathlib import Path; p = Path(zlmdb.flatbuffers.__file__).parent / "reflection.bfbs"; print(p) if p.exists() else exit(1)')
if [ $? -eq 0 ]; then
BFBS_SIZE=$(stat -c%s "${BFBS_PATH}" 2>/dev/null || stat -f%z "${BFBS_PATH}")
echo " ✓ PASS: reflection.bfbs found at ${BFBS_PATH}"
echo " Size: ${BFBS_SIZE} bytes"
else
echo " ❌ FAIL: reflection.bfbs not found"
exit 1
fi
echo ""
echo "========================================================================"
echo "✅ ALL BUNDLED FLATC TESTS PASSED"
echo "========================================================================"
# -----------------------------------------------------------------------------
# -- Artifact Verification (smoke tests for built wheels and sdist)
# -----------------------------------------------------------------------------
# Run smoke tests on an installed zlmdb package (verifies LMDB + FlatBuffers work)
# This is used by test-wheel-install and test-sdist-install after installation
test-smoke venv="":
#!/usr/bin/env bash
set -e
VENV_NAME="{{ venv }}"
if [ -z "${VENV_NAME}" ]; then
VENV_NAME=$(just --quiet _get-system-venv-name)
fi
VENV_PYTHON=$(just --quiet _get-venv-python "${VENV_NAME}")
VENV_PATH="{{ VENV_DIR }}/${VENV_NAME}"
echo "Running smoke tests with Python: $(${VENV_PYTHON} --version)"
echo "Venv: ${VENV_PATH}"
echo ""
# Run the smoke test Python script
${VENV_PYTHON} "{{ PROJECT_DIR }}/scripts/smoke_test.py"
# Test installing and verifying a built wheel (used in CI for artifact verification)
# Usage: just test-wheel-install /path/to/zlmdb-*.whl
test-wheel-install wheel_path:
#!/usr/bin/env bash
set -e
WHEEL_PATH="{{ wheel_path }}"
if [ ! -f "${WHEEL_PATH}" ]; then
echo "ERROR: Wheel file not found: ${WHEEL_PATH}"
exit 1
fi
WHEEL_NAME=$(basename "${WHEEL_PATH}")
echo "========================================================================"
echo " WHEEL INSTALL TEST"
echo "========================================================================"
echo ""
echo "Wheel: ${WHEEL_NAME}"
echo ""
# Create ephemeral venv name based on wheel
EPHEMERAL_VENV="smoke-wheel-$$"
EPHEMERAL_PATH="{{ VENV_DIR }}/${EPHEMERAL_VENV}"
# Extract Python version from wheel filename
# Wheel format: {name}-{version}-{python tag}-{abi tag}-{platform tag}.whl
# Python tag examples: cp312, cp311, pp311, py3
PYTAG=$(echo "${WHEEL_NAME}" | sed -n 's/.*-\(cp[0-9]*\|pp[0-9]*\|py[0-9]*\)-.*/\1/p')
if [[ "${PYTAG}" =~ ^cp([0-9])([0-9]+)$ ]]; then
# CPython wheel (e.g., cp312 -> 3.12)
MAJOR="${BASH_REMATCH[1]}"
MINOR="${BASH_REMATCH[2]}"
PYTHON_SPEC="cpython-${MAJOR}.${MINOR}"
echo "Detected CPython ${MAJOR}.${MINOR} wheel"
elif [[ "${PYTAG}" =~ ^pp([0-9])([0-9]+)$ ]]; then
# PyPy wheel (e.g., pp311 -> pypy-3.11)
MAJOR="${BASH_REMATCH[1]}"
MINOR="${BASH_REMATCH[2]}"
PYTHON_SPEC="pypy-${MAJOR}.${MINOR}"
echo "Detected PyPy ${MAJOR}.${MINOR} wheel"
elif [[ "${PYTAG}" =~ ^py([0-9])$ ]]; then
# Pure Python wheel (e.g., py3) - use system Python
SYSTEM_VERSION=$(python3 -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')")
PYTHON_SPEC="cpython-${SYSTEM_VERSION}"
echo "Pure Python wheel, using system Python ${SYSTEM_VERSION}"
else
# Fallback to system Python
SYSTEM_VERSION=$(python3 -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')")
PYTHON_SPEC="cpython-${SYSTEM_VERSION}"
echo "Could not detect Python version from wheel, using system Python ${SYSTEM_VERSION}"
fi
echo "Creating ephemeral venv with ${PYTHON_SPEC}..."
mkdir -p "{{ VENV_DIR }}"
uv venv --seed --python "${PYTHON_SPEC}" "${EPHEMERAL_PATH}"
EPHEMERAL_PYTHON="${EPHEMERAL_PATH}/bin/python3"
# Install the wheel
echo ""
echo "Installing wheel..."
${EPHEMERAL_PYTHON} -m pip install "${WHEEL_PATH}"
# Run smoke tests
echo ""
VENV_DIR="{{ VENV_DIR }}" just test-smoke "${EPHEMERAL_VENV}"
# Cleanup
echo ""
echo "Cleaning up ephemeral venv..."
rm -rf "${EPHEMERAL_PATH}"
echo ""
echo "========================================================================"
echo "✅ WHEEL INSTALL TEST PASSED: ${WHEEL_NAME}"
echo "========================================================================"
# Test installing and verifying a source distribution (used in CI for artifact verification)
# Usage: just test-sdist-install /path/to/zlmdb-*.tar.gz
test-sdist-install sdist_path:
#!/usr/bin/env bash
set -e
SDIST_PATH="{{ sdist_path }}"
if [ ! -f "${SDIST_PATH}" ]; then
echo "ERROR: Source distribution not found: ${SDIST_PATH}"
exit 1
fi
SDIST_NAME=$(basename "${SDIST_PATH}")
echo "========================================================================"
echo " SOURCE DISTRIBUTION INSTALL TEST"
echo "========================================================================"
echo ""
echo "Source dist: ${SDIST_NAME}"
echo ""
# Check if cmake is available (required for full functionality)
if command -v cmake >/dev/null 2>&1; then
echo "cmake: $(cmake --version | head -1)"
else
echo "WARNING: cmake not found - flatc binary will not be built"
echo " Install cmake for full functionality"
fi
echo ""
# Create ephemeral venv name
EPHEMERAL_VENV="smoke-sdist-$$"
EPHEMERAL_PATH="{{ VENV_DIR }}/${EPHEMERAL_VENV}"
echo "Creating ephemeral venv: ${EPHEMERAL_VENV}..."
# Detect system Python version and create venv
SYSTEM_VERSION=$(python3 -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')")
ENV_NAME="cpy$(echo ${SYSTEM_VERSION} | tr -d '.')"
PYTHON_SPEC="cpython-${SYSTEM_VERSION}"
mkdir -p "{{ VENV_DIR }}"
uv venv --seed --python "${PYTHON_SPEC}" "${EPHEMERAL_PATH}"
EPHEMERAL_PYTHON="${EPHEMERAL_PATH}/bin/python3"
# Install build dependencies (required for --no-build-isolation)
# CFFI is needed for LMDB extension, hatchling for the build system
# Use --no-cache-dir consistently to ensure fresh installs
echo ""
echo "Installing build dependencies..."
${EPHEMERAL_PYTHON} -m pip install --no-cache-dir cffi setuptools wheel hatchling
# Install from source distribution (this will compile LMDB CFFI extension)
# Use --no-build-isolation to allow access to system cmake for building flatc
# Use --no-cache-dir to disable HTTP download cache
# Use --no-binary zlmdb to force building from source (disable wheel cache)
# Note: flatc may not build if cmake is missing or grpc submodule isn't present
echo ""
echo "Installing from source distribution (includes CFFI compilation)..."
${EPHEMERAL_PYTHON} -m pip install --no-build-isolation --no-cache-dir --no-binary zlmdb "${SDIST_PATH}"
# Run smoke tests
echo ""
VENV_DIR="{{ VENV_DIR }}" just test-smoke "${EPHEMERAL_VENV}"
# Cleanup
echo ""
echo "Cleaning up ephemeral venv..."
rm -rf "${EPHEMERAL_PATH}"
echo ""
echo "========================================================================"
echo "✅ SOURCE DISTRIBUTION INSTALL TEST PASSED: ${SDIST_NAME}"
echo "========================================================================"
# Test all LMDB examples
test-examples-lmdb venv="": (test-examples-lmdb-addressbook venv) (test-examples-lmdb-dirtybench-gdbm venv) (test-examples-lmdb-dirtybench venv) (test-examples-lmdb-nastybench venv) (test-examples-lmdb-parabench venv)
# Test example LMDB address book
test-examples-lmdb-addressbook venv="": (install venv)
#!/usr/bin/env bash
set -e
VENV_NAME="{{ venv }}"
if [ -z "${VENV_NAME}" ]; then
VENV_NAME=$(just --quiet _get-system-venv-name)
fi
VENV_PYTHON=$(just --quiet _get-venv-python "${VENV_NAME}")
echo ""
echo "==> Testing in ${VENV_NAME} ..."
echo ""
${VENV_PYTHON} examples/lmdb/address-book.py
# Test example LMDB dirtybench-gdbm
test-examples-lmdb-dirtybench-gdbm venv="": (install venv)
#!/usr/bin/env bash
set -e
VENV_NAME="{{ venv }}"
if [ -z "${VENV_NAME}" ]; then
VENV_NAME=$(just --quiet _get-system-venv-name)
fi
VENV_PYTHON=$(just --quiet _get-venv-python "${VENV_NAME}")
echo ""
echo "==> Testing in ${VENV_NAME} ..."
echo ""
${VENV_PYTHON} examples/lmdb/dirtybench-gdbm.py
# Test example LMDB dirtybench (comprehensive benchmark, takes ~3-5 minutes)
test-examples-lmdb-dirtybench venv="": (install venv)
#!/usr/bin/env bash
set -e
VENV_NAME="{{ venv }}"
if [ -z "${VENV_NAME}" ]; then
VENV_NAME=$(just --quiet _get-system-venv-name)
fi
VENV_PYTHON=$(just --quiet _get-venv-python "${VENV_NAME}")
echo ""
echo "==> Testing in ${VENV_NAME} ..."
echo ""
# This benchmark takes ~3 minutes on fast hardware, allow 5 minutes for CI
timeout 300 ${VENV_PYTHON} examples/lmdb/dirtybench.py
# Test example LMDB nastybench
test-examples-lmdb-nastybench venv="": (install venv)
#!/usr/bin/env bash
set -e
VENV_NAME="{{ venv }}"
if [ -z "${VENV_NAME}" ]; then
VENV_NAME=$(just --quiet _get-system-venv-name)
fi
VENV_PYTHON=$(just --quiet _get-venv-python "${VENV_NAME}")
echo ""
echo "==> Testing in ${VENV_NAME} ..."
echo ""
timeout 60 ${VENV_PYTHON} examples/lmdb/nastybench.py
# Test example LMDB parabench (parallel benchmark, generates 4M keys then runs benchmark)
test-examples-lmdb-parabench venv="": (install venv)
#!/usr/bin/env bash
set -e
VENV_NAME="{{ venv }}"
if [ -z "${VENV_NAME}" ]; then
VENV_NAME=$(just --quiet _get-system-venv-name)
fi
VENV_PYTHON=$(just --quiet _get-venv-python "${VENV_NAME}")
echo ""
echo "==> Testing in ${VENV_NAME} ..."
echo ""
# Run with 2 processes for 10 seconds
# Key generation takes ~15-20 seconds, benchmark runs for 10 seconds
# Allow 90 seconds total for CI
timeout 90 ${VENV_PYTHON} examples/lmdb/parabench.py 2 10
# Run test suite for ORM.
test-orm venv="": (install-tools venv) (install-dev venv)
#!/usr/bin/env bash
set -e
VENV_NAME="{{ venv }}"
if [ -z "${VENV_NAME}" ]; then
VENV_NAME=$(just --quiet _get-system-venv-name)
fi
VENV_PYTHON=$(just --quiet _get-venv-python "${VENV_NAME}")
echo "==> Running test suite in ${VENV_NAME}..."
QUICK=1 ${VENV_PYTHON} -m pytest --log-cli-level=INFO -v src/zlmdb/tests/orm/
# Run LMDB low-level API tests
test-lmdb venv="": (install-tools venv) (install-dev venv)
#!/usr/bin/env bash
set -e
VENV_NAME="{{ venv }}"
if [ -z "${VENV_NAME}" ]; then
VENV_NAME=$(just --quiet _get-system-venv-name)
fi
VENV_PYTHON=$(just --quiet _get-venv-python "${VENV_NAME}")
echo "==> Running LMDB tests in ${VENV_NAME}..."
${VENV_PYTHON} -m pytest -v src/zlmdb/tests/lmdb/
# Run the test suite (both zlmdb/tests and tests directories)
test venv="": (install-tools venv) (install-dev venv)
#!/usr/bin/env bash
set -e
VENV_NAME="{{ venv }}"
if [ -z "${VENV_NAME}" ]; then
VENV_NAME=$(just --quiet _get-system-venv-name)
fi
VENV_PYTHON=$(just --quiet _get-venv-python "${VENV_NAME}")
echo "==> Running test suite in ${VENV_NAME}..."
${VENV_PYTHON} -m pytest -v src/zlmdb/tests/
# Run tests in all environments
test-all:
#!/usr/bin/env bash
for venv in {{ENVS}}; do
just test ${venv}
done
# -----------------------------------------------------------------------------
# -- Building
# -----------------------------------------------------------------------------
# Build wheel package
build venv="": (install-build-tools venv)
#!/usr/bin/env bash
set -e
VENV_NAME="{{ venv }}"
if [ -z "${VENV_NAME}" ]; then
VENV_NAME=$(just --quiet _get-system-venv-name)
fi
VENV_PYTHON=$(just --quiet _get-venv-python "${VENV_NAME}")
VENV_PATH="{{ VENV_DIR }}/${VENV_NAME}"
# Fail fast if the interpreter ABI doesn't match the env (zlmdb #124 / autobahn #1875):
# prevents publishing e.g. a free-threaded cp314t wheel in the GIL cp314 slot.
just _check-venv-abi "${VENV_NAME}"
echo "==> Building wheel package with ${VENV_NAME}..."
mkdir -p dist/
# Build the wheel
${VENV_PYTHON} -m build --wheel
# Convert linux wheels to manylinux format using auditwheel
if [ -x "${VENV_PATH}/bin/auditwheel" ]; then
for wheel in dist/*-linux_*.whl; do
if [ -f "$wheel" ]; then
echo "==> Converting $(basename $wheel) to manylinux format..."
"${VENV_PATH}/bin/auditwheel" show "$wheel"
"${VENV_PATH}/bin/auditwheel" repair "$wheel" -w dist/
# Remove the original linux wheel after successful repair
rm "$wheel"
fi
done
else
echo "WARNING: auditwheel not available, skipping manylinux conversion"
fi
ls -lh dist/
# Build source distribution
build-sourcedist venv="": (install-build-tools venv)
#!/usr/bin/env bash
set -e
VENV_NAME="{{ venv }}"
if [ -z "${VENV_NAME}" ]; then
VENV_NAME=$(just --quiet _get-system-venv-name)
fi
VENV_PYTHON=$(just --quiet _get-venv-python "${VENV_NAME}")
echo "==> Building source distribution with ${VENV_NAME}..."
# CRITICAL: Initialize all submodules recursively BEFORE building sdist
# Hatchling uses `git ls-files` to determine what goes into the sdist,
# and nested submodules (like deps/flatbuffers/grpc/) must be initialized
# for their files to be visible to git and thus included in the sdist.
echo "==> Initializing git submodules (recursive)..."