-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtasks.py
More file actions
847 lines (678 loc) Β· 24.7 KB
/
Copy pathtasks.py
File metadata and controls
847 lines (678 loc) Β· 24.7 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
"""Invoke tasks for code quality and formatting."""
import os
import platform
import shutil
import tarfile
import zipfile
from pathlib import Path
import requests
from invoke.context import Context
from invoke.tasks import task
@task
def python_lint(ctx: Context, fix: bool = False) -> None:
"""Run ruff linting on Python code with optional auto-fix.
Parameters
----------
ctx : Context
Invoke context object
fix : bool, optional
Whether to auto-fix issues, by default False
"""
print("π Linting Python code...")
cmd = "ruff check ."
if fix:
cmd += " --fix"
ctx.run(cmd)
@task
def lint(ctx: Context, fix: bool = False) -> None:
"""Run all linting (Python and C++) with optional auto-fix.
Parameters
----------
ctx : Context
Invoke context object
fix : bool, optional
Whether to auto-fix issues, by default False
"""
python_lint(ctx, fix=fix)
cpp_lint(ctx, fix=fix)
@task
def format(ctx: Context, check: bool = False) -> None:
"""Run ruff and clang-format with optional check-only mode.
Parameters
----------
ctx : Context
Invoke context object
check : bool, optional
Whether to check formatting without applying changes, by default False
"""
# Format Python code
print("π Formatting Python code...")
cmd = "ruff format ."
if check:
cmd += " --check"
ctx.run(cmd)
# Format C++ code
print("π Formatting C++ code...")
cpp_format(ctx, check=check)
@task
def typecheck(ctx: Context) -> None:
"""Run pyright type checking.
Parameters
----------
ctx : Context
Invoke context object
"""
ctx.run("pyright")
@task
def check(ctx: Context) -> None:
"""Run all code quality checks (lint, format check, typecheck, spellcheck).
Parameters
----------
ctx : Context
Invoke context object
"""
print("π Running linting...")
lint(ctx, fix=False)
print("π Checking formatting...")
format(ctx, check=True)
print("π¬ Type checking...")
typecheck(ctx)
print("π Spell checking...")
spellcheck(ctx)
print("β
All checks completed!")
@task
def check_fix(ctx: Context) -> None:
"""Auto-fix linting issues and format code (Python and C++).
Parameters
----------
ctx : Context
Invoke context object
"""
print("π§ Fixing linting issues...")
lint(ctx, fix=True)
print("π Formatting code...")
format(ctx, check=False)
print("β
All fixes applied!")
@task
def ai_developer_quality(ctx: Context) -> None:
"""Run comprehensive quality checks for AI agents.
AI Agents should use this task for quality checking.
After running this task, AI agents will need to refresh
their context as these commands can change files safely.
Parameters
----------
ctx : Context
Invoke context object
"""
print("π Formatting code...")
format(ctx, check=False)
print("π§ Fixing linting issues...")
lint(ctx, fix=True)
print("π¬ Type checking...")
typecheck(ctx)
print("π Spell checking...")
spellcheck(ctx)
@task
def clean(ctx: Context) -> None:
"""Clean up build artifacts and cache files.
Parameters
----------
ctx : Context
Invoke context object
"""
ctx.run("find . -type d -name '__pycache__' -exec rm -rf {} +", warn=True)
ctx.run("find . -type f -name '*.pyc' -delete", warn=True)
ctx.run("rm -rf .pytest_cache", warn=True)
ctx.run("rm -rf .ruff_cache", warn=True)
ctx.run("rm -f bmd_sg/decklink/libdecklink.dylib")
ctx.run("rm -rf cpp/build", warn=True)
ctx.run("rm -f cpp/compile_commands.json", warn=True)
print("π§Ή Cleaned up cache files and build artifacts!")
@task
def pristine(ctx: Context) -> None:
"""Clean up all build artifacts, cache files, and toolchain.
This is a more aggressive clean that removes everything including
the local toolchain. Use this for a complete reset.
Parameters
----------
ctx : Context
Invoke context object
"""
# Run regular clean first
clean(ctx)
# Clean up toolchain directory
toolchain_dir = Path(".toolchain")
if toolchain_dir.exists():
shutil.rmtree(toolchain_dir)
print("π§Ή Cleaned up .toolchain directory")
print("β¨ Repository reset to pristine state!")
@task
def test(ctx: Context) -> None:
"""Run tests.
Parameters
----------
ctx : Context
Invoke context object
"""
ctx.run("python -m pytest tests/")
def _get_cmake_path() -> str:
"""Get path to cmake binary, preferring local toolchain over system."""
# Check for local cmake first
system = platform.system()
if system == "Darwin":
toolchain_cmake = Path(".toolchain/CMake.app/Contents/bin/cmake")
else:
toolchain_cmake = Path(".toolchain/cmake/bin")
cmake_exe = "cmake.exe" if system == "Windows" else "cmake"
toolchain_cmake = toolchain_cmake / cmake_exe
if toolchain_cmake.exists():
return str(toolchain_cmake)
elif shutil.which("cmake"):
return "cmake"
else:
raise RuntimeError(
"cmake not found! Run 'uv run invoke setup-cmake' to install local toolchain"
)
@task(pre=[clean])
def build(ctx: Context) -> None:
"""Build the C++ library and Python package using CMake.
Parameters
----------
ctx : Context
Invoke context object
"""
try:
cmake_path = _get_cmake_path()
except RuntimeError as e:
print(f"β {e}")
print("π§ Setting up CMake first...")
setup_cmake(ctx)
cmake_path = _get_cmake_path()
print("π¨ Building C++ library with CMake...")
# Ensure build directory exists
build_dir = Path("cpp/build")
build_dir.mkdir(parents=True, exist_ok=True)
# Configure with CMake (generates compile_commands.json)
print("βοΈ Configuring build with CMake...")
result = ctx.run(f'"{cmake_path}" -B cpp/build -S cpp -DCMAKE_BUILD_TYPE=Release')
if not result or not result.ok:
print("β CMake configuration failed!")
return
# Build
print("ποΈ Building with CMake...")
result = ctx.run(f'"{cmake_path}" --build cpp/build')
if not result or not result.ok:
print("β CMake build failed!")
return
# Copy compile_commands.json to cpp directory for clang-tidy
compile_commands_src = Path("cpp/build/compile_commands.json")
compile_commands_dst = Path("cpp/compile_commands.json")
if compile_commands_src.exists():
import shutil
shutil.copy2(compile_commands_src, compile_commands_dst)
print("π Copied compile_commands.json for clang-tidy")
else:
print("β οΈ compile_commands.json not generated")
print("π¦ Building Python package...")
ctx.run("uv build")
print("β
Build completed!")
@task
def docs(ctx: Context, clean_build: bool = False) -> None:
"""Build Sphinx documentation.
Parameters
----------
ctx : Context
Invoke context object
clean_build : bool, optional
Whether to clean build directory first, by default False
"""
if clean_build:
print("π§Ή Cleaning documentation build directory...")
ctx.run("rm -rf docs/build/*", warn=True)
print("π Building Sphinx documentation...")
ctx.run("uv run sphinx-build -b html docs/source docs/build/html")
print("β
Documentation built successfully!")
print("π Open docs/build/html/index.html to view documentation")
@task
def serve_docs(ctx: Context, port: int = 8000) -> None:
"""Serve documentation locally with HTTP server.
Parameters
----------
ctx : Context
Invoke context object
port : int, optional
Port number for the web server, by default 8000
"""
import os
docs_path = "docs/build/html"
# Check if documentation exists
if not os.path.exists(docs_path):
print("π Documentation not found. Building first...")
docs(ctx)
print(f"π Starting web server on port {port}...")
print(f"π Open http://localhost:{port} in your browser")
print("π‘ Press Ctrl+C to stop the server")
try:
ctx.run(f"cd {docs_path} && python -m http.server {port}")
except KeyboardInterrupt:
print("\nπ Documentation server stopped.")
def _download_file(url: str, filename: str) -> None:
"""Download a file from URL with progress display."""
print(f"β¬οΈ Downloading {filename}...")
response = requests.get(url, stream=True)
response.raise_for_status()
# Download with progress
total_size = int(response.headers.get("content-length", 0))
downloaded = 0
with open(filename, "wb") as f:
for chunk in response.iter_content(chunk_size=8192):
if chunk:
f.write(chunk)
downloaded += len(chunk)
if total_size > 0:
percent = (downloaded / total_size) * 100
print(f"\r Progress: {percent:.1f}%", end="", flush=True)
print() # New line after progress
def _extract_archive(filename: str, target_dir: Path, special_handling=None) -> None:
"""Extract archive to target directory with optional special handling."""
print(f"π Extracting {filename}...")
# Clean up existing target directory
if target_dir.exists():
shutil.rmtree(target_dir)
# Extract based on file extension
if filename.endswith((".tar.xz", ".tar.gz")):
mode = "r:xz" if filename.endswith(".tar.xz") else "r:gz"
with tarfile.open(filename, mode) as tar:
members = tar.getnames()
if not members:
raise RuntimeError(f"Empty archive: {filename}")
top_dir = members[0].split("/")[0]
tar.extractall()
elif filename.endswith(".zip"):
with zipfile.ZipFile(filename, "r") as zip_file:
members = zip_file.namelist()
if not members:
raise RuntimeError(f"Empty archive: {filename}")
top_dir = members[0].split("/")[0]
zip_file.extractall()
else:
raise RuntimeError(f"Unsupported archive format: {filename}")
# Handle extraction with special or default logic
if special_handling:
special_handling(filename, top_dir, target_dir)
else:
# Default behavior: move extracted directory to target
shutil.move(top_dir, target_dir)
def _download_and_extract(
url: str, filename: str, target_dir: Path, special_handling=None
) -> str:
"""Download and extract a package from URL to target directory.
Parameters
----------
url : str
Download URL for the package
filename : str
Local filename to save the download
target_dir : Path
Directory where the extracted content should be placed
special_handling : callable, optional
Optional function to handle special extraction logic.
Should accept (filename, top_dir, target_dir) and return None.
Returns
-------
str
Path to the top-level extracted directory
"""
_download_file(url, filename)
_extract_archive(filename, target_dir, special_handling)
# Clean up downloaded file
os.remove(filename)
return str(target_dir)
@task
def spellcheck(ctx: Context) -> None:
"""Run spell checking using cspell.
Checks for spelling errors in Python, C++, and documentation files.
Provides helpful installation and configuration guidance if needed.
Parameters
----------
ctx : Context
Invoke context object
"""
import shutil
print("π Running spell check...")
# Check if npx is available
if not shutil.which("npx"):
print("β npx not found!")
print("π¦ Please install Node.js to get npx:")
print(" β’ macOS: brew install node")
print(" β’ Other: https://nodejs.org/")
return
# Try to run cspell, handle if not installed
try:
result = ctx.run(
'npx cspell "bmd_sg/**/*" "cpp/**/*" "docs/**/*" "tests/**/*" "examples/**/*" "*.md" --no-progress',
warn=True,
)
if result and result.ok:
print("β
No spelling errors found!")
else:
print("β οΈ Spelling errors detected!")
print("π§ To fix these issues:")
print(" 1. Correct any genuine spelling mistakes")
print(" 2. Add legitimate technical terms to cspell.json")
print(" 3. Technical terms should go in the 'words' array")
print("π Edit cspell.json to add new technical vocabulary")
except Exception as e:
if "command not found" in str(e).lower() or "not found" in str(e).lower():
print("π¦ cspell not found. For faster execution, install globally:")
print(" npm install -g cspell")
print("π Trying to install and run cspell temporarily...")
try:
ctx.run(
'npx cspell "bmd_sg/**/*" "cpp/**/*" "docs/**/*" "tests/**/*" "examples/**/*" "*.md" --no-progress',
warn=True,
)
except Exception:
print(
"β Failed to run cspell. Please check your Node.js installation."
)
else:
print(f"β Error running cspell: {e}")
@task
def setup_llvm(_: Context, version: str = "20.1.8") -> None:
"""Download and setup local LLVM toolchain with clang-tidy and clang-format.
Downloads LLVM binary release for the current platform and extracts
it to .toolchain/llvm/. This provides clang-tidy, clang-format, and other
LLVM tools for development.
Parameters
----------
ctx : Context
Invoke context object
version : str, optional
LLVM version to download, by default "20.1.8"
"""
toolchain_dir = Path(".toolchain")
llvm_dir = toolchain_dir / "llvm"
# Skip if already installed
clang_tidy_exe = (
"clang-tidy.exe" if platform.system() == "Windows" else "clang-tidy"
)
if (llvm_dir / "bin" / clang_tidy_exe).exists():
print(f"β
LLVM toolchain already installed at {llvm_dir}")
return
print(f"π¦ Setting up LLVM {version}...")
# Create directories
toolchain_dir.mkdir(exist_ok=True)
# Determine platform-specific download URL
system = platform.system()
if system == "Darwin":
prefix = "LLVM"
arch = "macOS-ARM64"
elif system == "Windows":
prefix = "clang+llvm"
arch = "x86_64-pc-windows-msvc"
else:
prefix = "LLVM-"
arch = "x86_64-linux-gnu-ubuntu-18.04"
filename = f"{prefix}-{version}-{arch}.tar.xz"
download_url = f"https://github.com/llvm/llvm-project/releases/download/llvmorg-{version}/{filename}"
# Download and extract using helper function (LLVM uses default extraction)
_download_and_extract(download_url, filename, llvm_dir)
# Verify installation
clang_tidy_path = llvm_dir / "bin" / clang_tidy_exe
if not clang_tidy_path.exists():
raise RuntimeError(f"clang-tidy not found at {clang_tidy_path}")
print("β
LLVM toolchain installed successfully!")
print(f"π Location: {llvm_dir}")
print(f"π§ clang-tidy: {clang_tidy_path}")
def _handle_cmake_extraction(_: str, top_dir: str, target_dir: Path) -> None:
"""Special handler for CMake extraction on macOS (app bundle)."""
system = platform.system()
toolchain_dir = target_dir.parent
if system == "Darwin":
# For macOS, move the entire CMake.app bundle to toolchain directory
extracted_cmake_app = Path(top_dir) / "CMake.app"
if extracted_cmake_app.exists():
shutil.move(str(extracted_cmake_app), str(toolchain_dir / "CMake.app"))
else:
# Fallback: move the whole directory and assume it's CMake.app
shutil.move(top_dir, str(toolchain_dir / "CMake.app"))
# Remove the now-empty extracted directory
if Path(top_dir).exists():
shutil.rmtree(top_dir)
else:
# For Linux/Windows, use default behavior
shutil.move(top_dir, target_dir)
@task
def setup_cmake(_: Context, version: str = "4.1.0") -> None:
"""Download and setup local CMake build system.
Downloads CMake binary release for the current platform and extracts
it to .toolchain/cmake/. This provides CMake for cross-platform builds
and compile_commands.json generation.
Parameters
----------
ctx : Context
Invoke context object
version : str, optional
CMake version to download, by default "4.1.0"
"""
toolchain_dir = Path(".toolchain")
system = platform.system()
# Platform-specific directory structure
if system == "Darwin":
cmake_dir = toolchain_dir / "CMake.app" / "Contents"
else:
cmake_dir = toolchain_dir / "cmake"
# Skip if already installed
cmake_exe = "cmake.exe" if system == "Windows" else "cmake"
if (cmake_dir / "bin" / cmake_exe).exists():
print(f"β
CMake already installed at {cmake_dir}")
return
print(f"π¦ Setting up CMake {version}...")
# Create directories
toolchain_dir.mkdir(exist_ok=True)
# Determine platform-specific CMake download
if system == "Darwin":
cmake_filename = f"cmake-{version}-macos-universal.tar.gz"
elif system == "Windows":
cmake_filename = f"cmake-{version}-windows-x86_64.zip"
else:
cmake_filename = f"cmake-{version}-linux-x86_64.tar.gz"
cmake_download_url = f"https://github.com/Kitware/CMake/releases/download/v{version}/{cmake_filename}"
# Download and extract using helper function
_download_and_extract(
cmake_download_url,
cmake_filename,
cmake_dir,
special_handling=_handle_cmake_extraction,
)
# Verify CMake installation
cmake_path = cmake_dir / "bin" / cmake_exe
if not cmake_path.exists():
raise RuntimeError(f"cmake not found at {cmake_path}")
print("β
CMake installed successfully!")
print(f"π Location: {cmake_dir}")
print(f"π§ cmake: {cmake_path}")
@task
def setup(ctx: Context, version: str = "20.1.8", cmake_version: str = "4.1.0") -> None:
"""Download and setup complete development toolchain (LLVM + CMake).
Orchestrates installation of both LLVM tools and CMake by calling the
individual setup tasks. This provides a convenient single command to
set up the entire development environment.
Parameters
----------
ctx : Context
Invoke context object
version : str, optional
LLVM version to download, by default "20.1.8"
cmake_version : str, optional
CMake version to download, by default "4.1.0"
"""
print("π¦ Setting up complete development toolchain...")
# Install LLVM tools (clang-tidy, clang-format, etc.)
setup_llvm(ctx, version=version)
# Install CMake
setup_cmake(ctx, version=cmake_version)
print("β
Development toolchain setup complete!")
@task
def cpp_format(ctx: Context, check: bool = False) -> None:
"""Run clang-format on C++ source files.
Uses local clang-format from .toolchain if available, falls back to system.
Parameters
----------
ctx : Context
Invoke context object
check : bool, optional
Whether to check formatting without applying changes, by default False
"""
# Check for local clang-format first
toolchain_clang_format = Path(".toolchain/llvm/bin")
clang_format_exe = (
"clang-format.exe" if platform.system() == "Windows" else "clang-format"
)
if (toolchain_clang_format / clang_format_exe).exists():
clang_format_path = str(toolchain_clang_format / clang_format_exe)
print(f"π§ Using local clang-format: {clang_format_path}")
elif shutil.which("clang-format"):
clang_format_path = "clang-format"
print("π§ Using system clang-format")
else:
print("β clang-format not found!")
print("π‘ Run 'uv run invoke setup-toolchain' to install local toolchain")
return
cpp_files = []
cpp_dir = Path("cpp")
if cpp_dir.exists():
# Find all C++ files but exclude DeckLink SDK
all_cpp_files = []
all_cpp_files.extend(cpp_dir.glob("*.cpp"))
all_cpp_files.extend(cpp_dir.glob("*.hpp"))
all_cpp_files.extend(cpp_dir.glob("*.cc"))
all_cpp_files.extend(cpp_dir.glob("*.h"))
# Filter out SDK files
cpp_files = [
f for f in all_cpp_files if "Blackmagic DeckLink SDK" not in str(f)
]
if not cpp_files:
print("π No C++ files found in cpp/ directory")
return
print(f"π Running clang-format on {len(cpp_files)} C++ files...")
# Build clang-format command
cmd_parts = [clang_format_path]
if check:
cmd_parts.append("--dry-run")
cmd_parts.append("--Werror")
else:
cmd_parts.append("-i")
# Add source files
cmd_parts.extend(str(f) for f in cpp_files)
cmd = " ".join(f'"{part}"' if " " in part else part for part in cmd_parts)
result = ctx.run(cmd, warn=True)
if result and result.ok:
if check:
print("β
No C++ formatting issues found!")
else:
print("β
C++ files formatted successfully!")
else:
if check:
print("β οΈ C++ formatting issues detected!")
else:
print("β οΈ C++ formatting encountered issues!")
@task
def cpp_lint(ctx: Context, fix: bool = False) -> None:
"""Run clang-tidy on C++ source files.
Uses xcrun to find the correct macOS SDK for local clang-tidy compatibility.
Parameters
----------
ctx : Context
Invoke context object
fix : bool, optional
Whether to auto-fix issues, by default False
"""
# Check for local clang-tidy first
toolchain_clang_tidy = Path(".toolchain/llvm/bin")
clang_tidy_exe = (
"clang-tidy.exe" if platform.system() == "Windows" else "clang-tidy"
)
if (toolchain_clang_tidy / clang_tidy_exe).exists():
clang_tidy_path = str(toolchain_clang_tidy / clang_tidy_exe)
print(f"π§ Using local clang-tidy: {clang_tidy_path}")
elif shutil.which("clang-tidy"):
clang_tidy_path = "clang-tidy"
print("π§ Using system clang-tidy")
else:
print("β clang-tidy not found!")
print("π‘ Run 'uv run invoke setup-toolchain' to install local toolchain")
return
# Find C++ files (exclude DeckLink SDK)
cpp_dir = Path("cpp")
if not cpp_dir.exists():
print("π No cpp/ directory found")
return
all_cpp_files = []
all_cpp_files.extend(cpp_dir.glob("*.cpp"))
all_cpp_files.extend(cpp_dir.glob("*.hpp"))
all_cpp_files.extend(cpp_dir.glob("*.cc"))
all_cpp_files.extend(cpp_dir.glob("*.h"))
cpp_files = [f for f in all_cpp_files if "Blackmagic DeckLink SDK" not in str(f)]
if not cpp_files:
print("π No C++ files found in cpp/ directory")
return
print(f"π Running clang-tidy on {len(cpp_files)} C++ files...")
# Get macOS SDK path using xcrun
try:
sdk_result = ctx.run("xcrun --show-sdk-path", hide=True)
if sdk_result and sdk_result.stdout:
sdk_path = sdk_result.stdout.strip()
print(f"π Using macOS SDK: {sdk_path}")
else:
print("β Failed to get SDK path from xcrun")
return
except Exception as e:
print(f"β Failed to get SDK path: {e}")
return
# Build clang-tidy command
cmd_parts = [clang_tidy_path]
if fix:
cmd_parts.append("--fix")
# Add source files
cmd_parts.extend(str(f) for f in cpp_files)
# Configure with proper sysroot and target
cmd_parts.extend(
[
f"--extra-arg-before=--sysroot={sdk_path}",
"--extra-arg-before=-target",
"--extra-arg-before=arm64-apple-macos",
]
)
# Add compile commands if available
if Path("cpp/compile_commands.json").exists():
cmd_parts.extend(["-p", "cpp"])
else:
# Add basic include paths for BMD project
cmd_parts.extend(
[
"--",
"-std=c++20",
"-I",
"cpp/Blackmagic DeckLink SDK 15.3/Mac/include",
]
)
cmd = " ".join(f'"{part}"' if " " in part else part for part in cmd_parts)
result = ctx.run(cmd, warn=True)
if result and result.ok:
print("β
No C++ linting issues found!")
else:
print("β οΈ C++ linting issues detected!")
@task
def dev(ctx: Context) -> None:
"""Quick development check: fix issues and run tests.
Parameters
----------
ctx : Context
Invoke context object
"""
check_fix(ctx)
typecheck(ctx)
spellcheck(ctx)
test(ctx)