mirror of
https://github.com/harvard-edge/cs249r_book.git
synced 2026-07-16 14:42:29 -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
43 lines
1.2 KiB
Python
43 lines
1.2 KiB
Python
import sys
|
|
import traceback
|
|
|
|
def test_file(qmd_file):
|
|
with open(qmd_file, 'r') as f:
|
|
content = f.read()
|
|
|
|
import re
|
|
blocks = re.findall(r'```\{python\}(.*?)```', content, re.DOTALL)
|
|
if not blocks:
|
|
print(f"✅ {qmd_file} (No Python blocks)")
|
|
return True
|
|
|
|
combined_code = "\n".join(blocks)
|
|
|
|
# Save combined code to temp file to get accurate line numbers
|
|
import tempfile
|
|
with tempfile.NamedTemporaryFile(suffix='.py', mode='w', delete=False) as temp:
|
|
temp.write(combined_code)
|
|
temp_name = temp.name
|
|
|
|
namespace = {}
|
|
try:
|
|
exec(compile(combined_code, temp_name, 'exec'), namespace)
|
|
print(f"✅ {qmd_file} (Passed)")
|
|
import os
|
|
os.remove(temp_name)
|
|
return True
|
|
except Exception as e:
|
|
print(f"❌ Error in {qmd_file}:")
|
|
traceback.print_exc(file=sys.stdout)
|
|
import os
|
|
os.remove(temp_name)
|
|
return False
|
|
|
|
if __name__ == "__main__":
|
|
if len(sys.argv) > 1:
|
|
success = test_file(sys.argv[1])
|
|
sys.exit(0 if success else 1)
|
|
else:
|
|
print("Usage: python3 scripts/exec_single.py <path/to/file.qmd>")
|
|
sys.exit(1)
|