diff --git a/tests/preflight_parser/fixture/anc_files_1/NOBEL_PRIZE_WINNER.TEX b/tests/preflight_parser/fixture/anc_files_1/NOBEL_PRIZE_WINNER.TEX new file mode 100644 index 0000000..1f0b0c6 --- /dev/null +++ b/tests/preflight_parser/fixture/anc_files_1/NOBEL_PRIZE_WINNER.TEX @@ -0,0 +1,15 @@ +%! Author = ntai +%! Date = 2/14/24 + +% Preamble +\documentclass[11pt]{article} + +% Packages +\usepackage{amsmath} + +% Document +\begin{document} + + + +\end{document} diff --git a/tests/preflight_parser/fixture/anc_files_1/anc/foo.cpp b/tests/preflight_parser/fixture/anc_files_1/anc/foo.cpp new file mode 100644 index 0000000..e69de29 diff --git a/tests/preflight_parser/fixture/anc_files_1/anc/subdir/data.csv b/tests/preflight_parser/fixture/anc_files_1/anc/subdir/data.csv new file mode 100644 index 0000000..e69de29 diff --git a/tests/preflight_parser/test_preflight.py b/tests/preflight_parser/test_preflight.py index 89c90fc..ab05f87 100644 --- a/tests/preflight_parser/test_preflight.py +++ b/tests/preflight_parser/test_preflight.py @@ -170,3 +170,15 @@ def test_preflight_html_only_submission(self): """{"engine": "unknown", "lang": "html", "output": "unknown", "postp": "none"}""", ) self.assertEqual(pf.detected_toplevel_files[0].process.compiler.compiler_string, "html_submission") + + def test_anc_files_submission(self): + """Test submission with ancillary files.""" + dir_path = os.path.join(self.fixture_dir, "anc_files_1") + pf: PreflightResponse = generate_preflight_response(dir_path) + self.assertEqual(pf.status.key.value, "success") + self.assertEqual(len(pf.detected_toplevel_files), 1) + self.assertEqual( + pf.detected_toplevel_files[0].process.compiler.json(exclude_none=True, exclude_defaults=True), + """{"engine": "tex", "lang": "latex", "output": "pdf", "postp": "none"}""", + ) + self.assertEqual(len(pf.ancillary_files), 2) diff --git a/tex2pdf/preflight_parser/__init__.py b/tex2pdf/preflight_parser/__init__.py index c7bdcaa..c121c4d 100644 --- a/tex2pdf/preflight_parser/__init__.py +++ b/tex2pdf/preflight_parser/__init__.py @@ -714,6 +714,7 @@ class PreflightResponse(BaseModel): status: PreflightStatus detected_toplevel_files: list[ToplevelFile] tex_files: list[ParsedTeXFile] + ancillary_files: list[str] def to_json(self, **kwargs: typing.Any) -> str: """Return a json representation.""" @@ -956,12 +957,14 @@ def parse_file(basedir: str, filename: str) -> ParsedTeXFile: return n -def parse_dir(rundir: str) -> dict[str, ParsedTeXFile] | ToplevelFile: +def parse_dir(rundir: str) -> tuple[dict[str, ParsedTeXFile] | ToplevelFile, list[str]]: """Parse all TeX files in a directory.""" files = glob.glob(f"{rundir}/**/*", recursive=True) # strip rundir/ prefix n = len(rundir) + 1 files = [f[n:] for f in files if os.path.isfile(f)] + # ancillary files + anc_files = [t for t in files if t.startswith("anc/")] # files = os.listdir(rundir) # needs more extensions that we support tex_files = [t for t in files if os.path.splitext(t)[1].lower() in PARSED_FILE_EXTENSIONS] @@ -971,17 +974,17 @@ def parse_dir(rundir: str) -> dict[str, ParsedTeXFile] | ToplevelFile: # PDF only submission, only one PDF file, nothing else return ToplevelFile( filename=files[0], process=MainProcessSpec(compiler=CompilerSpec(compiler=PDF_SUBMISSION_STRING)) - ) + ), anc_files else: # check for HTML submissions for f in sorted(files): if f.lower().endswith(".html"): return ToplevelFile( filename=f, process=MainProcessSpec(compiler=CompilerSpec(compiler=HTML_SUBMISSION_STRING)) - ) + ), anc_files nodes = {f: parse_file(rundir, f) for f in tex_files} # print(nodes) - return nodes + return nodes, anc_files def kpse_search_files(basedir: str, nodes: dict[str, ParsedTeXFile]) -> dict[str, str]: @@ -1162,10 +1165,13 @@ def deal_with_bibliographies( def _generate_preflight_response_dict(rundir: str) -> PreflightResponse: """Parse submission and generated preflight response as dictionary.""" # parse files - n: dict[str, ParsedTeXFile] | ToplevelFile = parse_dir(rundir) + n: dict[str, ParsedTeXFile] | ToplevelFile + anc_files: list[str] nodes: dict[str, ParsedTeXFile] roots: dict[str, ParsedTeXFile] toplevel_files: dict[str, ToplevelFile] + + n, anc_files = parse_dir(rundir) if isinstance(n, ToplevelFile): # pdf only submission, we received the toplevel file already toplevel_files = {n.filename: n} @@ -1196,6 +1202,7 @@ def _generate_preflight_response_dict(rundir: str) -> PreflightResponse: status=status, detected_toplevel_files=[tl for tl in toplevel_files.values()], tex_files=[n for n in nodes.values()], + ancillary_files=anc_files, ) @@ -1208,6 +1215,7 @@ def generate_preflight_response(rundir: str, json: bool = False, **kwargs: typin status=PreflightStatus(key=PreflightStatusValues.error, info=str(e)), detected_toplevel_files=[], tex_files=[], + ancillary_files=[], ) if json: return pfr.to_json(**kwargs)