From 1e18bb89bc5fa648342ea1a03110d03218555c34 Mon Sep 17 00:00:00 2001 From: TeeVahReeeeeen Date: Thu, 4 Jul 2024 11:05:46 +0100 Subject: [PATCH 01/16] test1 --- in2lambda/json_convert/minimal_template.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/in2lambda/json_convert/minimal_template.json b/in2lambda/json_convert/minimal_template.json index dfef133..356d08e 100644 --- a/in2lambda/json_convert/minimal_template.json +++ b/in2lambda/json_convert/minimal_template.json @@ -22,5 +22,5 @@ "displayStructuredTutorial": true, "displayWorkedSolution": true }, - "title": "Question title here" + "title": "Question title here test" } From 32b973431e511be66e493524ec0df41cff37b77f Mon Sep 17 00:00:00 2001 From: TeeVahReeeeeen Date: Thu, 4 Jul 2024 11:06:43 +0100 Subject: [PATCH 02/16] test2 --- in2lambda/json_convert/json_convert.py | 2 +- in2lambda/json_convert/minimal_template.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/in2lambda/json_convert/json_convert.py b/in2lambda/json_convert/json_convert.py index 40862c2..54df5a3 100644 --- a/in2lambda/json_convert/json_convert.py +++ b/in2lambda/json_convert/json_convert.py @@ -50,7 +50,7 @@ def converter( ) # Output file - filename = "question_" + str(i + 1) + filename = "question_" + str(i + 1) + "test" # create directory to put the questions os.makedirs(output_dir, exist_ok=True) diff --git a/in2lambda/json_convert/minimal_template.json b/in2lambda/json_convert/minimal_template.json index 356d08e..dfef133 100644 --- a/in2lambda/json_convert/minimal_template.json +++ b/in2lambda/json_convert/minimal_template.json @@ -22,5 +22,5 @@ "displayStructuredTutorial": true, "displayWorkedSolution": true }, - "title": "Question title here test" + "title": "Question title here" } From 3073b2cef994c98667077dd057c9860799a9a975 Mon Sep 17 00:00:00 2001 From: TeeVahReeeeeen Date: Thu, 4 Jul 2024 11:38:21 +0100 Subject: [PATCH 03/16] more testing --- in2lambda/json_convert/json_convert.py | 8 ++++---- in2lambda/json_convert/minimal_template.json | 10 ++++------ 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/in2lambda/json_convert/json_convert.py b/in2lambda/json_convert/json_convert.py index 54df5a3..eb0a268 100644 --- a/in2lambda/json_convert/json_convert.py +++ b/in2lambda/json_convert/json_convert.py @@ -29,9 +29,9 @@ def converter( # add title to the question file if ListQuestions[i].title != "": - output["title"] = ListQuestions[i].title + output["title"] = ListQuestions[i].title + "test" else: - output["title"] = "Question " + str(i + 1) + output["title"] = "Question " + str(i + 1) + "test" # add main text to the question file output["masterContent"] = ListQuestions[i].main_text @@ -58,7 +58,7 @@ def converter( os.makedirs(output_question, exist_ok=True) # create directory to put image - output_image = os.path.join(output_question, "media") + output_image = os.path.join(output_question, "media" + "test") os.makedirs(output_image, exist_ok=True) # write questions into directory @@ -73,7 +73,7 @@ def converter( shutil.copy(image_path, output_image) # copies image into the directory # output zip file in destination folder - shutil.make_archive(output_question, "zip", output_question) + shutil.make_archive(output_question + "test", "zip", output_question) def main(questions: list[Question], output_dir: str) -> None: diff --git a/in2lambda/json_convert/minimal_template.json b/in2lambda/json_convert/minimal_template.json index dfef133..3b1d920 100644 --- a/in2lambda/json_convert/minimal_template.json +++ b/in2lambda/json_convert/minimal_template.json @@ -4,7 +4,7 @@ { "answer": "", "content": "Part text here", - "responseArea": [], + "responseAreas": [], "tutorial": [], "universalPartId": "N/A", "workedSolution": [ @@ -17,10 +17,8 @@ } ], "publish": false, - "questionSettings": { - "displayFinalAnswer": true, - "displayStructuredTutorial": true, - "displayWorkedSolution": true - }, + "displayFinalAnswer": true, + "displayStructuredTutorial": true, + "displayWorkedSolution": true, "title": "Question title here" } From 9fdbd8039da0713b313eb7d709e0f87f55ca07a4 Mon Sep 17 00:00:00 2001 From: TeeVahReeeeeen Date: Thu, 4 Jul 2024 13:47:00 +0100 Subject: [PATCH 04/16] finally working? --- in2lambda/json_convert/json_convert.py | 30 +++++++++++--------- in2lambda/json_convert/minimal_template.json | 18 ++++++------ in2lambda/main.py | 5 ++++ 3 files changed, 29 insertions(+), 24 deletions(-) diff --git a/in2lambda/json_convert/json_convert.py b/in2lambda/json_convert/json_convert.py index eb0a268..01b6487 100644 --- a/in2lambda/json_convert/json_convert.py +++ b/in2lambda/json_convert/json_convert.py @@ -24,14 +24,24 @@ def converter( """ # Create output by copying template + # create directory to put the questions + os.makedirs(output_dir, exist_ok=True) + output_question = os.path.join(output_dir, "set") + os.makedirs(output_question, exist_ok=True) + + + # create directory to put images - should be in set + output_image = os.path.join(output_question, "media") + os.makedirs(output_image, exist_ok=True) + for i in range(len(ListQuestions)): output = deepcopy(template) # add title to the question file if ListQuestions[i].title != "": - output["title"] = ListQuestions[i].title + "test" + output["title"] = ListQuestions[i].title else: - output["title"] = "Question " + str(i + 1) + "test" + output["title"] = "Question " + str(i + 1) # add main text to the question file output["masterContent"] = ListQuestions[i].main_text @@ -39,27 +49,19 @@ def converter( # add parts to the question file if ListQuestions[i].parts: output["parts"][0]["content"] = ListQuestions[i].parts[0].text - output["parts"][0]["workedSolution"][0]["content"] = ( + output["parts"][0]["workedSolution"]["content"] = ( ListQuestions[i].parts[0].worked_solution ) for j in range(1, len(ListQuestions[i].parts)): output["parts"].append(deepcopy(template["parts"][0])) output["parts"][j]["content"] = ListQuestions[i].parts[j].text - output["parts"][j]["workedSolution"][0]["content"] = ( + output["parts"][j]["workedSolution"]["content"] = ( ListQuestions[i].parts[j].worked_solution ) # Output file - filename = "question_" + str(i + 1) + "test" - - # create directory to put the questions - os.makedirs(output_dir, exist_ok=True) - output_question = os.path.join(output_dir, filename) - os.makedirs(output_question, exist_ok=True) + filename = "question_" + str(i + 1) - # create directory to put image - output_image = os.path.join(output_question, "media" + "test") - os.makedirs(output_image, exist_ok=True) # write questions into directory with open(f"{output_question}/{filename}.json", "w") as file: @@ -73,7 +75,7 @@ def converter( shutil.copy(image_path, output_image) # copies image into the directory # output zip file in destination folder - shutil.make_archive(output_question + "test", "zip", output_question) + shutil.make_archive(output_question, "zip", output_question) def main(questions: list[Question], output_dir: str) -> None: diff --git a/in2lambda/json_convert/minimal_template.json b/in2lambda/json_convert/minimal_template.json index 3b1d920..8b4896b 100644 --- a/in2lambda/json_convert/minimal_template.json +++ b/in2lambda/json_convert/minimal_template.json @@ -1,5 +1,10 @@ { + "title": "Question title here", "masterContent": "Top level question here", + "publish": false, + "displayFinalAnswer": true, + "displayStructuredTutorial": true, + "displayWorkedSolution": true, "parts": [ { "answer": "", @@ -7,18 +12,11 @@ "responseAreas": [], "tutorial": [], "universalPartId": "N/A", - "workedSolution": [ - { + "workedSolution": { "content": "Part worked solution here", "id": "N/A", "title": "" - } - ] + } } - ], - "publish": false, - "displayFinalAnswer": true, - "displayStructuredTutorial": true, - "displayWorkedSolution": true, - "title": "Question title here" + ] } diff --git a/in2lambda/main.py b/in2lambda/main.py index 32ccc8c..82678a7 100644 --- a/in2lambda/main.py +++ b/in2lambda/main.py @@ -1,5 +1,10 @@ """The main input for in2lambda, defining both the CLT and main library function.""" +import sys +import os +sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) + + import importlib import pkgutil from typing import Optional From e3531106dc034258762dc6994c4616f945bda355 Mon Sep 17 00:00:00 2001 From: Tom W Date: Sun, 7 Jul 2024 15:41:14 +0100 Subject: [PATCH 05/16] made .docx files work --- in2lambda/main.py | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/in2lambda/main.py b/in2lambda/main.py index 82678a7..15ce5ee 100644 --- a/in2lambda/main.py +++ b/in2lambda/main.py @@ -15,6 +15,12 @@ import in2lambda.filters from in2lambda.api.module import Module +import subprocess + + +def docx_to_md(docx_file: str) -> str: + md_output = subprocess.check_output(['pandoc', docx_file, '-t', 'markdown']) + return md_output.decode('utf-8') def file_type(file: str) -> str: """Determines which pandoc file format to use for a given file. @@ -95,14 +101,21 @@ def runner( # Dynamically import the correct pandoc filter depending on the subject. filter_module = importlib.import_module(f"in2lambda.filters.{chosen_filter}.filter") - with open(question_file, "r", encoding="utf-8") as file: - text = file.read() + + if file_type(question_file) == 'docx': + # Convert .docx to md using Pandoc + text = docx_to_md(question_file) + input_format = "markdown" + else: + with open(question_file, "r", encoding="utf-8") as file: + text = file.read() + input_format=file_type(question_file) # Parse the Pandoc AST using the relevant panflute filter. pf.run_filter( filter_module.pandoc_filter, doc=pf.convert_text( - text, input_format=file_type(question_file), standalone=True + text, input_format=input_format, standalone=True ), module=module, tex_file=question_file, @@ -111,13 +124,18 @@ def runner( # If separate answer TeX file provided, parse that as well. if answer_file: - with open(answer_file, "r", encoding="utf-8") as file: - answer_text = file.read() + if file_type(answer_file) == 'docx': + answer_text = docx_to_md(answer_file) + answer_format = "markdown" + else: + with open(answer_file, "r", encoding="utf-8") as file: + answer_text = file.read() + answer_format = file_type(answer_file) pf.run_filter( filter_module.pandoc_filter, doc=pf.convert_text( - answer_text, input_format=file_type(answer_file), standalone=True + answer_text, input_format=answer_format, standalone=True ), module=module, tex_file=answer_file, @@ -177,3 +195,8 @@ def cli( if __name__ == "__main__": cli() +#%% + +# import panflute as pf + +# pf.convert_text("PS/TestQ.docx", input_format="docx", standalone=True) From f1ec6eca06ea0523bfa88c05567fb244f1114be0 Mon Sep 17 00:00:00 2001 From: TeeVahReeeeeen Date: Mon, 8 Jul 2024 13:38:57 +0100 Subject: [PATCH 06/16] removed local running thingy --- in2lambda/main.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/in2lambda/main.py b/in2lambda/main.py index 15ce5ee..4de0861 100644 --- a/in2lambda/main.py +++ b/in2lambda/main.py @@ -1,8 +1,8 @@ """The main input for in2lambda, defining both the CLT and main library function.""" -import sys -import os -sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) +# import sys +# import os +# sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) import importlib From fb87caecc0fb499b5215a93a0fafa983cb6eb61f Mon Sep 17 00:00:00 2001 From: TeeVahReeeeeen Date: Mon, 8 Jul 2024 13:47:43 +0100 Subject: [PATCH 07/16] Added comments --- in2lambda/main.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/in2lambda/main.py b/in2lambda/main.py index 4de0861..0a39793 100644 --- a/in2lambda/main.py +++ b/in2lambda/main.py @@ -1,5 +1,7 @@ """The main input for in2lambda, defining both the CLT and main library function.""" +#This commented block makes it run the local files rather than the pip library (I think, I don't understand it. Kevin wrote it.) +# # import sys # import os # sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) @@ -17,7 +19,7 @@ import subprocess - +#Converts .docx files to markdown def docx_to_md(docx_file: str) -> str: md_output = subprocess.check_output(['pandoc', docx_file, '-t', 'markdown']) return md_output.decode('utf-8') @@ -63,7 +65,7 @@ def file_type(file: str) -> str: ): return "markdown" case "docx": - return "docx" # Pandoc doesn't seem to support doc + return "docx" # Pandoc doesn't seem to support .doc, and panflute doesn't like .docx. raise RuntimeError(f"Unsupported file extension: .{extension}") @@ -103,7 +105,7 @@ def runner( if file_type(question_file) == 'docx': - # Convert .docx to md using Pandoc + # Convert .docx to md using Pandoc and proceed text = docx_to_md(question_file) input_format = "markdown" else: @@ -195,8 +197,3 @@ def cli( if __name__ == "__main__": cli() -#%% - -# import panflute as pf - -# pf.convert_text("PS/TestQ.docx", input_format="docx", standalone=True) From 0ee251a19b65af3002784bc6be6fcecd2904b1b2 Mon Sep 17 00:00:00 2001 From: TeeVahReeeeeen Date: Mon, 8 Jul 2024 15:21:43 +0100 Subject: [PATCH 08/16] Reformatted code with Black --- in2lambda/json_convert/json_convert.py | 2 -- in2lambda/main.py | 23 +++++++++++------------ 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/in2lambda/json_convert/json_convert.py b/in2lambda/json_convert/json_convert.py index 01b6487..07720f3 100644 --- a/in2lambda/json_convert/json_convert.py +++ b/in2lambda/json_convert/json_convert.py @@ -29,7 +29,6 @@ def converter( output_question = os.path.join(output_dir, "set") os.makedirs(output_question, exist_ok=True) - # create directory to put images - should be in set output_image = os.path.join(output_question, "media") os.makedirs(output_image, exist_ok=True) @@ -62,7 +61,6 @@ def converter( # Output file filename = "question_" + str(i + 1) - # write questions into directory with open(f"{output_question}/{filename}.json", "w") as file: json.dump(output, file) diff --git a/in2lambda/main.py b/in2lambda/main.py index 0a39793..d3237bf 100644 --- a/in2lambda/main.py +++ b/in2lambda/main.py @@ -1,11 +1,11 @@ """The main input for in2lambda, defining both the CLT and main library function.""" -#This commented block makes it run the local files rather than the pip library (I think, I don't understand it. Kevin wrote it.) +# This commented block makes it run the local files rather than the pip library (I think, I don't understand it. Kevin wrote it.) # # import sys # import os # sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) - + import importlib import pkgutil @@ -19,10 +19,12 @@ import subprocess -#Converts .docx files to markdown + +# Converts .docx files to markdown def docx_to_md(docx_file: str) -> str: - md_output = subprocess.check_output(['pandoc', docx_file, '-t', 'markdown']) - return md_output.decode('utf-8') + md_output = subprocess.check_output(["pandoc", docx_file, "-t", "markdown"]) + return md_output.decode("utf-8") + def file_type(file: str) -> str: """Determines which pandoc file format to use for a given file. @@ -103,22 +105,19 @@ def runner( # Dynamically import the correct pandoc filter depending on the subject. filter_module = importlib.import_module(f"in2lambda.filters.{chosen_filter}.filter") - - if file_type(question_file) == 'docx': + if file_type(question_file) == "docx": # Convert .docx to md using Pandoc and proceed text = docx_to_md(question_file) input_format = "markdown" else: with open(question_file, "r", encoding="utf-8") as file: text = file.read() - input_format=file_type(question_file) + input_format = file_type(question_file) # Parse the Pandoc AST using the relevant panflute filter. pf.run_filter( filter_module.pandoc_filter, - doc=pf.convert_text( - text, input_format=input_format, standalone=True - ), + doc=pf.convert_text(text, input_format=input_format, standalone=True), module=module, tex_file=question_file, parsing_answers=False, @@ -126,7 +125,7 @@ def runner( # If separate answer TeX file provided, parse that as well. if answer_file: - if file_type(answer_file) == 'docx': + if file_type(answer_file) == "docx": answer_text = docx_to_md(answer_file) answer_format = "markdown" else: From efb98ce2dbbb53b2cd29cf13856fae1e748f8a3f Mon Sep 17 00:00:00 2001 From: TeeVahReeeeeen <40565892+TeeVahReeeeeen@users.noreply.github.com> Date: Mon, 8 Jul 2024 15:40:16 +0100 Subject: [PATCH 09/16] Update main.py --- in2lambda/main.py | 1 - 1 file changed, 1 deletion(-) diff --git a/in2lambda/main.py b/in2lambda/main.py index ee8093a..199f6f3 100644 --- a/in2lambda/main.py +++ b/in2lambda/main.py @@ -1,6 +1,5 @@ """The main input for in2lambda, defining both the CLT and main library function.""" - # This commented block makes it run the local files rather than the pip library (I think, I don't understand it. Kevin wrote it.) # # import sys From 6793d01451805407b26a69ade7cc94fac390767a Mon Sep 17 00:00:00 2001 From: TeeVahReeeeeen Date: Mon, 8 Jul 2024 15:47:21 +0100 Subject: [PATCH 10/16] formatted properly --- in2lambda/main.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/in2lambda/main.py b/in2lambda/main.py index 199f6f3..12005a9 100644 --- a/in2lambda/main.py +++ b/in2lambda/main.py @@ -18,10 +18,12 @@ import subprocess -#Converts .docx files to markdown + +# Converts .docx files to markdown def docx_to_md(docx_file: str) -> str: - md_output = subprocess.check_output(['pandoc', docx_file, '-t', 'markdown']) - return md_output.decode('utf-8') + md_output = subprocess.check_output(["pandoc", docx_file, "-t", "markdown"]) + return md_output.decode("utf-8") + def file_type(file: str) -> str: """Determines which pandoc file format to use for a given file. @@ -102,7 +104,7 @@ def runner( # Dynamically import the correct pandoc filter depending on the subject. filter_module = importlib.import_module(f"in2lambda.filters.{chosen_filter}.filter") - if file_type(question_file) == 'docx': + if file_type(question_file) == "docx": # Convert .docx to md using Pandoc and proceed text = docx_to_md(question_file) input_format = "markdown" @@ -115,9 +117,7 @@ def runner( # Parse the Pandoc AST using the relevant panflute filter. pf.run_filter( filter_module.pandoc_filter, - doc=pf.convert_text( - text, input_format=input_format, standalone=True - ), + doc=pf.convert_text(text, input_format=input_format, standalone=True), module=module, tex_file=question_file, parsing_answers=False, @@ -126,7 +126,7 @@ def runner( # If separate answer TeX file provided, parse that as well. if answer_file: - if file_type(answer_file) == 'docx': + if file_type(answer_file) == "docx": answer_text = docx_to_md(answer_file) answer_format = "markdown" From 95ab4b1255fe5ed032a7563757ef57b87cbbbb1c Mon Sep 17 00:00:00 2001 From: TeeVahReeeeeen Date: Mon, 8 Jul 2024 15:47:21 +0100 Subject: [PATCH 11/16] formatted properly #2 --- in2lambda/main.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/in2lambda/main.py b/in2lambda/main.py index 199f6f3..15a781c 100644 --- a/in2lambda/main.py +++ b/in2lambda/main.py @@ -8,6 +8,7 @@ import importlib import pkgutil +import subprocess from typing import Optional import panflute as pf @@ -16,12 +17,12 @@ import in2lambda.filters from in2lambda.api.module import Module -import subprocess -#Converts .docx files to markdown +# Converts .docx files to markdown def docx_to_md(docx_file: str) -> str: - md_output = subprocess.check_output(['pandoc', docx_file, '-t', 'markdown']) - return md_output.decode('utf-8') + md_output = subprocess.check_output(["pandoc", docx_file, "-t", "markdown"]) + return md_output.decode("utf-8") + def file_type(file: str) -> str: """Determines which pandoc file format to use for a given file. @@ -102,7 +103,7 @@ def runner( # Dynamically import the correct pandoc filter depending on the subject. filter_module = importlib.import_module(f"in2lambda.filters.{chosen_filter}.filter") - if file_type(question_file) == 'docx': + if file_type(question_file) == "docx": # Convert .docx to md using Pandoc and proceed text = docx_to_md(question_file) input_format = "markdown" @@ -115,9 +116,7 @@ def runner( # Parse the Pandoc AST using the relevant panflute filter. pf.run_filter( filter_module.pandoc_filter, - doc=pf.convert_text( - text, input_format=input_format, standalone=True - ), + doc=pf.convert_text(text, input_format=input_format, standalone=True), module=module, tex_file=question_file, parsing_answers=False, @@ -126,7 +125,7 @@ def runner( # If separate answer TeX file provided, parse that as well. if answer_file: - if file_type(answer_file) == 'docx': + if file_type(answer_file) == "docx": answer_text = docx_to_md(answer_file) answer_format = "markdown" From 2b8c3d5b7ab53952e502f0fcfe651b5b55afe32b Mon Sep 17 00:00:00 2001 From: TeeVahReeeeeen Date: Tue, 9 Jul 2024 08:46:37 +0100 Subject: [PATCH 12/16] format --- in2lambda/main.py | 1 - 1 file changed, 1 deletion(-) diff --git a/in2lambda/main.py b/in2lambda/main.py index 095669b..135402e 100644 --- a/in2lambda/main.py +++ b/in2lambda/main.py @@ -18,7 +18,6 @@ from in2lambda.api.module import Module - # Converts .docx files to markdown def docx_to_md(docx_file: str) -> str: md_output = subprocess.check_output(["pandoc", docx_file, "-t", "markdown"]) From 17fdea9404d27be14d6dfcdd980bafeed0034d3c Mon Sep 17 00:00:00 2001 From: TeeVahReeeeeen Date: Tue, 9 Jul 2024 08:46:37 +0100 Subject: [PATCH 13/16] docstring --- in2lambda/main.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/in2lambda/main.py b/in2lambda/main.py index 095669b..92b31bc 100644 --- a/in2lambda/main.py +++ b/in2lambda/main.py @@ -18,9 +18,13 @@ from in2lambda.api.module import Module - -# Converts .docx files to markdown def docx_to_md(docx_file: str) -> str: + """Converts .docx files to markdown + Args: + docx_file: A file path with the file extension included + Returns: + the contents of the .docx file in markdown formatting + """ md_output = subprocess.check_output(["pandoc", docx_file, "-t", "markdown"]) return md_output.decode("utf-8") From 63cf25f546160851edcc0c77d86a143dbeb5c10d Mon Sep 17 00:00:00 2001 From: TeeVahReeeeeen Date: Tue, 9 Jul 2024 08:57:44 +0100 Subject: [PATCH 14/16] format :( --- in2lambda/main.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/in2lambda/main.py b/in2lambda/main.py index 100f969..86f37a9 100644 --- a/in2lambda/main.py +++ b/in2lambda/main.py @@ -17,12 +17,13 @@ import in2lambda.filters from in2lambda.api.module import Module + def docx_to_md(docx_file: str) -> str: """Converts .docx files to markdown Args: docx_file: A file path with the file extension included Returns: - the contents of the .docx file in markdown formatting + the contents of the .docx file in markdown formatting """ md_output = subprocess.check_output(["pandoc", docx_file, "-t", "markdown"]) return md_output.decode("utf-8") From 51a57e541082a78709ce1b18a56e555bf1f8e750 Mon Sep 17 00:00:00 2001 From: TeeVahReeeeeen Date: Tue, 9 Jul 2024 08:57:44 +0100 Subject: [PATCH 15/16] format --- in2lambda/main.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/in2lambda/main.py b/in2lambda/main.py index 100f969..df2ef64 100644 --- a/in2lambda/main.py +++ b/in2lambda/main.py @@ -17,12 +17,15 @@ import in2lambda.filters from in2lambda.api.module import Module + def docx_to_md(docx_file: str) -> str: - """Converts .docx files to markdown + """Converts .docx files to markdown. + Args: - docx_file: A file path with the file extension included + docx_file: A file path with the file extension included. + Returns: - the contents of the .docx file in markdown formatting + the contents of the .docx file in markdown formatting. """ md_output = subprocess.check_output(["pandoc", docx_file, "-t", "markdown"]) return md_output.decode("utf-8") From 40ac8105eacd6e7bb9479a74c5b9ebee98bd21da Mon Sep 17 00:00:00 2001 From: TeeVahReeeeeen Date: Tue, 9 Jul 2024 11:32:37 +0100 Subject: [PATCH 16/16] gettings tests to work --- in2lambda/api/module.py | 7 +++++-- in2lambda/filters/markdown.py | 6 +++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/in2lambda/api/module.py b/in2lambda/api/module.py index 96dcb3d..0cf404d 100644 --- a/in2lambda/api/module.py +++ b/in2lambda/api/module.py @@ -112,10 +112,13 @@ def to_json(self, output_dir: str) -> None: ... module.to_json(temp_dir) ... # Check the contents of the directory ... sorted(os.listdir(temp_dir)) + ... # Check the contents of the set directory + ... sorted(os.listdir(f"{temp_dir}/set")) ... # Check the title of the first question - ... with open(f"{temp_dir}/question_1/question_1.json") as file: + ... with open(f"{temp_dir}/set/question_1.json") as file: ... print(f"Question 1's title: {json.load(file)['title']}") - ['question_1', 'question_1.zip', 'question_2', 'question_2.zip'] + ['set', 'set.zip'] + ['media', 'question_1.json', 'question_2.json'] Question 1's title: Question 1 """ diff --git a/in2lambda/filters/markdown.py b/in2lambda/filters/markdown.py index 3a2a086..b285b7a 100644 --- a/in2lambda/filters/markdown.py +++ b/in2lambda/filters/markdown.py @@ -32,12 +32,12 @@ def image_directories(tex_file: str) -> list[str]: >>> temp_dir = tempfile.mkdtemp() >>> tex_file = os.path.join(temp_dir, 'test.tex') >>> with open(tex_file, 'w') as f: - ... f.write("\graphicspath{{subdir1/}{subdir2/}{subdir3/}}") + ... f.write("\\graphicspath{{subdir1/}{subdir2/}{subdir3/}}") 45 >>> image_directories(tex_file) ['subdir1/', 'subdir2/', 'subdir3/'] >>> with open(tex_file, 'w') as f: - ... f.write("\graphicspath{ { subdir1/ }, { subdir2/ }, { subdir3/ } }") + ... f.write("\\graphicspath{ { subdir1/ }, { subdir2/ }, { subdir3/ } }") 57 >>> image_directories.cache_clear() >>> image_directories(tex_file) @@ -78,7 +78,7 @@ def image_path(image_name: str, tex_file: str) -> Optional[str]: >>> temp_dir = tempfile.mkdtemp() >>> tex_file = os.path.join(temp_dir, 'test.tex') >>> with open(tex_file, 'w') as f: - ... f.write("\graphicspath{{./subdir1/}{./subdir2/}{./subdir3/}}") + ... f.write("\\graphicspath{{./subdir1/}{./subdir2/}{./subdir3/}}") 51 >>> # Example image in a relative subdirectory >>> sub_dir = os.path.join(temp_dir, 'subdir3')