Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .githooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ echo ""
echo "mfc: Running precheck before commit (-j $JOBS)..."
echo ""

if ./mfc.sh precheck -j "$JOBS"; then
if ./mfc.sh precheck --staged -j "$JOBS"; then
echo ""
exit 0
else
Expand Down
4 changes: 2 additions & 2 deletions .github/scripts/monitor_slurm_job.sh
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ while [ ! -f "$output_file" ]; do
RUNNING|COMPLETING)
unknown_count=0
# Job is running but output file not yet visible (NFS delay)
sleep 2
sleep "$MFC_MONITOR_POLL_SECONDS"
;;
UNKNOWN)
unknown_count=$((unknown_count + 1))
Expand Down Expand Up @@ -223,7 +223,7 @@ done
# Give tail a moment to flush the final lines, then stop streaming. Whether it
# was still alive decides how much needs reprinting below: if it streamed the
# whole job, printing the file again just doubles every log.
sleep 2
sleep "$MFC_MONITOR_POLL_SECONDS"
streamed_ok=0
if kill -0 "${tail_pid}" 2>/dev/null; then
streamed_ok=1
Expand Down
2 changes: 1 addition & 1 deletion toolchain/bootstrap/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ if [ "$RUN_TESTS" = true ]; then
log "(venv) Running$MAGENTA unit tests$COLOR_RESET on$MAGENTA MFC$COLOR_RESET's $MAGENTA""toolchain$COLOR_RESET."

cd toolchain
python3 -m pytest . -v
python3 -m pytest . -v -n auto --maxprocesses=16
cd - > /dev/null
fi

Expand Down
39 changes: 31 additions & 8 deletions toolchain/bootstrap/precheck.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ show_help() {
echo "Options:"
echo " -h, --help Display this help message and exit."
echo " -j, --jobs JOBS Runs JOBS number of parallel jobs for formatting."
echo " --staged Skip the checks no staged file can affect (the pre-commit hook)."
echo ""
exit 0
}


JOBS=1
STAGED=0

while [[ $# -gt 0 ]]; do
case "$1" in
Expand All @@ -32,6 +34,9 @@ while [[ $# -gt 0 ]]; do
JOBS="$2"
shift
;;
--staged)
STAGED=1
;;
-h | --help)
show_help
;;
Expand All @@ -56,6 +61,16 @@ export MFC_SKIP_SUITE_LINT=1

NCHECK=7

# --staged: the unit tests read src/ and examples/ as well, so only a docs-only commit skips them;
# the example decks depend only on examples/ and toolchain/. CI runs everything.
LINT_ARGS=()
CHECK_EXAMPLES=1
if [ "$STAGED" = 1 ]; then
staged=$(git diff --cached --name-only)
if [ -n "$staged" ] && ! grep -qv '^docs/' <<< "$staged"; then LINT_ARGS=(--no-test); fi
grep -qE '^(examples|toolchain)/' <<< "$staged" || CHECK_EXAMPLES=0
fi

log "Running$MAGENTA precheck$COLOR_RESET (same checks as CI lint-gate)..."
echo ""

Expand Down Expand Up @@ -88,7 +103,7 @@ PID_SPELL=$!

# Lint (ruff + unit tests) — safe after format since files are stable
(
if ./mfc.sh lint > /dev/null 2>&1; then
if ./mfc.sh lint "${LINT_ARGS[@]}" > /dev/null 2>&1; then
echo "0" > "$TMPDIR_PC/lint_exit"
else
echo "1" > "$TMPDIR_PC/lint_exit"
Expand All @@ -107,10 +122,14 @@ PID_LINT=$!
PID_SOURCE=$!

# Doc reference check
DOC_FAILED=0
if ! python3 toolchain/mfc/lint_docs.py > /dev/null 2>&1; then
DOC_FAILED=1
fi
(
if python3 toolchain/mfc/lint_docs.py > /dev/null 2>&1; then
echo "0" > "$TMPDIR_PC/doc_exit"
else
echo "1" > "$TMPDIR_PC/doc_exit"
fi
) &
PID_DOC=$!

# Parameter documentation check
(
Expand All @@ -127,6 +146,7 @@ PID_PARAM_DOCS=$!
# (~90%) the ~6 min serial loop over 155 cases; batching drops it to well under a minute.
# Every example directory holds its deck as case.py, so the glob below sees it (scaling/ is a benchmark harness).
(
[ "$CHECK_EXAMPLES" = 1 ] || { echo "skip" > "$TMPDIR_PC/examples_exit"; exit 0; }
missing=$(git ls-files 'examples/*/*' | cut -d/ -f2 | sort -u | while read -r d; do
[ -f "examples/$d/case.py" ] || [ "$d" = scaling ] || echo "examples/$d"
done)
Expand Down Expand Up @@ -165,7 +185,7 @@ wait $PID_LINT
log "[$CYAN 3/$NCHECK$COLOR_RESET] Running$MAGENTA toolchain lint$COLOR_RESET..."
LINT_RC=$(cat "$TMPDIR_PC/lint_exit" 2>/dev/null || echo "1")
if [ "$LINT_RC" = "0" ]; then
ok "Toolchain lint passed."
ok "Toolchain lint passed${LINT_ARGS:+ (unit tests skipped: only docs/ staged)}."
else
error "Toolchain lint failed. Run$MAGENTA ./mfc.sh lint$COLOR_RESET for details."
FAILED=1
Expand All @@ -181,8 +201,9 @@ else
FAILED=1
fi

wait $PID_DOC
log "[$CYAN 5/$NCHECK$COLOR_RESET] Checking$MAGENTA doc references$COLOR_RESET..."
if [ $DOC_FAILED -eq 0 ]; then
if [ "$(cat "$TMPDIR_PC/doc_exit" 2>/dev/null || echo 1)" = "0" ]; then
ok "Doc references are valid."
else
error "Doc reference check failed. Run$MAGENTA python3 toolchain/mfc/lint_docs.py$COLOR_RESET for details."
Expand All @@ -202,7 +223,9 @@ fi
wait $PID_EXAMPLES
log "[$CYAN 7/$NCHECK$COLOR_RESET] Validating$MAGENTA example cases$COLOR_RESET..."
EXAMPLES_FAILED=$(cat "$TMPDIR_PC/examples_exit" 2>/dev/null || echo "1")
if [ "$EXAMPLES_FAILED" = "0" ]; then
if [ "$EXAMPLES_FAILED" = "skip" ]; then
ok "Example cases skipped: nothing staged under examples/ or toolchain/."
elif [ "$EXAMPLES_FAILED" = "0" ]; then
ok "All example cases are valid."
else
[ -f "$TMPDIR_PC/examples_missing" ] && error "$(cat "$TMPDIR_PC/examples_missing") (name the deck case.py)."
Expand Down
16 changes: 11 additions & 5 deletions toolchain/mfc/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import os
import sys
from concurrent.futures import ThreadPoolExecutor

from . import state
from .case_validator import CaseConstraintError, CaseValidator
Expand Down Expand Up @@ -33,13 +34,18 @@ def _validate_batch_default_build(inputs):
failed = []
refused = []
with_issues = []
for c in inputs:
if not os.path.isfile(c):
failed.append(c)
continue

def _load(c):
try:
case = run_input.load(c, do_print=False)
return run_input.load(c, do_print=False) if os.path.isfile(c) else None
except MFCException:
return None

# Each load runs the case file in its own interpreter (~0.5 s, most of the time), so run them side by side.
with ThreadPoolExecutor(max_workers=min(16, os.cpu_count() or 1)) as pool:
cases = list(pool.map(_load, inputs))
for c, case in zip(inputs, cases):
if case is None:
failed.append(c)
continue
had_issue = False
Expand Down
1 change: 1 addition & 0 deletions toolchain/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ dependencies = [
"ffmt==0.4.5",
"ansi2txt",
"pytest",
"pytest-xdist",

# Profiling
"numpy",
Expand Down
Loading