Files
cs249r_book/scripts/static_analysis.py
T
Vijay Janapa Reddi fccee3c735 Refactor: complete the Great Constant Migration across mlsysim and Quarto chapters
- Migrated all legacy constants from constants.py to hardware and model registries
- Updated dozens of LEGO blocks in Volume 1 and Volume 2 to use Engine.solve and formulas
- Resolved all resulting NameError, TypeError, and AttributeError exceptions in the inline Python blocks
- Master Quarto HTML build now passes with zero execution failures
2026-05-23 16:45:00 -04:00

34 lines
1.1 KiB
Python

import os
import glob
import subprocess
import tempfile
qmd_files = glob.glob('book/quarto/contents/**/*.qmd', recursive=True)
for qmd in qmd_files:
with open(qmd, 'r') as f:
content = f.read()
# Extract all python code blocks
import re
blocks = re.findall(r'```\{python\}(.*?)```', content, re.DOTALL)
if not blocks:
continue
combined_code = "\n".join(blocks)
# Write to a temp file and run pyflakes
with tempfile.NamedTemporaryFile(suffix='.py', mode='w', delete=False) as temp:
temp.write(combined_code)
temp_name = temp.name
result = subprocess.run(['python3', '-m', 'pyflakes', temp_name], capture_output=True, text=True)
if result.stdout or result.stderr:
print(f"\n--- Errors in {qmd} ---")
# Filter out unused imports for this check, focus on undefined names
errors = [line for line in result.stdout.split('\n') if 'undefined name' in line]
for e in errors:
print(e.split(':', 1)[1].strip())
os.remove(temp_name)