mirror of
https://github.com/harvard-edge/cs249r_book.git
synced 2026-07-20 01:01:30 -05:00
- 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
34 lines
1.1 KiB
Python
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)
|