-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmise.toml
More file actions
929 lines (863 loc) · 32.8 KB
/
mise.toml
File metadata and controls
929 lines (863 loc) · 32.8 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
# SPDX-FileCopyrightText: 2025 Knitli Inc.
# SPDX-FileContributor: Adam Poulemanos <adam@knit.li>
#
# SPDX-License-Identifier: MIT OR Apache-2.0
#:tombi schema.strict = false
experimental_monorepo_root = true
[monorepo]
config_roots = ["./", "./docs-site", "./packages/*"]
[env]
MISE_EXPERIMENTAL = "1"
GH_REPO = "knitli/codeweaver"
REMOTE_ORIGIN_URL = '''http://github.com/knitli/codeweaver.git'''
PROJECT_NAME = "codeweaver"
# defaults to false -- override in a local mise.local.toml if you want to use GPU dependencies (recommended if hardware supports it)
CODEWEAVER__DEV__USE_GPU = '''{{ get_env(name="CODEWEAVER__DEV__USE_GPU", default="false") }}'''
# According to the mise docs, config_root should always be the project root. Even if the mise.toml is in a subdirectory.
# But that didn't seem to be the case, so we manually trim known suffixes.
CODEWEAVER_PROJECT_PATH = '''{{ config_root | trim | trim_end_matches(pat="/") | trim_end_matches(pat="/mise") | trim_end_matches(pat="/.config") }}'''
# Get version from git tags (uv-dynamic-versioning uses git as source)
# Falls back to "dev" if git command fails
CODEWEAVER_VERSION = '''{{ exec(command='git describe --tags --always --dirty 2>/dev/null || echo "dev"') | trim }}'''
CI = '''{% if get_env(name="GITHUB_ACTIONS", default="") != "" %}true{% else %}false{% endif %}'''
_.path = [
"bin",
"scripts/dev-env",
"scripts/code-quality",
"scripts/build",
"scripts/language-support",
"scripts/testing",
"scripts/utils",
".venv/bin",
]
MISE_ENV = '''{% if get_env(name="CI", default="") == "true" %}""{% else %}dev{% endif %}'''
CW_PREFIX = '''{% if get_env(name="CI", default="") == "true" %}[codeweaver]{% elif get_env(name="TERM", default="xterm-256color") == "*truecolor*" %}\033[38;2;181;108;48;m[codeweaver]\033[0m{% else %}\033[38;5;131m[codeweaver]\033[0m{% endif %}'''
# this is a bit redundant but it makes it easier to override in CI environments
# For the life of me, I can't get mise to use free-threaded python, so we strip the 't' and in CI use 'uv' directly based on `PYTHON_VERSION`
MISE_PYTHON_VERSION = '''{{ get_env(name="MISE_PYTHON_VERSION", default="3.13") | lower | trim_end_matches(pat="t") }}'''
PYTHON_VERSION = '''{{ get_env(name="MISE_PYTHON_VERSION", default="3.13") }}'''
HK_MISE = "1"
[shell_alias]
mx = "mise x"
mr = "mise r"
start-serena = '''uvx -p 3.13 --from git+https://github.com/oraios/serena serena start-mcp-server --project {{ get_env(name="CODEWEAVER_PROJECT_PATH", default=exec(command="pwd")) }} --transport streamable-http --port 9121 --host 127.0.0.1'''
[settings]
idiomatic_version_file_enable_tools = []
experimental = true
[settings.python]
[tools]
ast-grep = "latest"
"pipx:ipython" = "latest"
# most tools are defined in mise.dev.toml to keep CI workflows lightweight
# Where needed, tools are defined at the task level here, which allows for more granular control
python = '''{{ get_env(name="MISE_PYTHON_VERSION", default="3.13") }}'''
uv = "latest"
"pipx:exportify" = "latest"
hk = "latest"
pkl = "0.31.1"
# Quick note for those unfamiliar with mise:
# - despite the namespace, tools prefixed with "pipx:" are installed via "uv" (I assume once upon a time they were installed with pipx before uv came along)
# - some tools have no prefix -- these are defined in mise's internal registry directly
# - The prefix refers to the "backend" used to install the tool -- most of the no-prefix tools are installed through `aqua` or github/gitlab releases, and failing that, `ubi`. Language-specific package managers (cargo/npm/go) are also used where appropriate.
[tasks.info]
description = "Print project information"
run = '''
echo "running info task"
echo "${CW_PREFIX} Project: $PROJECT_NAME"
echo "${CW_PREFIX} Virtual Environment: $VIRTUAL_ENV"
echo "${CW_PREFIX} Python Version: $(python --version 2>&1)"
echo "${CW_PREFIX} CodeWeaver Version: $CODEWEAVER_VERSION"
echo "${CW_PREFIX} Project Path: $CODEWEAVER_PROJECT_PATH"
'''
run_windows = '''
echo "running info task"
echo [codeweaver] Project: %PROJECT_NAME%
echo [codeweaver] Virtual Environment: %VIRTUAL_ENV%
echo [codeweaver] Python Version: %PYTHON_VERSION%
echo [codeweaver] CodeWeaver Version: %CODEWEAVER_VERSION%
echo [codeweaver] Project Path: %CODEWEAVER_PROJECT_PATH%
'''
[tasks._special-dependencies]
hide = true
tools.uv = "latest"
run = '''
if [ "$MISE_PYTHON_VERSION" = "3.13" ] || [ "$MISE_PYTHON_VERSION" = "3.14" ]; then
GIL_STATUS="$(uv run python -c 'import sys; print(sys._is_gil_enabled())')"
# If the gil is enabled we can install a couple extras
if [ "$GIL_STATUS" = "True" ]; then
case "$MISE_PYTHON_VERSION" in
3.13)
uv pip install 'pydantic-settings[yaml,toml,aws-secrets-manager,gcp-secret-manager,azure-key-vault]'
;;
3.14)
uv pip install ddgs
;;
esac
fi
fi
'''
[tasks.sync]
depends = ["source"]
tools.uv = "latest"
run = '''
echo "running sync task"
if [ "$CODEWEAVER__DEV__USE_GPU" = "true" ]; then
echo "${CW_PREFIX} GPU support enabled. Syncing GPU dependencies..."
mise //:sync-gpu
else
echo "${CW_PREFIX} Syncing CPU dependencies..."
uv sync --python {{ get_env(name='PYTHON_VERSION', default='3.13') }} --extra full --group dev --group docs --group build --group test
fi
mise //:_special-dependencies
'''
run_windows = '''
echo "running sync task"
if "%CODEWEAVER__DEV__USE_GPU%"=="true" (
echo [codeweaver] GPU support enabled. Syncing GPU dependencies...
mise //:sync-gpu
) else (
echo [codeweaver] Syncing dependencies...
uv sync --python {{ get_env(name='PYTHON_VERSION', default='3.13') }} --extra full --group dev --group docs --group build --group test
)
mise //:_special-dependencies
'''
[tasks.sync-gpu]
depends = ["source"]
tools.uv = "latest"
run = '''
echo "running sync-gpu task"
echo "${CW_PREFIX} Syncing GPU dependencies..."
uv sync --python {{ get_env(name='PYTHON_VERSION', default='3.13') }} --extra full-gpu --group dev --group docs --group build --group test
mise //:_special-dependencies
'''
run_windows = '''
echo "running sync-gpu task"
echo [codeweaver] Syncing GPU dependencies...
uv sync --python {{ get_env(name='PYTHON_VERSION', default='3.13') }} --extra full-gpu --group dev --group docs --group build --group test
mise //:_special-dependencies
'''
[tasks.sync-gpu.env]
# if you explicitly run the sync-gpu task, we assume you want GPU dependencies regardless of the CODEWEAVER__DEV__USE_GPU setting
CODEWEAVER__DEV__USE_GPU = "true"
[tasks.source]
run = '''
echo "running source task"
# Source the virtual environment
echo "${CW_PREFIX} Sourcing virtual environment..."
git rev-parse --show-toplevel || true
if [ ! -d ".venv" ]; then
echo "${CW_PREFIX} ⚠️ \033[0;31mVirtual environment not found. We'll try to proceed, but things may break!\033[0m"
uv venv --seed --keyring-provider subprocess --python {{ get_env(name='PYTHON_VERSION', default='3.13') }} .venv
fi
. .venv/bin/activate || echo "${CW_PREFIX} ⚠️ \033[0;31mFailed to source virtual environment.\033[0m"
'''
run_windows = '''
echo "running source task"
echo [codeweaver] Sourcing virtual environment...
git rev-parse --show-toplevel
.venv\Scripts\activate.bat
'''
[tasks.setup]
# Development setup
run = [
"echo \"running setup task\"",
"echo \"${CW_PREFIX} Setting up development environment for the first time...\"",
"mise set &>/dev/null",
"mise trust --all &>/dev/null",
"mise install &>/dev/null || echo \"${CW_PREFIX} ⚠️ WARNING: mise install failed during setup.\"",
"mise //:venv &>/dev/null",
"git config include.path .gitconfig &>/dev/null || true",
"echo 'src/codeweaver/_version.py' >> .git/info/exclude",
"echo 'coverage.xml' >> .git/info/exclude",
"echo 'test-results.xml' >> .git/info/exclude",
"ln -sf AGENTS.md CLAUDE.md",
"ln -sf AGENTS.md GEMINI.md",
"eval \"$(mise activate \"$ACTIVE_SHELL\")\" &>/dev/null",
]
run_windows = [
"echo [codeweaver] Running setup task",
"echo [codeweaver] Setting up development environment for the first time...",
"mise set > NUL 2>&1",
"mise trust --all > NUL 2>&1",
"mise install > NUL 2>&1 || echo \"[codeweaver] WARNING: mise install failed during setup.\"",
"mise //:venv > NUL 2>&1",
"git config include.path .gitconfig > NUL 2>&1",
"echo src/codeweaver/_version.py >> .git\\info\\exclude",
"echo coverage.xml >> .git\\info\\exclude",
"echo test-results.xml >> .git\\info\\exclude",
"mklink CLAUDE.md AGENTS.md > NUL 2>&1",
"mklink GEMINI.md AGENTS.md > NUL 2>&1",
"mise activate cmd",
]
silent = "stdout"
[tasks.setup.env]
MISE_EXPERIMENTAL = "1"
MISE_ENV = "dev"
MISE_YES = "1"
ACTIVE_SHELL = '''{{ exec(command='basename "$SHELL" 2>/dev/null || echo zsh') }}'''
[tasks.setup.tools]
uv = "latest"
[tasks.cloud-setup]
run = [
"echo \"running cloud-setup task\"",
"echo \"[codeweaver] Setting up cloud development environment...\"",
"ln -sf AGENTS.md CLAUDE.md",
"ln -sf AGENTS.md GEMINI.md",
'''if ! command -v mise &>/dev/null; then
if [ -d "$HOME/.local/share/mise" ] || [ -d "$HOME/.mise" ] || [ -f "$HOME/.local/bin/mise" ]; then
export PATH="$HOME/.local/bin:$HOME/.mise/bin:$HOME/.local/share/mise/bin:$PATH"
if ! grep -q "mise activate" "$HOME/.bashrc"; then
echo "eval \"$(mise activate \"${ACTIVE_SHELL:-bash}\")\" 2>&1 || true" >> "$HOME/.bashrc"
fi
else
chmod +x scripts/dev-env/install-mise.sh 2>&1 || true
./scripts/dev-env/install-mise.sh 2>&1 || true
fi
fi''',
"mise -y trust --all 2>&1 || true",
"mise install 2>&1 || true",
"hk install --mise 2>&1 || mise x hk@latest -- hk install --mise 2>&1 || true",
"mise x uv@latest -- uv venv --allow-existing --seed --keyring-provider subprocess --python {{ get_env(name='PYTHON_VERSION', default='3.13') }} .venv 2>&1",
"source .venv/bin/activate 2>&1 || true",
"mise x uv@latest -- uv sync --group dev --group test 2>&1",
"git config include.path .gitconfig 2>&1 || true",
'''
ignore_files=('src/codeweaver/_version.py' 'coverage.xml' 'test-results.xml')
for file in "${ignore_files[@]}"; do
if ! grep -qx "$file" .git/info/exclude; then
echo "$file" >> .git/info/exclude 2>&1
fi
done
''',
"echo \"[codeweaver] Cloud development environment setup complete!\"",
]
[tasks.cloud-setup.env]
ACTIVE_SHELL = '''{{ exec(command='basename "$SHELL" 2>/dev/null || echo bash') }}'''
MISE_EXPERIMENTAL = "1"
MISE_ENV = "dev"
MISE_YES = "1"
[tasks.fix-python]
tools.uv = "latest"
usage = '''
arg "[dir]" help="directory to fix (default: current directory)" default="."
'''
run = [
"echo \"running fix-python task\"",
"uvx ruff format \"${usage_dir}\"",
"uvx ruff check --fix \"${usage_dir}\"",
]
run_windows = [
"echo \"running fix-python task\"",
"uvx ruff format \"%usage_dir%\"",
"uvx ruff check --fix \"%usage_dir%\""
]
sources = ["{src,scripts,tests,mise-tasks}/**/*.py"]
[tasks.fix-python-unsafe]
description = "Fix Python code with unsafe fixes and pattern transformations (may make unintended changes)"
tools.uv = "latest"
tools.ast-grep = "latest"
usage = '''
arg "[dir]" help="directory to fix (default: current directory)" default="."
'''
run = [
"echo \"running fix-python-unsafe task\"",
"echo \"⚠️ WARNING: This task applies aggressive transformations. Review changes carefully!\"",
"uvx ruff format \"${usage_dir}\"",
"uvx ruff check --fix --unsafe-fixes \"${usage_dir}\"",
"bash scripts/code-quality/fix-ruff-patterns.sh \"${usage_dir}\"",
]
run_windows = [
"echo \"running fix-python-unsafe task\"",
"echo \"WARNING: This task applies aggressive transformations. Review changes carefully!\"",
"uvx ruff format \"%usage_dir%\"",
"uvx ruff check --fix --unsafe-fixes \"%usage_dir%\"",
"bash scripts/code-quality/fix-ruff-patterns.sh \"%usage_dir%\""
]
sources = ["{src,scripts,tests,mise-tasks}/**/*.py"]
[tasks.check]
tools.hk = "latest"
tools.pkl = "latest"
tools."pipx:exportify" = "latest"
tools."pipx:ty" = "latest"
tools."pipx:reuse" = "latest"
tools.ruff = "latest"
run = '''
echo "running check task"
echo "${CW_PREFIX} Running quality checks..."
hk check
'''
run_windows = '''
echo "running check task"
echo [codeweaver] Running quality checks...
hk check
'''
[tasks.lint]
tools.uv = "latest"
usage = '''
arg "[dir]" help="directory to lint" default="."
flag "-f --format <format>" {
help "Output format"
choices "concise" "full" "json" "junit" "github" "gitlab" "pylint" "grouped"
default "full"
}
flag "--fix" help="Apply auto-fixes"
'''
run = '''
echo "running lint task"
echo "${CW_PREFIX} Running linting checks..."
# Determine output format (CI overrides)
OUTPUT_FORMAT="${usage_format}"
if [ "$CI" = "true" ] && [ "${usage_format}" = "full" ]; then
OUTPUT_FORMAT="github"
fi
# Build ruff command
RUFF_CMD="uv run ruff check \"${usage_dir}\" --output-format=${OUTPUT_FORMAT}"
if [ "${usage_fix}" = "true" ]; then
RUFF_CMD="$RUFF_CMD --fix"
fi
eval "$RUFF_CMD"
'''
run_windows = '''
echo "running lint task"
echo [codeweaver] Running linting checks...
set OUTPUT_FORMAT=%usage_format%
if "%CI%"=="true" if "%usage_format%"=="full" set OUTPUT_FORMAT=github
if "%usage_fix%"=="true" (
uv run ruff check "%usage_dir%" --output-format=%OUTPUT_FORMAT% --fix
) else (
uv run ruff check "%usage_dir%" --output-format=%OUTPUT_FORMAT%
)
'''
[tasks.format]
run = '''
echo "running format task"
echo "${CW_PREFIX} Running formatting checks..."
hk fix
'''
run_windows = '''
echo "running format task"
echo [codeweaver] Running formatting checks...
hk fix
'''
[tasks.format.tools]
"aqua:typos" = "latest"
"pipx:exportify" = "latest"
"pipx:reuse" = "latest"
"aqua:tombi-toml/tombi" = "latest"
"ubi:astral-sh/ty" = "latest"
actionlint = "latest"
hk = "latest"
pkl = "latest"
shellcheck = "latest"
shfmt = "latest"
yq = "latest"
[tasks.format-fix]
run = '''
echo "running format-fix task"
echo "${CW_PREFIX} Applying formatting...hold onto your butts 🚬...🦖 "
# mise -y //:fix-ruff-patterns || { # there are some bugs to work out
# echo "${CW_PREFIX} ⚠️ \033[0;32mRuff pattern fixer encountered issues.\033[0m"}
uv run ruff format .
uv run ruff check --fix --unsafe-fixes . || true
git ls-files "*.yaml" "*.yml" "*.json" 2>/dev/null | xargs -r yq -iP --indent=2 eval "." 2>/dev/null || true
toml_files="$(git ls-files "*.toml" 2>/dev/null)"
# exportify fix || true
if [ -n "$toml_files" ]; then
printf '%s\n' "$toml_files" | xargs -r tombi format 2>/dev/null || true
fi
'''
run_windows = '''
echo "running format-fix task"
echo [codeweaver] Applying formatting...hold onto your butts 🚬...🦖
uv run ruff format .
for /f "delims=" %%f in ('git ls-files "*.yaml" "*.yml" "*.json" 2^>NUL') do (
yq -iP --indent=2 "." "%%f" 2>NUL
)
for /f "delims=" %%f in ('git ls-files "*.toml" 2^>NUL') do (
tombi format "%%f" 2>NUL
)
'''
[tasks.format-fix.tools]
"aqua:tombi-toml/tombi" = "latest"
yq = "latest"
uv = "latest"
[tasks.graph]
usage = '''
arg "[dir]" help="python directory to generate a graph for" default="src"
'''
run = '''
echo "running graph task"
mise x -- ruff analyze graph --target-version py312 --python .venv/bin/python "${usage_dir:-src/}"
'''
run_windows = '''
echo "running graph task"
mise x -- ruff analyze graph --target-version py312 --python .venv\Scripts\python.exe .
'''
[tasks.tree]
tools.uv = "latest"
run = '''
echo "running tree task"
uv tree --no-dev --group full
'''
[tasks.venv]
env.MISE_EXPERIMENTAL = "1"
tools.uv = "latest"
run = '''
echo "running venv task"
echo "${CW_PREFIX} Setting up Python virtual environment..."
uv venv --allow-existing --seed --keyring-provider subprocess --python {{ get_env(name="MISE_PYTHON_VERSION", default="3.13") }} --refresh .venv &&
echo "${CW_PREFIX} ✅ Virtual environment is ready!"
. .venv/bin/activate || echo "${CW_PREFIX} ⚠️ \033[0;31mFailed to source virtual environment.\033[0m"
echo "${CW_PREFIX} Running dependency sync..."
if [ "$CODEWEAVER__DEV__USE_GPU" = "true" ]; then
mise //:sync-gpu &
else
mise //:sync &
fi
'''
run_windows = '''
echo "running venv task"
echo [codeweaver] Setting up Python virtual environment...
uv venv --allow-existing --seed --keyring-provider subprocess --python {{ get_env(name="MISE_PYTHON_VERSION", default="3.13") }} --refresh .venv
if %ERRORLEVEL% equ 0 (
echo [codeweaver] Virtual environment is ready!
call .venv\Scripts\activate.bat
if %ERRORLEVEL% neq 0 (
echo [codeweaver] WARNING: Failed to source virtual environment.
)
)
echo [codeweaver] Running dependency sync...
if "%CODEWEAVER__DEV__USE_GPU%"=="true" (
start /b mise //:sync-gpu
) else (
start /b mise //:sync
)
'''
[tasks.test]
# Testing with flexible profiles and marker selection
tools.python = '''{{ get_env(name="MISE_PYTHON_VERSION", default="3.13") }}'''
tools.uv = "latest"
usage = '''
arg "[dir]" help="directory to test" default="tests/"
flag "-m --marks <markers>" help="pytest markers to filter tests"
flag "-p --profile <profile>" {
help "Test profile preset"
choices "fast" "integration" "real" "heavy" "all" "skip-list"
}
flag "--cov" help="Run with coverage reporting"
'''
run = '''
echo "running test task"
echo "${CW_PREFIX} Running tests..."
# Set markers based on profile
PYTEST_MARKS="${usage_marks}"
case "${usage_profile}" in
fast)
PYTEST_MARKS="unit and not expensive and not requires_models"
echo "${CW_PREFIX} Running fast unit tests (CI subset)..."
;;
integration)
PYTEST_MARKS="integration and not real_providers and not expensive"
echo "${CW_PREFIX} Running integration tests..."
;;
real)
PYTEST_MARKS="real_providers"
echo "${CW_PREFIX} Running real provider tests (requires model downloads)..."
;;
heavy)
PYTEST_MARKS="requires_models or expensive"
echo "${CW_PREFIX} Running heavy tests (requires models)..."
;;
skip-list)
echo "${CW_PREFIX} Listing skipped tests..."
uv run pytest --collect-only -m "skip" "$@"
exit 0
;;
all)
echo "${CW_PREFIX} Running ALL tests (including expensive ones)..."
;;
esac
# Build pytest command
PYTEST_CMD="uv run pytest \"${usage_dir}\""
if [ -n "$PYTEST_MARKS" ]; then
PYTEST_CMD="$PYTEST_CMD -m \"$PYTEST_MARKS\""
fi
if [ "${usage_cov}" = "true" ]; then
uv sync --group test --inexact
PYTEST_CMD="$PYTEST_CMD --cov=codeweaver --cov-report=xml --cov-report=term-missing --junit-xml=test-results.xml"
fi
PYTEST_CMD="$PYTEST_CMD -v \"\$@\""
eval "$PYTEST_CMD"
'''
run_windows = '''
echo "running test task"
echo [codeweaver] Running tests...
set PYTEST_MARKS=%usage_marks%
if "%usage_profile%"=="fast" (
set PYTEST_MARKS=unit and not expensive and not requires_models
echo [codeweaver] Running fast unit tests...
)
if "%usage_profile%"=="integration" (
set PYTEST_MARKS=integration and not real_providers and not expensive
echo [codeweaver] Running integration tests...
)
if "%usage_profile%"=="real" (
set PYTEST_MARKS=real_providers
echo [codeweaver] Running real provider tests...
)
if "%usage_profile%"=="heavy" (
set PYTEST_MARKS=requires_models or expensive
echo [codeweaver] Running heavy tests...
)
if "%usage_profile%"=="skip-list" (
echo [codeweaver] Listing skipped tests...
uv run pytest --collect-only -m "skip" %*
exit /b 0
)
if "%usage_profile%"=="all" (
echo [codeweaver] Running ALL tests...
)
if defined PYTEST_MARKS (
set PYTEST_ARGS=-m "%PYTEST_MARKS%"
) else (
set PYTEST_ARGS=
)
if "%usage_cov%"=="true" (
uv sync --group test --inexact
uv run pytest "%usage_dir%" %PYTEST_ARGS% --cov=codeweaver --cov-report=xml --cov-report=term-missing --junit-xml=test-results.xml -v %*
) else (
uv run pytest "%usage_dir%" %PYTEST_ARGS% -v %*
)
'''
[tasks.test.env]
CODEWEAVER_TEST_MODE = "true"
PYTHONPATH = "src"
PYTHONWARNINGS = "ignore:Core Pydantic V1:UserWarning"
[tasks.test-cov]
env.PYTHONPATH = "src"
env.PYTHONWARNINGS = "ignore:Core Pydantic V1:UserWarning"
tools.uv = "latest"
tools.python = '''{{ get_env(name="MISE_PYTHON_VERSION", default="3.13") }}'''
depends = ["sync"] # ensure test dependencies are installed
usage = '''
flag "-m --marks <markers>" help="pytest marker expression to filter tests"
flag "--timeout <seconds>" help="per-test timeout in seconds"
flag "--timeout-method <method>" help="pytest-timeout method (thread or signal)"
'''
run = '''
echo "running test-cov task"
echo "${CW_PREFIX} Running tests with coverage..."
# Build argument list without eval (POSIX-safe)
# Coverage measurement, reporting (html/xml/term-missing), and fail-under
# are all configured in pyproject.toml [tool.pytest] addopts.
# pytest-cov handles parallel combine and report generation internally.
set -- uv run --group test pytest tests/ --junit-xml=test-results.xml -v
if [ -n "${usage_marks}" ]; then
set -- "$@" -m "${usage_marks}"
fi
if [ -n "${usage_timeout}" ]; then
set -- "$@" --timeout="${usage_timeout}"
fi
if [ -n "${usage_timeout_method}" ]; then
set -- "$@" --timeout-method="${usage_timeout_method}"
fi
"$@"
'''
run_windows = '''
echo "running test-cov task"
echo [codeweaver] Running tests with coverage...
REM Coverage measurement, reporting (html/xml/term-missing), and fail-under
REM are all configured in pyproject.toml [tool.pytest] addopts.
REM pytest-cov handles parallel combine and report generation internally.
set PYTEST_CMD=uv run --group test pytest tests/ --junit-xml=test-results.xml -v
if defined usage_marks set PYTEST_CMD=%PYTEST_CMD% -m "%usage_marks%"
if defined usage_timeout set PYTEST_CMD=%PYTEST_CMD% --timeout=%usage_timeout%
if defined usage_timeout_method set PYTEST_CMD=%PYTEST_CMD% --timeout-method=%usage_timeout_method%
%PYTEST_CMD%
'''
[tasks.test-categories]
description = "Show test counts by category"
tools.uv = "latest"
tools.python = '''{{ get_env(name="MISE_PYTHON_VERSION", default="3.13") }}'''
run = '''
echo "running test-categories task"
echo "${CW_PREFIX} Test counts by category:"
echo "${CW_PREFIX} Fast unit tests:"
uv run pytest --collect-only -q -m "unit and not expensive and not requires_models" | grep -E "(test session|tests collected)" || echo " No matching tests"
echo ""
echo "${CW_PREFIX} Integration tests:"
uv run pytest --collect-only -q -m "integration and not real_providers and not expensive" | grep -E "(test session|tests collected)" || echo " No matching tests"
echo ""
echo "${CW_PREFIX} Real provider tests:"
uv run pytest --collect-only -q -m "real_providers" | grep -E "(test session|tests collected)" || echo " No matching tests"
echo ""
echo "${CW_PREFIX} Heavy tests:"
uv run pytest --collect-only -q -m "requires_models or expensive" | grep -E "(test session|tests collected)" || echo " No matching tests"
'''
run_windows = '''
echo [codeweaver] Running test-categories task...
echo [codeweaver] Test counts by category:
echo [codeweaver] Fast unit tests:
uv run pytest --collect-only -q -m "unit and not expensive and not requires_models" | findstr /R "test.*session tests.*collected" || echo No matching tests
echo.
echo [codeweaver] Integration tests:
uv run pytest --collect-only -q -m "integration and not real_providers and not expensive" | findstr /R "test.*session tests.*collected" || echo No matching tests
echo.
echo [codeweaver] Real provider tests:
uv run pytest --collect-only -q -m "real_providers" | findstr /R "test.*session tests.*collected" || echo No matching tests
echo.
echo [codeweaver] Heavy tests:
uv run pytest --collect-only -q -m "requires_models or expensive" | findstr /R "test.*session tests.*collected" || echo No matching tests
'''
[tasks.test-profiles]
description = "Build wheels and run install_smoke tests against each extras profile in an isolated venv"
tools.uv = "latest"
tools.python = '''{{ get_env(name="MISE_PYTHON_VERSION", default="3.13") }}'''
usage = '''
flag "-p --profiles <list>" help="Space-separated profiles to test (default: base recommended full)"
flag "--py <version>" help="Python version for the isolated venvs (default: current)"
flag "--keep-dist" help="Keep dist/ after the run instead of cleaning up"
'''
# Not yet cross-platform: this task shells out a bunch of POSIX stuff (mktemp,
# trap, shell globs) and isn't worth porting to PowerShell until the pattern
# stabilizes. Contributors on Windows should run the install-profile smoke
# tests via CI (nightly / weekly workflow integration is the next phase).
run = '''
set -e
PROFILES="${usage_profiles:-base recommended full}"
PY="${usage_py:-${MISE_PYTHON_VERSION:-3.13}}"
KEEP_DIST="${usage_keep_dist:-false}"
echo "${CW_PREFIX} Install-profile smoke runner"
echo "${CW_PREFIX} python: ${PY}"
echo "${CW_PREFIX} profiles: ${PROFILES}"
echo ""
# Temp scratch dir for venvs. `trap` on EXIT cleans up regardless of how we
# leave — success, failure, or Ctrl-C.
SCRATCH="$(mktemp -d -t cw-test-profiles.XXXXXXXX)"
cleanup() {
rm -rf "${SCRATCH}"
if [ "${KEEP_DIST}" != "true" ]; then
rm -rf dist/
fi
}
trap cleanup EXIT
# Build all three workspace wheels once. The smoke suite runs against these,
# not against the editable source tree — that's the whole point of the
# isolation: we want to know the PUBLISHED ARTIFACT resolves and imports
# cleanly on a minimal profile, not the developer's workstation.
echo "${CW_PREFIX} Building workspace wheels..."
rm -rf dist/
uv build --wheel --all-packages --quiet
ROOT_WHEEL="$(ls dist/code_weaver-*.whl | head -n 1)"
DAEMON_WHEEL="$(ls dist/code_weaver_daemon-*.whl | head -n 1)"
TOKENIZERS_WHEEL="$(ls dist/code_weaver_tokenizers-*.whl | head -n 1)"
if [ -z "${ROOT_WHEEL}" ] || [ -z "${DAEMON_WHEEL}" ] || [ -z "${TOKENIZERS_WHEEL}" ]; then
echo "${CW_PREFIX} ERROR: one or more workspace wheels missing from dist/ after build"
exit 1
fi
echo "${CW_PREFIX} root: $(basename "${ROOT_WHEEL}")"
echo "${CW_PREFIX} daemon: $(basename "${DAEMON_WHEEL}")"
echo "${CW_PREFIX} tokenizers: $(basename "${TOKENIZERS_WHEEL}")"
echo ""
FAILED_PROFILES=""
PASSED_PROFILES=""
for profile in ${PROFILES}; do
echo "${CW_PREFIX} =========================================================="
echo "${CW_PREFIX} profile: ${profile} (python ${PY})"
echo "${CW_PREFIX} =========================================================="
VENV_DIR="${SCRATCH}/venv-${profile}"
uv venv --python "${PY}" --quiet "${VENV_DIR}"
VENV_PY="${VENV_DIR}/bin/python"
# Install the wheel with the target profile's extras. `base` is the
# unadorned wheel; everything else appends `[profile]` to the main wheel
# spec. Passing all three wheels on the same install line lets uv resolve
# the workspace sibling pins (`code-weaver-daemon=={version}`) against the
# local files instead of PyPI, where they don't exist yet.
if [ "${profile}" = "base" ]; then
ROOT_SPEC="${ROOT_WHEEL}"
else
ROOT_SPEC="${ROOT_WHEEL}[${profile}]"
fi
echo "${CW_PREFIX} installing ${profile}..."
if ! VIRTUAL_ENV="${VENV_DIR}" uv pip install \
--python "${VENV_PY}" \
--quiet \
--find-links dist/ \
"${ROOT_SPEC}" \
"${DAEMON_WHEEL}" \
"${TOKENIZERS_WHEEL}" \
"pytest>=9" \
"pytest-asyncio>=1" \
"pytest-timeout>=2"; then
echo "${CW_PREFIX} INSTALL FAILED for ${profile}"
FAILED_PROFILES="${FAILED_PROFILES} ${profile}(install)"
continue
fi
# Pytest invocation notes:
# -o "addopts=" clears the project's --cov-fail-under / --cov=codeweaver
# defaults. Coverage doesn't work in isolation because the source tree
# isn't on sys.path (which is the whole point — we're testing the
# installed wheel, not `src/`).
# -o "pythonpath=" clears the project's `pythonpath = ["src"]` setting.
# If we left it, pytest would prepend the source tree to sys.path and
# `import codeweaver` would resolve there instead of the installed
# wheel, defeating the entire isolation.
# --import-mode=importlib matches the rest of the project's test runner.
echo "${CW_PREFIX} running smoke suite for ${profile}..."
if "${VENV_PY}" -m pytest \
tests/unit/smoke \
-m install_smoke \
-o "addopts=" \
-o "pythonpath=" \
--import-mode=importlib \
-v; then
echo "${CW_PREFIX} ${profile}: PASS"
PASSED_PROFILES="${PASSED_PROFILES} ${profile}"
else
echo "${CW_PREFIX} ${profile}: FAIL"
FAILED_PROFILES="${FAILED_PROFILES} ${profile}"
fi
echo ""
done
echo "${CW_PREFIX} =========================================================="
echo "${CW_PREFIX} Summary"
echo "${CW_PREFIX} =========================================================="
if [ -n "${PASSED_PROFILES}" ]; then
echo "${CW_PREFIX} passed:${PASSED_PROFILES}"
fi
if [ -n "${FAILED_PROFILES}" ]; then
echo "${CW_PREFIX} FAILED:${FAILED_PROFILES}"
exit 1
fi
echo "${CW_PREFIX} all profiles green"
'''
[tasks.clean]
usage = '''
flag "--deep" help="Perform deep clean (includes .venv and caches)"
flag "--venv-only" help="Only recreate virtual environment"
'''
run = '''
echo "running clean task"
if [ "${usage_deep}" = "true" ]; then
echo "${CW_PREFIX} Performing deep clean..."
# First clean build artifacts
rm -rf dist/ build/ *.egg-info/ .coverage test-results.xml
find . -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null || true
find . -type f -name "*.pyc" -delete
# Then clean caches and venv
rm -rf .venv
mise cache clear
uv cache clean --force
echo "${CW_PREFIX} ✅ Deep clean complete! Recreating venv..."
mise //:venv
elif [ "${usage_venv_only}" = "true" ]; then
echo "${CW_PREFIX} Recreating virtual environment..."
rm -rf .venv
mise //:venv
else
echo "${CW_PREFIX} Cleaning build artifacts..."
rm -rf dist/ build/ *.egg-info/ .coverage test-results.xml &&
find . -type d -name __pycache__ -exec rm -rf {} + 2>/dev/null || true &&
find . -type f -name "*.pyc" -delete &&
echo "${CW_PREFIX} ✅ Build artifacts cleaned!"
fi
'''
run_windows = '''
echo "running clean task"
if "%usage_deep%"=="true" (
echo [codeweaver] Performing deep clean...
if exist dist rd /s /q dist
if exist build rd /s /q build
if exist *.egg-info rd /s /q *.egg-info
if exist .coverage del .coverage
if exist test-results.xml del test-results.xml
for /d /r . %%d in (__pycache__) do @if exist "%%d" rd /s /q "%%d"
del /s /q *.pyc 2>NUL
rd /s /q .venv
mise cache clear
uv cache clean --force
echo [codeweaver] Deep clean complete! Recreating venv...
mise //:venv
) else if "%usage_venv_only%"=="true" (
echo [codeweaver] Recreating virtual environment...
rd /s /q .venv
mise //:venv
) else (
echo [codeweaver] Cleaning build artifacts...
if exist dist rd /s /q dist
if exist build rd /s /q build
if exist *.egg-info rd /s /q *.egg-info
if exist .coverage del .coverage
if exist test-results.xml del test-results.xml
for /d /r . %%d in (__pycache__) do @if exist "%%d" rd /s /q "%%d"
del /s /q *.pyc 2>NUL
echo [codeweaver] Build artifacts cleaned!
)
'''
# Release and maintenance
[tasks.version]
tools.uv = "latest"
run = '''
echo "running version task"
echo "${CW_PREFIX} CodeWeaver version information:"
echo "${CW_PREFIX} 📦 Package version: $CODEWEAVER_VERSION"
echo "${CW_PREFIX} 🐍 Python version: $(python --version)"
echo "${CW_PREFIX} 🌞 UV version: $(uv --version)"
'''
run_windows = '''
echo "running version task"
echo [codeweaver] CodeWeaver version information:
echo [codeweaver] 📦 Package version: %CODEWEAVER_VERSION%
for /f "delims=" %%v in ('python --version') do echo [codeweaver] Python version: %%v
for /f "delims=" %%v in ('uv --version') do echo [codeweaver] UV version: %%v
'''
[tasks.pre-commit]
env.MISE_EXPERIMENTAL = "1"
run = [
"echo \"${CW_PREFIX} Running pre-commit task...\"",
"echo \"${CW_PREFIX} Running CodeWeaver pre-commit checks 🪝... Thanks for your contributions! You're pretty cool. 🚀\" || true",
"mise //:format || echo \"${CW_PREFIX} ⚠️ You need to fix some issues before committing. Do not pass go, do not collect 200 dollars. 💸 😦\" && exit 1",
"git add .",
"git commit --amend --no-edit || true",
"mise //:check || echo \"${CW_PREFIX} ⚠️ You need to fix some issues before committing. Almost there!\" && exit 1",
"echo \"${CW_PREFIX} ✅ All pre-commit checks passed! You're awesome! 🎉 ... and they said the Kobiyashi Maru was unwinnable! 🖖\"",
]
run_windows = '''
echo "running pre-commit task"
echo [codeweaver] Running CodeWeaver pre-commit checks... Thanks for your contributions! You're pretty cool. 🚀
mise //:format
if %ERRORLEVEL% neq 0 (
echo [codeweaver] WARNING: You need to fix some issues before committing.
exit /b 1
)
git add .
git commit --amend --no-edit || echo.
mise //:check
if %ERRORLEVEL% neq 0 (
echo [codeweaver] WARNING: You need to fix some issues before committing. Almost there!
exit /b 1
)
echo [codeweaver] All pre-commit checks passed! You're awesome!
'''
[tasks.activate]
run = '''
echo "running activate task"
eval "$(mise activate "$ACTIVE_SHELL")" &>/dev/null
'''
run_windows = '''
echo "running activate task"
mise activate cmd
'''
hide = true
env.ACTIVE_SHELL = '''{{ exec(command='basename "$SHELL" 2>/dev/null || echo zsh') }}'''
[tasks.activate-shims]
run = '''
echo "running activate-shims task"
eval '"$(mise activate "${ACTIVE_SHELL:-zsh}" --shims)"' &>/dev/null
'''
run_windows = '''
echo "running activate-shims task"
mise activate cmd --shims
'''
hide = true
env.ACTIVE_SHELL = '''{{ exec(command='basename "$SHELL" 2>/dev/null || echo bash') }}'''