Bnot fixes ; Missing énoncés fixes.

This commit is contained in:
sebastien committed 2026-10-23 11:15:05 +02:00
1 parent f39868207d
commit 55d5cf16c9
18 files changed
+486 -44

No files matched your search

+52 -14
View File
@@ -93,10 +93,7 @@ def pdf_images_of_contexts(root_dir, label, all_labels):
def get_exam_file_content(folder_path, mode, label):
"""
Retrieves content from the Text or Sol directory for a specific label.
Checks for exact filename matches or grouped 'prefix[a,b,c]' filenames.
"""
"""Use the most specific exact, grouped, or enclosing section available."""
target_dir = Path(folder_path) / mode
if not target_dir.is_dir():
return None
@@ -109,23 +106,37 @@ def get_exam_file_content(folder_path, mode, label):
if direct_file.is_file():
return direct_file.read_text(encoding="utf-8")
# 2. Search for grouped files: prefix[suffix1,suffix2,...]
for file_path in target_dir.iterdir():
candidates = []
for file_path in sorted(target_dir.iterdir()):
if not file_path.is_file():
continue
name = file_path.name
if file_path.suffix in {".pdf", ".tex"}:
continue
covered_labels = [name]
if "[" in name and name.endswith("]"):
# Split 'prefix[suffixes]' -> 'prefix', 'suffixes'
prefix, rest = name.split("[", 1)
suffixes = rest[:-1].split(",") # Remove trailing ']' and split
# Check if any reconstructed label matches
for s in suffixes:
if (prefix + s) == safe_label:
return file_path.read_text(encoding="utf-8")
covered_labels = [prefix + suffix.strip() for suffix in rest[:-1].split(",")]
for covered in covered_labels:
if covered == safe_label or _is_parent_label(covered, safe_label):
candidates.append((len(covered), name == covered, file_path))
if candidates:
# Prefer a narrower section, then its direct file over a grouped file.
candidates.sort(key=lambda item: (-item[0], -item[1], item[2].name))
return candidates[0][2].read_text(encoding="utf-8")
return None
def _is_parent_label(parent, label):
if not parent or not label.startswith(parent):
return False
suffix = label[len(parent):]
# Respect component boundaries: Ex 1 must not match Ex 10, nor 1) match 10).
return bool(
suffix.startswith((" ", ":", "."))
or (parent.endswith(")") and re.match(r"[A-Za-z0-9]+\)", suffix))
)
def get_label_text_content(folder, label):
return get_exam_file_content(folder, "Text", label)
@@ -135,6 +146,33 @@ def get_label_sol_content(folder, label):
def get_label_persp_content(folder, label):
return get_exam_file_content(folder, "Persp", label)
def warn_missing_exam_material(workspace):
"""Report prompt coverage after statement preparation without blocking work."""
if not workspace.labels_file.is_file():
print("[Vérification des prompts] Avertissement : fichier labels absent ; vérification impossible.")
return
labels = workspace.read_labels()
missing_count = 0
for label in labels:
missing = []
for mode, title in (("Text", "énoncé"), ("Sol", "corrigé")):
try:
content = get_exam_file_content(workspace.root, mode, label)
if not content or not content.strip() or content.strip().rstrip(" :") == label:
missing.append(f"{title} absent ou vide ({mode})")
except (OSError, UnicodeError) as exc:
missing.append(f"{title} illisible ({mode}) : {exc}")
if missing:
missing_count += 1
print(f"[Vérification des prompts] Avertissement — {label} : {' ; '.join(missing)}")
print(
f"[Vérification des prompts] {len(labels) - missing_count}/{len(labels)} labels "
"avec énoncé et corrigé non vides."
)
if missing_count:
print("[Vérification des prompts] Vous pouvez continuer ; les corrections des labels signalés utiliseront des documents incomplets.")
import tempfile
import shutil
import subprocess