From 3458dce5401ee5ea5789f62123dab7a01f70c0cf Mon Sep 17 00:00:00 2001 From: Norbert Preining Date: Sat, 7 Dec 2024 10:16:03 +0900 Subject: [PATCH 1/4] Detect and report HTML submissions --- preflight_parser/preflight_parser/__init__.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/preflight_parser/preflight_parser/__init__.py b/preflight_parser/preflight_parser/__init__.py index 6aa2b20..24e059b 100644 --- a/preflight_parser/preflight_parser/__init__.py +++ b/preflight_parser/preflight_parser/__init__.py @@ -62,6 +62,8 @@ class LanguageType(str, Enum): TEX does not allow compiling as latex, e.g., because it contains \bye LATEX does not allow compiling as plain tex, e.g., because it contains \documentclass + PDF is for PDF only submissions. + HTML is for HTML only submissions. UNKNOWN allows compilation as either TEX or LATEX. """ @@ -69,6 +71,7 @@ class LanguageType(str, Enum): tex = "tex" latex = "latex" pdf = "pdf" + html = "html" class EngineType(str, Enum): @@ -212,6 +215,8 @@ def compiler_string(self) -> str | None: # first deal with PDF only submissions: if self.lang.value == "pdf": return "pdf_submission" + if self.lang.value == "html": + return "html_submission" if self.lang in self._COMPILER_SELECTION: if self.output in self._COMPILER_SELECTION[self.lang]: if self.engine in self._COMPILER_SELECTION[self.lang][self.output]: @@ -244,6 +249,12 @@ def from_compiler_string(self, compiler: str): self.output = OutputType.unknown self.postp = PostProcessType.none return + if compiler == "html_submission": + self.lang = LanguageType.html + self.engine = EngineType.unknown + self.output = OutputType.unknown + self.postp = PostProcessType.none + return parts = compiler.split("+", 1) comp: str = "" if len(parts) == 2: @@ -955,6 +966,9 @@ def parse_dir(rundir) -> dict[str, ParsedTeXFile] | ToplevelFile: return ToplevelFile( filename=files[0], process=MainProcessSpec(compiler=CompilerSpec(compiler="pdf_submission")) ) + else: + # TODO detect HTML submissions + pass nodes = {f: parse_file(rundir, f) for f in tex_files} # print(nodes) return nodes From ca127e4eaf97017db239327742d324b1940b8250 Mon Sep 17 00:00:00 2001 From: Norbert Preining Date: Sat, 7 Dec 2024 13:59:10 +0900 Subject: [PATCH 2/4] Make pdf/html_submission strings a variable --- preflight_parser/preflight_parser/__init__.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/preflight_parser/preflight_parser/__init__.py b/preflight_parser/preflight_parser/__init__.py index 24e059b..85eae17 100644 --- a/preflight_parser/preflight_parser/__init__.py +++ b/preflight_parser/preflight_parser/__init__.py @@ -16,6 +16,9 @@ MODULE_PATH = os.path.dirname(__file__) +PDF_SUBMISSION_STRING = "pdf_submission" +HTML_SUBMISSION_STRING = "html_submission" + # # CLASSES AND TYPES # @@ -214,9 +217,9 @@ def compiler_string(self) -> str | None: """Convert Language/Output/Engine/PostProcess to compiler string.""" # first deal with PDF only submissions: if self.lang.value == "pdf": - return "pdf_submission" + return PDF_SUBMISSION_STRING if self.lang.value == "html": - return "html_submission" + return HTML_SUBMISSION_STRING if self.lang in self._COMPILER_SELECTION: if self.output in self._COMPILER_SELECTION[self.lang]: if self.engine in self._COMPILER_SELECTION[self.lang][self.output]: @@ -234,7 +237,9 @@ def tex_compiler(self) -> str | None: """Return the TeX compiler to be used.""" # first deal with PDF only submissions: if self.lang.value == "pdf": - return "pdf_submission" + return PDF_SUBMISSION_STRING + if self.lang.value == "html": + return HTML_SUBMISSION_STRING if self.lang in self._COMPILER_SELECTION: if self.output in self._COMPILER_SELECTION[self.lang]: if self.engine in self._COMPILER_SELECTION[self.lang][self.output]: @@ -243,13 +248,13 @@ def tex_compiler(self) -> str | None: def from_compiler_string(self, compiler: str): """Convert compiler string to Language/Output/Engine/PostProcess types.""" - if compiler == "pdf_submission": + if compiler == PDF_SUBMISSION_STRING: self.lang = LanguageType.pdf self.engine = EngineType.unknown self.output = OutputType.unknown self.postp = PostProcessType.none return - if compiler == "html_submission": + if compiler == HTML_SUBMISSION_STRING: self.lang = LanguageType.html self.engine = EngineType.unknown self.output = OutputType.unknown @@ -964,7 +969,7 @@ def parse_dir(rundir) -> dict[str, ParsedTeXFile] | ToplevelFile: if len(files) == 1 and files[0].lower().endswith(".pdf"): # PDF only submission, only one PDF file, nothing else return ToplevelFile( - filename=files[0], process=MainProcessSpec(compiler=CompilerSpec(compiler="pdf_submission")) + filename=files[0], process=MainProcessSpec(compiler=CompilerSpec(compiler=PDF_SUBMISSION_STRING)) ) else: # TODO detect HTML submissions From d5a57a0d6412bdc13de0cb9c26dd19d612acf26a Mon Sep 17 00:00:00 2001 From: Norbert Preining Date: Sat, 7 Dec 2024 15:57:56 +0900 Subject: [PATCH 3/4] detect html submissions, add unittest --- preflight_parser/preflight_parser/__init__.py | 8 ++++++-- .../tests/fixture/html_1/figure1.eps | 0 .../tests/fixture/html_1/figure2.png | 0 .../tests/fixture/html_1/figure3.jpg | 0 preflight_parser/tests/fixture/html_1/paper.html | 13 +++++++++++++ preflight_parser/tests/test_preflight.py | 16 ++++++++++++++++ 6 files changed, 35 insertions(+), 2 deletions(-) create mode 100644 preflight_parser/tests/fixture/html_1/figure1.eps create mode 100644 preflight_parser/tests/fixture/html_1/figure2.png create mode 100644 preflight_parser/tests/fixture/html_1/figure3.jpg create mode 100644 preflight_parser/tests/fixture/html_1/paper.html diff --git a/preflight_parser/preflight_parser/__init__.py b/preflight_parser/preflight_parser/__init__.py index 85eae17..5ca1c6c 100644 --- a/preflight_parser/preflight_parser/__init__.py +++ b/preflight_parser/preflight_parser/__init__.py @@ -972,8 +972,12 @@ def parse_dir(rundir) -> dict[str, ParsedTeXFile] | ToplevelFile: filename=files[0], process=MainProcessSpec(compiler=CompilerSpec(compiler=PDF_SUBMISSION_STRING)) ) else: - # TODO detect HTML submissions - pass + # 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)) + ) nodes = {f: parse_file(rundir, f) for f in tex_files} # print(nodes) return nodes diff --git a/preflight_parser/tests/fixture/html_1/figure1.eps b/preflight_parser/tests/fixture/html_1/figure1.eps new file mode 100644 index 0000000..e69de29 diff --git a/preflight_parser/tests/fixture/html_1/figure2.png b/preflight_parser/tests/fixture/html_1/figure2.png new file mode 100644 index 0000000..e69de29 diff --git a/preflight_parser/tests/fixture/html_1/figure3.jpg b/preflight_parser/tests/fixture/html_1/figure3.jpg new file mode 100644 index 0000000..e69de29 diff --git a/preflight_parser/tests/fixture/html_1/paper.html b/preflight_parser/tests/fixture/html_1/paper.html new file mode 100644 index 0000000..903f802 --- /dev/null +++ b/preflight_parser/tests/fixture/html_1/paper.html @@ -0,0 +1,13 @@ + + + +Norbert Preining + + + +
+ Hello World +
+ + + diff --git a/preflight_parser/tests/test_preflight.py b/preflight_parser/tests/test_preflight.py index d99cd80..d1e8089 100644 --- a/preflight_parser/tests/test_preflight.py +++ b/preflight_parser/tests/test_preflight.py @@ -160,3 +160,19 @@ def test_preflight_pdf_only_submission(self): pf.detected_toplevel_files[0].process.compiler.compiler_string, "pdf_submission" ) + + def test_preflight_html_only_submission(self): + """Test HTML only submission.""" + dir_path = os.path.join(self.fixture_dir, "html_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].filename, "paper.html") + self.assertEqual( + pf.detected_toplevel_files[0].process.compiler.json(exclude_none=True, exclude_defaults=True), + """{"engine": "unknown", "lang": "html", "output": "unknown", "postp": "none"}""", + ) + self.assertEqual( + pf.detected_toplevel_files[0].process.compiler.compiler_string, + "html_submission" + ) From da0c16310240a75ae67f785c87d3c970d6005117 Mon Sep 17 00:00:00 2001 From: Norbert Preining Date: Sat, 7 Dec 2024 16:01:58 +0900 Subject: [PATCH 4/4] Fix HTML title --- preflight_parser/tests/fixture/html_1/paper.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/preflight_parser/tests/fixture/html_1/paper.html b/preflight_parser/tests/fixture/html_1/paper.html index 903f802..d8e787d 100644 --- a/preflight_parser/tests/fixture/html_1/paper.html +++ b/preflight_parser/tests/fixture/html_1/paper.html @@ -1,7 +1,7 @@ -Norbert Preining +HTML Submission Test