# gather all the meta info from all the files - check for errors
import yaml
from pathlib import Path
def extract_meta_from_qmd(file_path):
"""
Extracts and returns the YAML front matter (meta information) from a QMD file.
Parameters:
- file_path: Path to the QMD file.
Returns:
- A dictionary containing the parsed YAML front matter, or None if not found.
"""
# Initialize an empty string to hold the YAML content
= ''
yaml_content # Flag to indicate if we are within the YAML front matter
= False
in_yaml
with open(file_path, 'r') as f:
for line in f:
# Check for the start/end of the YAML front matter
if line.strip() == '---':
if in_yaml:
# We found the second ---, stop reading further
break
else:
# We found the first ---, start collecting lines
= True
in_yaml elif in_yaml:
# Add the current line to the YAML content
+= line
yaml_content
# Parse the YAML content if any was found
if yaml_content:
return yaml.safe_load(yaml_content)
else:
return None
import os
def list_all_files(root_dir):
"""List all files in a directory and its subdirectories."""
= []
all_files for root, dirs, files in os.walk(root_dir):
for file in files:
file))
all_files.append(os.path.join(root, return all_files
= Path("/home/norm/compiler_course_2024fa/") base
from numpy import isin
= {}
meta_union for file in list_all_files(base):
= Path(file)
file_path if file_path.suffix in [".pdf", ".jpg", ".png", ".woff", ".eot", ".woff2", ".ttf", ".so", ".pyc"]:
continue
if file_path.parent.name == "bin":
continue
if any(parent.name == ".venv" for parent in file_path.parents):
continue
if any(parent.name == ".git" for parent in file_path.parents):
continue
= extract_meta_from_qmd(file)
meta_info if meta_info:
for key, value in meta_info.items():
if isinstance(value, list):
= ', '.join(map(str, value))
value elif isinstance(value,dict):
for sub_key, sub_value in value.items():
= f"{key}.{sub_key}" # Combine the parent key and sub-key
combined_key = str(sub_value) # Convert sub-value to string
sub_value if combined_key not in meta_union:
= {sub_value}
meta_union[combined_key] else:
meta_union[combined_key].add(sub_value)continue
if key not in meta_union:
= {value}
meta_union[key] else:
meta_union[key].add(value)
for (k,v) in meta_union.items():
print (k, v )
title {'Representation of programs', 'Performance and Measurement', '14_gpu_compilers', '5_hw', 'project', 'EECE7398 Fall 2024', '10 MLIR', '3_hw ', 'Untitled', '_ loop invariant code motion', '9 polyhedral analysis', '11 Whole program', 'EECS7398 Weekly Schedule', 'How to do assignments', 'homework 0', '8 classic loop optimizations', 'Overview of Bril', '_ partial_redundancy elimination', '4_hw', 'EECS7398 Weekly Schedule fa 2024', '_ local value numbering', '4. Data Flow', 'About', 'Schedule', '3 Local Analysis & Optimization', '2.hw', '12_memory.qmd', 'Testing Register allocators', '6- extra credit hw ', '1 Compiler Overview', '1-Homework', 'Static Single Assignment', '13_dynamic_compielrs', '5 Global Analysis'}
format {'html'}
tbl-colwidths {'10, 20, 20, 20, 15, 15'}
format.html {'default'}
format.revealjs {"{'chalkboard': True, 'output-file': 'revealjs-licm', 'scrollable': True}", "{'chalkboard': True, 'output-file': 'revealjs-rep'}", "{'chalkboard': True, 'output-file': 'revealjs-partial-redun', 'scrollable': True}", "{'chalkboard': True, 'scrollable': True, 'output-location': 'slide', 'code-line-numbers': True, 'output-file': 'revealjs-bril'}", "{'chalkboard': True, 'output-file': 'revealjs-local', 'scrollable': True}", "{'chalkboard': True, 'output-file': 'revealjs-ssa', 'scrollable': True}", "{'chalkboard': True, 'output-file': 'revealjs-lvn', 'scrollable': True}", "{'chalkboard': True, 'output-file': 'revealjs-compiler_overview.html', 'scrollable': True}", "{'chalkboard': True, 'output-file': 'revealjs-data-flow', 'scrollable': True}", "{'chalkboard': True, 'output-file': 'revealjs-global-anal', 'scrollable': True}", "{'chalkboard': True, 'output-file': 'revealjs-performance.html', 'scrollable': True}"}
keep-ipynb {True}
python {'kaggle_comp'}
sidebar {False}
execute.echo {'True'}
import os
import yaml
= Path("/home/norm/compiler_course_2024fa/")
base
# Step 1: List all .qmd files
= []
qmd_files = []
slide_qmd_files
for root, dirs, files in os.walk(base): # Adjust '.' to your project directory if necessary
revealjs_if "_site" in Path(root).parts:
continue
for file in files:
if file.endswith('.qmd'):
file))
qmd_files.append(os.path.join(root,
# Step 2: Read and parse each .qmd file
for qmd_file in qmd_files:
with open(qmd_file, 'r') as file:
= file.read()
content # Assuming the YAML metadata is at the top of the file, delimited by ---
if content.startswith('---'):
= content.find('---', 3)
end_of_yaml if end_of_yaml != -1:
= content[3:end_of_yaml]
yaml_content = yaml.safe_load(yaml_content) # Parse YAML
metadata
= metadata.get('format')
format_data if not format_data:
print(qmd_file, "no format field")
continue
try:
= format_data.get("html")
html_meta_data except Exception as e:
print(qmd_file, e, 'format does not have html')
continue
if html_meta_data != 'default':
print(qmd_file, "not html default")
continue
try:
= format_data.get('revealjs')
revealjs_meta_data except:
print("qmd_file", "no revealjs")
continue
if revealjs_meta_data:
= revealjs_meta_data.get("chalkboard'")
chalk if chalk != 'true':
print(qmd_file, "missing chalkboard")
# get the format
# see if it has a subkey, revealjs
# if it does check for an deeper subkey of output-file
# Step 3: Check for format: reveljs
if metadata.get('format') == 'revealjs':
# Step 4: Verify the output file name
= 'reveljs-' + os.path.basename(qmd_file).replace('.qmd', '')
expected_output if metadata.get('output-file') == expected_output:
print(f"{qmd_file}: Success, output file name is correct.")
else:
print(f"{qmd_file}: Failure, output file name does not match the expected '{expected_output}'.")
/home/norm/compiler_course_2024fa/lectures/02a_representation.qmd missing chalkboard
/home/norm/compiler_course_2024fa/lectures/010_compiler_overview.qmd missing chalkboard
/home/norm/compiler_course_2024fa/lectures/02b_bril.qmd missing chalkboard
/home/norm/compiler_course_2024fa/lectures/05_global.qmd missing chalkboard
/home/norm/compiler_course_2024fa/lectures/01a_performance_measurement.qmd missing chalkboard
/home/norm/compiler_course_2024fa/lectures/06_ssa.qmd missing chalkboard
/home/norm/compiler_course_2024fa/lectures/05b_licm.qmd missing chalkboard
/home/norm/compiler_course_2024fa/lectures/04_data_flow.qmd missing chalkboard
/home/norm/compiler_course_2024fa/lectures/03b_local_value_numbering.qmd missing chalkboard
/home/norm/compiler_course_2024fa/lectures/03_local.qmd missing chalkboard