-
Notifications
You must be signed in to change notification settings - Fork 769
Expand file tree
/
Copy pathjustfile
More file actions
2842 lines (2469 loc) · 111 KB
/
justfile
File metadata and controls
2842 lines (2469 loc) · 111 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.
#
# IMPORTANT:
# Ubuntu: sudo apt install gir1.2-girepository-2.0-dev
# Debian: https://pkgs.org/search/?q=girepository
# -----------------------------------------------------------------------------
# -- 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 = directory of this justfile
PROJECT_DIR := justfile_directory()
# 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 " Autobahn|Python "
echo ""
echo " WebSocket & WAMP for Python on Twisted and asyncio "
echo ""
echo " Python Package: autobahn "
echo " Python Package Version: ${VERSION} "
echo " Git Version: ${GIT_REV} "
echo " Protocol Specification: https://wamp-proto.org/ "
echo " Documentation: https://autobahn.readthedocs.io "
echo " Package Releases: https://pypi.org/project/autobahn/ "
echo " Nightly/Dev Releases: https://github.com/crossbario/autobahn-python/releases"
echo " Source Code: https://github.com/crossbario/autobahn-python "
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 ""
# Tell uv to always copy files instead of trying to hardlink them.
# set export UV_LINK_MODE := 'copy'
# Tell uv to use project-local cache directory.
export UV_CACHE_DIR := './.uv-cache'
# Autobahn|Testsuite (https://github.com/crossbario/autobahn-testsuite) Docker image to use.
AUTOBAHN_TESTSUITE_IMAGE := 'crossbario/autobahn-testsuite:25.10.1'
# Default output directory for Autobahn|Testsuite reports (HTML files).
AUTOBAHN_TESTSUITE_OUTPUT_DIR := justfile_directory() / '.wstest'
# Default config directory for Autobahn|Testsuite configuration (JSON files).
AUTOBAHN_TESTSUITE_CONFIG_DIR := justfile_directory() / 'wstest'
# Use this common single directory for all uv venvs.
# Use absolute path (based on PROJECT_DIR) to avoid issues when cd'ing in recipes
VENV_DIR := PROJECT_DIR / '.venvs'
# Define a justfile-local variable for our environments.
ENVS := 'cpy314 cpy313 cpy312 cpy311 pypy311'
# 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";; # cpython-3.14.0b3-linux-x86_64-gnu
cpy313) echo "cpython-3.13";; # cpython-3.13.5-linux-x86_64-gnu
cpy312) echo "cpython-3.12";; # cpython-3.12.11-linux-x86_64-gnu
cpy311) echo "cpython-3.11";; # cpython-3.11.13-linux-x86_64-gnu
pypy311) echo "pypy-3.11";; # pypy-3.11.11-linux-x86_64-gnu
*) echo "Unknown environment: {{short_name}}" >&2; exit 1;;
esac
# uv python install pypy-3.11-linux-aarch64-gnu --preview --verbose
# file /home/oberstet/.local/share/uv/python/pypy-3.11.11-linux-aarch64-gnu/bin/pypy3.11
# /home/oberstet/.local/share/uv/python/pypy-3.11.11-linux-aarch64-gnu/bin/pypy3.11: ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-aarch64.so.1, BuildID[sha1]=150f642a07dc36d3e465beaa0109e70da76ca67e, for GNU/Linux 3.7.0, stripped
# 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 in this project." >&2
exit 1
fi
# The only output of this recipe is the name itself.
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="{{VENV_DIR}}/${VENV_NAME}"
# In your main recipes, replace direct calls to python with:
# VENV_PYTHON=$(just --quiet _get-venv-python "${VENV_NAME}")
# ${VENV_PYTHON} -V
# ${VENV_PYTHON} -m pip -V
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'..."
# Check if we have already configured it.
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..."
# 1. Ensure the directory exists.
mkdir -p "$(dirname "${COMPLETION_FILE}")"
# 2. Add our marker comment to the file.
echo "" >> "${COMPLETION_FILE}"
echo "${MARKER}" >> "${COMPLETION_FILE}"
# 3. CRITICAL: Run `just` and append its raw output directly to the file.
# No `echo`, no `eval`, no quoting hell. Just run and redirect.
just --completions bash >> "${COMPLETION_FILE}"
echo "--> Successfully added completion logic to ${COMPLETION_FILE}."
echo ""
echo "==> Setup complete. Please restart your shell or run the following command:"
echo " source \"${COMPLETION_FILE}\""
# Remove ALL generated files, including venvs, caches, and build artifacts. WARNING: This is a destructive operation.
distclean:
#!/usr/bin/env bash
set -e
echo "==> Performing a deep clean (distclean)..."
# 1. Remove top-level directories known to us.
# This is fast for the common cases.
echo "--> Removing venvs, cache, and build/dist directories..."
rm -rf {{UV_CACHE_DIR}} {{VENV_DIR}} build/ dist/ wheelhouse/ .pytest_cache/ .ruff_cache/ .ty/
rm -rf .wstest docs/_build/
rm -f ./*.so
rm -f ./.coverage.*
rm -rf ./_trial_temp
# 2. Use `find` to hunt down and destroy nested artifacts that can be
# scattered throughout the source tree. This is the most thorough part.
echo "--> Searching for and removing nested Python caches..."
find . -type d -name "__pycache__" -exec rm -rf {} +
echo "--> Searching for and removing compiled Python files..."
find . -type f -name "*.pyc" -delete
find . -type f -name "*.pyo" -delete
echo "--> Searching for and removing setuptools egg-info directories..."
find . -type d -name "*.egg-info" -exec rm -rf {} +
echo "--> Searching for and removing coverage data..."
rm -f .coverage
find . -type f -name ".coverage.*" -delete
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
# This shell loop correctly uses a SHELL variable ($env), not a just variable.
for env in {{ENVS}}; do
# We call our helper recipe to get the spec for the current env.
# The `--quiet` flag is important to only capture the `echo` output.
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 }}"
# This is the "default parameter" logic.
# If VENV_NAME is empty (because `just create` was run), calculate the default.
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}")
# Only create the venv if it doesn't already exist
if [ ! -d "${VENV_PATH}" ]; then
# Get the Python spec just-in-time
PYTHON_SPEC=$(just --quiet _get-spec "${VENV_NAME}")
echo "==> Creating Python virtual environment '${VENV_NAME}' using ${PYTHON_SPEC} in ${VENV_PATH}..."
mkdir -p "{{ VENV_DIR }}"
uv venv --seed --python "${PYTHON_SPEC}" "${VENV_PATH}"
echo "==> Successfully created venv '${VENV_NAME}'."
else
echo "==> Python virtual environment '${VENV_NAME}' already exists in ${VENV_PATH}."
fi
${VENV_PYTHON} -V
${VENV_PYTHON} -m pip -V
echo "==> Activate Python virtual environment with: source ${VENV_PATH}/bin/activate"
# Meta-recipe to run `create` on all 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 (usage: `just version cpy314`)
version venv="":
#!/usr/bin/env bash
set -e
VENV_NAME="{{ venv }}"
# This is the "default parameter" logic.
# If VENV_NAME is empty (because `just create` was run), calculate the default.
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
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
echo ""
# Get versions of all Python virtual environments
version-all:
#!/usr/bin/env bash
for venv in {{ENVS}}; do
just version ${venv}
done
# Make Python packages installed by the OS package manager available in a managed venv. Usage: `just link-system-packages "" "/usr/lib/kicad-nightly/lib/python3/dist-packages"`
link-system-packages venv="" vendors="": (create venv)
#!/usr/bin/env bash
set -euo pipefail
VENV_NAME="{{ venv }}"
VENDOR_PATHS="{{ vendors }}"
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}"
if [ ! -d "${VENV_PATH}" ] || [ ! -f "${VENV_PATH}/bin/python" ]; then
echo "✗ Error: Virtual environment '${VENV_NAME}' not found at '${VENV_PATH}'." >&2
exit 1
fi
echo "✓ Found virtual environment: ${VENV_PATH}"
SYSTEM_PYTHON="/usr/bin/python3"
SYSTEM_VERSION=$(${SYSTEM_PYTHON} -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')")
# Collect all relevant site-packages directories (Debian + Ubuntu quirks)
SYSTEM_SITE_PACKAGES=$(${SYSTEM_PYTHON} -c "import sysconfig, site, os, sys; paths={sysconfig.get_path('purelib')}; [paths.add(p) for p in site.getsitepackages() if os.path.isdir(p)]; print('\n'.join(sorted(paths)))")
VENV_PYTHON=$(just --quiet _get-venv-python "${VENV_NAME}")
VENV_VERSION=$(${VENV_PYTHON} -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')")
VENV_SITE_PACKAGES=$(${VENV_PYTHON} -c "import sysconfig; print(sysconfig.get_path('purelib'))")
echo " - System Python ${SYSTEM_VERSION} site-packages: ${SYSTEM_SITE_PACKAGES}"
echo " - Venv Python ${VENV_VERSION} site-packages: ${VENV_SITE_PACKAGES}"
if [ "${VENV_VERSION}" != "${SYSTEM_VERSION}" ]; then
echo "✗ Error: Python version mismatch!" >&2
echo " System is ${SYSTEM_VERSION}, but venv is ${VENV_VERSION}." >&2
echo " Cannot link system packages due to risk of binary incompatibility." >&2
# exit 1
fi
echo "✓ Python versions match."
PTH_FILE="${VENV_SITE_PACKAGES}/__system_packages.pth"
echo "==> Writing link file: ${PTH_FILE}"
{
# system paths (multi-line safe)
while IFS= read -r sp; do
if [ -d "$sp" ]; then
echo "$sp"
else
echo "⚠ Warning: system path not found: $sp" >&2
fi
done <<< "${SYSTEM_SITE_PACKAGES}"
# vendor paths (comma/space separated)
if [ -n "${VENDOR_PATHS}" ]; then
IFS=', ' read -ra VENDOR_ARRAY <<< "${VENDOR_PATHS}"
for vp in "${VENDOR_ARRAY[@]}"; do
if [ -d "${vp}" ]; then
echo "${vp}"
else
echo "⚠ Warning: vendor path not found: ${vp}" >&2
fi
done
fi
} > "${PTH_FILE}"
echo "✓ Done."
echo
echo "Linked paths in $(basename "${PTH_FILE}"):"
echo
cat "${PTH_FILE}"
echo
# -----------------------------------------------------------------------------
# -- Installation and Test
# -----------------------------------------------------------------------------
# Install this package and its run-time dependencies in a single environment (usage: `just install cpy314` or `just install`)
install venv="": (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}")
echo "==> Installing package with package runtime dependencies in ${VENV_NAME}..."
# uv pip install --python "{{VENV_DIR}}/${VENV_NAME}/bin/python" .[all]
${VENV_PYTHON} -m pip install .[all]
# Install this package in development (editable) mode and its run-time dependencies in a single environment (usage: `just install-dev cpy314` or `just install-dev`)
install-dev venv="": (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}")
echo "==> Installing package - in editable mode - with package runtime dependencies in ${VENV_NAME}..."
# uv pip install --python "{{VENV_DIR}}/${VENV_NAME}/bin/python" -e .[all]
${VENV_PYTHON} -m pip install -e .[all]
# 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
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}")
echo "==> Installing WAMP packages in editable mode from local repos..."
echo "==> Looking for sibling repos (../txaio)..."
# 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
echo "==> Installing autobahn in editable mode with [all,dev] extras..."
${VENV_PYTHON} -m pip install -e .[all,dev] --upgrade --upgrade-strategy only-if-needed
# Build NVX (Native Vector Extensions) CFFI modules for development/editable installs
# This is needed because hatchling's build hook only compiles during wheel builds.
# For editable installs in CI or local development, we need to compile manually.
#
# The .so files are placed in src/ (not src/autobahn/nvx/) because:
# - CFFI names the modules as top-level modules (e.g., "_nvx_utf8validator")
# - Python imports look for top-level modules in sys.path roots
# - For editable installs, src/ is on sys.path, so .so files there are importable
#
# (usage: `just build-nvx cpy314` or with explicit NVX: `AUTOBAHN_USE_NVX=1 just build-nvx cpy314`)
build-nvx venv="": (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}")
echo "==> Building NVX CFFI extension modules in ${VENV_NAME}..."
# Ensure cffi is available
${VENV_PYTHON} -m pip install "cffi>=2.0.0" --quiet
# Build modules in src/ directory (for editable install sys.path compatibility)
# The CFFI ffi.compile() writes output to current directory
# VENV_DIR and PROJECT_DIR are absolute paths, so VENV_PATH is absolute too
SRC_DIR="{{ PROJECT_DIR }}/src"
NVX_DIR="{{ PROJECT_DIR }}/src/autobahn/nvx"
echo " Building _nvx_utf8validator..."
(cd "${SRC_DIR}" && ${VENV_PYTHON} "${NVX_DIR}/_utf8validator.py")
echo " Building _nvx_xormasker..."
(cd "${SRC_DIR}" && ${VENV_PYTHON} "${NVX_DIR}/_xormasker.py")
# List built artifacts
echo "==> Built NVX artifacts:"
ls -la "${SRC_DIR}"/_nvx_*.so 2>/dev/null || echo " (no .so files found - check for errors above)"
echo "==> NVX build complete for ${VENV_NAME}."
# Meta-recipe to run `install` on all environments
install-all:
#!/usr/bin/env bash
set -e
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
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_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 .[all,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
# -----------------------------------------------------------------------------
# -- Installation: Tools (Ruff, Sphinx, etc)
# -----------------------------------------------------------------------------
# Install minimal build tools for building wheels (usage: `just install-build-tools cpy314`)
# This is lighter than install-tools as it excludes dependencies like twine
# (which depends on nh3, a Rust package that segfaults under QEMU ARM64 emulation)
install-build-tools venv="": (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}")
echo "==> Installing minimal build tools in ${VENV_NAME}..."
${VENV_PYTHON} -V
${VENV_PYTHON} -m pip -V
${VENV_PYTHON} -m pip install -e .[build-tools]
# Install the development tools for this Package in a single environment (usage: `just install-tools cpy314`)
# This also builds NVX CFFI modules so that tests with AUTOBAHN_USE_NVX=1 work.
install-tools venv="": (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}")
echo "==> Installing package development tools in ${VENV_NAME}..."
${VENV_PYTHON} -V
${VENV_PYTHON} -m pip -V
# uv pip install --python "{{VENV_DIR}}/${VENV_NAME}/bin/python" -e .[dev]
${VENV_PYTHON} -m pip install -e .[dev]
# Build NVX CFFI modules for editable installs (needed for tests with AUTOBAHN_USE_NVX=1)
just build-nvx ${VENV_NAME}
# 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 benchmark dependencies (Python 3.11+ only - vmprof requires binary wheels)
install-benchmark venv="": (create venv) (install 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}")
# Check Python version is 3.11+
PY_VERSION=$(${VENV_PYTHON} -c "import sys; print(f'{sys.version_info.major}.{sys.version_info.minor}')")
PY_MAJOR=$(echo ${PY_VERSION} | cut -d. -f1)
PY_MINOR=$(echo ${PY_VERSION} | cut -d. -f2)
if [ "${PY_MAJOR}" -lt 3 ] || ([ "${PY_MAJOR}" -eq 3 ] && [ "${PY_MINOR}" -lt 11 ]); then
echo "❌ ERROR: Benchmarking requires Python 3.11+ (vmprof binary wheels)"
echo " Current venv '${VENV_NAME}' has Python ${PY_VERSION}"
echo ""
echo "Supported venvs for benchmarking:"
echo " - cpy311 (CPython 3.11)"
echo " - cpy312 (CPython 3.12)"
echo " - cpy313 (CPython 3.13)"
echo " - cpy314 (CPython 3.14)"
echo " - pypy311 (PyPy 3.11)"
exit 1
fi
echo "==> Installing benchmark dependencies in ${VENV_NAME} (Python ${PY_VERSION})..."
${VENV_PYTHON} -V
${VENV_PYTHON} -m pip -V
${VENV_PYTHON} -m pip install -e .[benchmark]
# Install Rust (rustc & cargo) from upstream via rustup.
install-rust:
#!/usr/bin/env bash
set -e
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
. "$HOME/.cargo/env"
which rustc
rustc --version
which cargo
cargo --version
# Install Autobahn WebSocket Testsuite (Docker image).
install-wstest:
#!/usr/bin/env bash
set -e
sudo docker pull {{AUTOBAHN_TESTSUITE_IMAGE}}
# -----------------------------------------------------------------------------
# -- Linting, Static Typechecking, .. the codebase
# -----------------------------------------------------------------------------
# Automatically fix all formatting and code style issues.
fix-format venv="": (install-tools 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}"
echo "==> Automatically formatting code with ${VENV_NAME}..."
# 1. Run the FORMATTER first. This will handle line lengths, quotes, etc.
# Uses exclude list from pyproject.toml (includes autobahn/wamp/gen/*, tests, etc.)
"${VENV_PATH}/bin/ruff" format .
# 2. Run the LINTER'S FIXER second. This will handle things like
# removing unused imports, sorting __all__, etc.
# Uses exclude list from pyproject.toml (includes autobahn/wamp/gen/*, tests, etc.)
"${VENV_PATH}/bin/ruff" check --fix .
echo "--> Formatting complete."
# Alias for fix-format (backward compatibility)
autoformat venv="": (fix-format venv)
# Lint code using Ruff in a single environment
check-format venv="": (install-tools 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}"
echo "==> Linting code with ${VENV_NAME}..."
"${VENV_PATH}/bin/ruff" check .
# Run static type checking with ty (Astral's Rust-based type checker)
# FIXME: Many type errors need to be fixed. For now, we ignore most rules
# to get CI passing. Create follow-up issue to address type errors.
check-typing venv="": (install 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}"
echo "==> Running static type checks with ty (using ${VENV_NAME} for type stubs)..."
# Note: Only check src/autobahn/, not src/flatbuffers/ (generated code)
# FIXME: Many ignores needed until type annotations are fixed
ty check \
--python "${VENV_PATH}/bin/python" \
--ignore unresolved-import \
--ignore unresolved-attribute \
--ignore unresolved-reference \
--ignore possibly-missing-attribute \
--ignore call-non-callable \
--ignore invalid-assignment \
--ignore invalid-argument-type \
--ignore invalid-method-override \
--ignore invalid-type-form \
--ignore unsupported-operator \
--ignore too-many-positional-arguments \
--ignore unknown-argument \
--ignore not-subscriptable \
--ignore not-iterable \
--ignore no-matching-overload \
--ignore conflicting-declarations \
--ignore deprecated \
src/autobahn/
# Run coverage for Twisted tests only
check-coverage-twisted venv="" use_nvx="": (install-tools venv) (install-dev 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}")
# Handle NVX configuration
USE_NVX="{{ use_nvx }}"
if [ "${USE_NVX}" = "1" ]; then
export AUTOBAHN_USE_NVX=1
echo "==> Running Twisted tests with coverage in ${VENV_NAME} (WITH NVX)..."
elif [ "${USE_NVX}" = "0" ]; then
export AUTOBAHN_USE_NVX=0
echo "==> Running Twisted tests with coverage in ${VENV_NAME} (WITHOUT NVX)..."
else
echo "==> Running Twisted tests with coverage in ${VENV_NAME} (AUTO NVX)..."
fi
# Clean previous coverage data
rm -f .coverage .coverage.*
# Run Twisted tests with coverage
USE_TWISTED=1 "${VENV_PATH}/bin/coverage" run \
--source=autobahn \
--parallel-mode \
-m twisted.trial --no-recurse \
autobahn.test \
autobahn.twisted.test \
autobahn.websocket.test \
autobahn.rawsocket.test \
autobahn.wamp.test \
autobahn.nvx.test
# Run coverage for asyncio tests only
check-coverage-asyncio venv="" use_nvx="": (install-tools venv) (install-dev 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}"
# Handle NVX configuration
USE_NVX="{{ use_nvx }}"
if [ "${USE_NVX}" = "1" ]; then
export AUTOBAHN_USE_NVX=1
echo "==> Running asyncio tests with coverage in ${VENV_NAME} (WITH NVX)..."
elif [ "${USE_NVX}" = "0" ]; then
export AUTOBAHN_USE_NVX=0
echo "==> Running asyncio tests with coverage in ${VENV_NAME} (WITHOUT NVX)..."
else
echo "==> Running asyncio tests with coverage in ${VENV_NAME} (AUTO NVX)..."
fi
# Run asyncio tests with coverage (parallel mode to combine later)
USE_ASYNCIO=1 "${VENV_PATH}/bin/coverage" run \
--source=src/autobahn \
--parallel-mode \
-m pytest -s -v -rfP \
--ignore=./src/autobahn/twisted ./src/autobahn
# Combined coverage report from both Twisted and asyncio tests
check-coverage-combined venv="" use_nvx="": (check-coverage-twisted venv use_nvx) (check-coverage-asyncio venv use_nvx)
#!/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}"
# Determine NVX suffix for report naming
USE_NVX="{{ use_nvx }}"
if [ "${USE_NVX}" = "1" ]; then
NVX_SUFFIX="-with-nvx"
echo "==> Combining coverage data from Twisted and asyncio tests (WITH NVX)..."
elif [ "${USE_NVX}" = "0" ]; then
NVX_SUFFIX="-without-nvx"
echo "==> Combining coverage data from Twisted and asyncio tests (WITHOUT NVX)..."
else
NVX_SUFFIX=""
echo "==> Combining coverage data from Twisted and asyncio tests (AUTO NVX)..."
fi
# Combine all coverage data files
"${VENV_PATH}/bin/coverage" combine
# Generate reports with NVX-specific naming
mkdir -p docs/_build/html
"${VENV_PATH}/bin/coverage" html -d docs/_build/html/coverage-combined${NVX_SUFFIX}
"${VENV_PATH}/bin/coverage" report --show-missing
echo ""
echo "✅ Combined coverage report generated:"
echo " HTML: docs/_build/html/coverage-combined${NVX_SUFFIX}/index.html"
echo " Text: above summary"
# Legacy coverage recipe (DEPRECATED - use check-coverage-combined instead)
check-coverage venv="" use_nvx="": (install-tools venv) (install-dev venv)
#!/usr/bin/env bash
set -e
echo "⚠️ DEPRECATED: Use 'just check-coverage-combined' for comprehensive coverage"
echo "⚠️ This recipe only runs pytest coverage and misses Twisted-specific code paths"
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}"
# Handle NVX configuration
USE_NVX="{{ use_nvx }}"
if [ "${USE_NVX}" = "1" ]; then
export AUTOBAHN_USE_NVX=1
NVX_SUFFIX="-with-nvx"
echo "==> Running tests with coverage with ${VENV_NAME} (WITH NVX)..."
elif [ "${USE_NVX}" = "0" ]; then
export AUTOBAHN_USE_NVX=0
NVX_SUFFIX="-without-nvx"
echo "==> Running tests with coverage with ${VENV_NAME} (WITHOUT NVX)..."
else
NVX_SUFFIX=""
echo "==> Running tests with coverage with ${VENV_NAME} (AUTO NVX)..."
fi
mkdir -p docs/_build/html
# for now, ignore any non-zero exit code by prefixing with hyphen (FIXME: remove later)
"${VENV_PATH}/bin/pytest" \
--cov=autobahn \
--cov-report=html:docs/_build/html/coverage${NVX_SUFFIX}
echo "--> Coverage report generated in docs/_build/html/coverage${NVX_SUFFIX}/index.html"
# Verify all WebSocket compression methods are available (usage: `just check-compressors cpy314 "permessage-deflate, permessage-brotli"`)
check-compressors venv="" expect="permessage-brotli,permessage-bzip2,permessage-deflate,permessage-snappy": (install 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}"
EXPECT_LIST="{{ expect }}"
echo "==> Checking WebSocket compression methods in ${VENV_NAME}..."
TMP_SCRIPT="/tmp/check_compressors_$$.py"
{
echo "import sys"
echo "from autobahn.websocket.compress import PERMESSAGE_COMPRESSION_EXTENSION"
echo ""
echo "available = sorted(PERMESSAGE_COMPRESSION_EXTENSION.keys())"
echo ""
echo "print('Available WebSocket Compression Methods:')"
echo "print('=' * 70)"
echo "for ext_name in available:"
echo " ext_classes = PERMESSAGE_COMPRESSION_EXTENSION[ext_name]"
echo " pmce_class = ext_classes.get('PMCE')"
echo " if pmce_class:"
echo " class_ref = f\"{pmce_class.__module__}.{pmce_class.__name__}\""
echo " print(f' {ext_name:25s} -> {class_ref}')"
echo " else:"
echo " print(f' {ext_name:25s} -> (no PMCE class found)')"
echo "print('=' * 70)"
echo "print(f'Total: {len(available)} compression methods available')"
echo ""
echo "# Output list for bash validation"
echo "print('ACTUAL_LIST:' + ','.join(available))"
} > "${TMP_SCRIPT}"
OUTPUT=$("${VENV_PATH}/bin/python" "${TMP_SCRIPT}")
rm "${TMP_SCRIPT}"
echo "${OUTPUT}" | grep -v "^ACTUAL_LIST:"
if [ -n "${EXPECT_LIST}" ]; then
echo ""
echo "==> Validating against expected list..."
ACTUAL=$(echo "${OUTPUT}" | grep "^ACTUAL_LIST:" | cut -d: -f2)
# Convert comma-separated strings to sorted arrays
IFS=',' read -ra EXPECTED_ARRAY <<< "${EXPECT_LIST}"
IFS=',' read -ra ACTUAL_ARRAY <<< "${ACTUAL}"
# Trim whitespace and sort
EXPECTED_SORTED=($(for item in "${EXPECTED_ARRAY[@]}"; do echo "${item}" | xargs; done | sort))
ACTUAL_SORTED=($(for item in "${ACTUAL_ARRAY[@]}"; do echo "${item}" | xargs; done | sort))
# Compare arrays
if [ "${EXPECTED_SORTED[*]}" != "${ACTUAL_SORTED[*]}" ]; then
echo "❌ ERROR: Compression methods mismatch!"
echo ""
echo "Expected: ${EXPECTED_SORTED[*]}"
echo "Actual: ${ACTUAL_SORTED[*]}"
echo ""
# Show differences
echo "Missing: $(comm -23 <(printf '%s\n' "${EXPECTED_SORTED[@]}") <(printf '%s\n' "${ACTUAL_SORTED[@]}") | tr '\n' ' ')"
echo "Extra: $(comm -13 <(printf '%s\n' "${EXPECTED_SORTED[@]}") <(printf '%s\n' "${ACTUAL_SORTED[@]}") | tr '\n' ' ')"
exit 1
else
echo "✅ Compression methods match expected list (${EXPECTED_SORTED[*]})"
fi
else
echo "✅ Compression methods check completed"
fi
# Verify all WAMP serializers are available (usage: `just check-serializers cpy314 "json, msgpack, cbor, ubjson, flatbuffers"`)
check-serializers venv="" expect="cbor,flatbuffers,json,msgpack,ubjson": (install 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}"
EXPECT_LIST="{{ expect }}"
echo "==> Checking WAMP serializers in ${VENV_NAME}..."
TMP_SCRIPT="/tmp/check_serializers_$$.py"
{
echo "import sys"
echo "from autobahn.wamp.serializer import SERID_TO_OBJSER"
echo ""
echo "available = sorted(SERID_TO_OBJSER.keys())"
echo ""
echo "print('Available WAMP Serializers:')"
echo "print('=' * 70)"
echo "for ser_name in available:"
echo " ser_class = SERID_TO_OBJSER[ser_name]"
echo " class_ref = f\"{ser_class.__module__}.{ser_class.__name__}\""
echo " print(f' {ser_name:25s} -> {class_ref}')"
echo "print('=' * 70)"
echo "print(f'Total: {len(available)} serializers available')"
echo ""
echo "# Output list for bash validation"
echo "print('ACTUAL_LIST:' + ','.join(available))"
} > "${TMP_SCRIPT}"
OUTPUT=$("${VENV_PATH}/bin/python" "${TMP_SCRIPT}")
rm "${TMP_SCRIPT}"
echo "${OUTPUT}" | grep -v "^ACTUAL_LIST:"
if [ -n "${EXPECT_LIST}" ]; then
echo ""
echo "==> Validating against expected list..."
ACTUAL=$(echo "${OUTPUT}" | grep "^ACTUAL_LIST:" | cut -d: -f2)
# Convert comma-separated strings to sorted arrays
IFS=',' read -ra EXPECTED_ARRAY <<< "${EXPECT_LIST}"
IFS=',' read -ra ACTUAL_ARRAY <<< "${ACTUAL}"
# Trim whitespace and sort
EXPECTED_SORTED=($(for item in "${EXPECTED_ARRAY[@]}"; do echo "${item}" | xargs; done | sort))
ACTUAL_SORTED=($(for item in "${ACTUAL_ARRAY[@]}"; do echo "${item}" | xargs; done | sort))
# Compare arrays
if [ "${EXPECTED_SORTED[*]}" != "${ACTUAL_SORTED[*]}" ]; then
echo "❌ ERROR: WAMP serializers mismatch!"
echo ""
echo "Expected: ${EXPECTED_SORTED[*]}"
echo "Actual: ${ACTUAL_SORTED[*]}"
echo ""
# Show differences
echo "Missing: $(comm -23 <(printf '%s\n' "${EXPECTED_SORTED[@]}") <(printf '%s\n' "${ACTUAL_SORTED[@]}") | tr '\n' ' ')"
echo "Extra: $(comm -13 <(printf '%s\n' "${EXPECTED_SORTED[@]}") <(printf '%s\n' "${ACTUAL_SORTED[@]}") | tr '\n' ' ')"
exit 1
else
echo "✅ WAMP serializers match expected list (${EXPECTED_SORTED[*]})"