Support for A.pdf, A.tex and Ac.tex for initial files

This commit is contained in:
sebastien committed 2026-09-26 11:22:09 +02:00
1 parent 42a5b9778e
commit e4e25eca55
12 files changed
+104 -32

No files matched your search

+4 -1
View File
@@ -109,7 +109,10 @@ def _return_artifacts(workspace: EvaluationWorkspace) -> list[Path]:
def _is_statement_text_file(workspace: EvaluationWorkspace, path: Path) -> bool:
relative = path.relative_to(workspace.root)
if len(relative.parts) == 1:
return relative.name in STATEMENT_ROOT_FILES
return relative.name in STATEMENT_ROOT_FILES or path in {
*workspace.input_candidates("enonce.tex"),
*workspace.input_candidates("correction.tex"),
}
top_level = relative.parts[0]
if top_level in STATEMENT_TEXT_DIRECTORIES:
return path.suffix.casefold() in {"", ".json", ".tex", ".txt"}
+1 -2
View File
@@ -24,7 +24,7 @@ def copy_pdfs(directory: Path) -> list[Path]:
(
path
for path in directory.glob("*.pdf")
if path.name.casefold() not in {"enonce.pdf", "énoncé.pdf"}
if not EvaluationWorkspace(directory).is_statement_pdf(path)
),
key=lambda path: path.name.casefold(),
)
@@ -134,4 +134,3 @@ def main(argv: Sequence[str] | None = None) -> int:
if __name__ == "__main__":
raise SystemExit(main())
+1 -1
View File
@@ -143,7 +143,7 @@ def save_split_content(text, path, base_fname, problem):
def process_directory(workspace: EvaluationWorkspace) -> ExitCode:
directory = str(workspace.root)
# Find the first .tex file in the directory
enonce = workspace.root / "enonce.tex"
enonce = workspace.statement_source_file
tex_files = [str(enonce)] if enonce.is_file() else sorted(glob.glob(os.path.join(directory, "*.tex")))
if not tex_files:
print(f"No .tex file found in {directory}. Looking in /Staging/Interro/")
+7 -3
View File
@@ -331,14 +331,18 @@ def process_exam(
cache_c_file = cache_dir / "gemini_context.json"
# 1. Resolve files
pdf_path = folder / "enonce.pdf"
pdf_path = workspace.statement_pdf_file
enonce_path = find_file(folder, "enonce")
if enonce_path is None:
enonce_path = workspace.statement_source_file
correction_path = find_file(folder, "correction")
if correction_path is None:
correction_path = workspace.correction_source_file
missing = []
if not pdf_path.is_file(): missing.append("enonce.pdf")
if not enonce_path: missing.append("enonce.org or enonce.tex")
if not correction_path: missing.append("correction.org or correction.tex")
if not enonce_path.is_file(): missing.append("enonce.tex")
if not correction_path.is_file(): missing.append("correction.tex")
if missing:
raise CliError(
+3 -9
View File
@@ -476,17 +476,11 @@ class ImageViewer:
def on_open_interro(self, event):
if self.is_viewing and self.current_json_path:
# Check local directory first
local_accent = self.base_dir / "énoncé.pdf"
local_plain = self.base_dir / "enonce.pdf"
if local_accent.exists():
pdf_path = str(local_accent)
elif local_plain.exists():
pdf_path = local_plain
else:
pdf_path = EvaluationWorkspace(self.base_dir).statement_pdf_file
if not pdf_path.is_file():
messagebox.showerror(
"PDF not found",
f"Neither {local_accent.name} nor {local_plain.name} exists in {self.base_dir}.",
f"No statement PDF exists in {self.base_dir}.",
)
return
+40 -3
View File
@@ -63,12 +63,49 @@ class EvaluationWorkspace:
".copienator",
".copienator-gui.json",
)
return path.is_dir() and any((path / marker).exists() for marker in markers)
if not path.is_dir():
return False
aliases = (f"{path.name}.pdf", f"{path.name}.tex", f"{path.name}c.tex")
return any((path / marker).exists() for marker in (*markers, *aliases))
@property
def name(self) -> str:
return self.root.name
def input_candidates(self, canonical_name: str) -> tuple[Path, ...]:
"""Return preferred paths for one of the three statement inputs."""
aliases = {
"enonce.pdf": ("enonce.pdf", "énoncé.pdf", f"{self.name}.pdf"),
"enonce.tex": ("enonce.tex", f"{self.name}.tex"),
"correction.tex": ("correction.tex", f"{self.name}c.tex"),
}
names = aliases.get(canonical_name, (canonical_name,))
return tuple(self.root / name for name in names)
def resolve(self, relative_path: str) -> Path:
"""Resolve a logical workspace path, including statement aliases."""
candidates = self.input_candidates(relative_path)
return next((path for path in candidates if path.exists()), candidates[0])
def resolve_file(self, relative_path: str) -> Path:
candidates = self.input_candidates(relative_path)
return next((path for path in candidates if path.is_file()), candidates[0])
@property
def statement_pdf_file(self) -> Path:
return self.resolve_file("enonce.pdf")
@property
def statement_source_file(self) -> Path:
return self.resolve_file("enonce.tex")
@property
def correction_source_file(self) -> Path:
return self.resolve_file("correction.tex")
def is_statement_pdf(self, path: Path) -> bool:
return path in self.input_candidates("enonce.pdf")
@property
def metadata_dir(self) -> Path:
return self.root / ".copienator"
@@ -220,7 +257,7 @@ class EvaluationWorkspace:
missing = [
relative_path
for relative_path in relative_paths
if not (self.root / relative_path).exists()
if not self.resolve(relative_path).exists()
]
if missing:
raise WorkspaceValidationError(self.root, missing)
@@ -229,7 +266,7 @@ class EvaluationWorkspace:
missing = [
relative_path
for relative_path in relative_paths
if not (self.root / relative_path).is_file()
if not self.resolve_file(relative_path).is_file()
]
if missing:
raise WorkspaceValidationError(self.root, missing)