diff --git a/.gitignore b/.gitignore index 15f3203..19cd598 100644 --- a/.gitignore +++ b/.gitignore @@ -178,6 +178,7 @@ rendercv/vendor/TinyTeX/texmf-var/luatex-cache/ tests/outputs/ tests/inputs/personal.json tests/inputs/personal.yaml +personal.yaml output/ # VSCode diff --git a/rendercv/__init__.py b/rendercv/__init__.py index 2dff56a..c1c7360 100644 --- a/rendercv/__init__.py +++ b/rendercv/__init__.py @@ -5,6 +5,8 @@ mistakes, checks if the dates are consistent, etc.). Then, with the data, it cre $\LaTeX$ file and renders it with [TinyTeX](https://yihui.org/tinytex/). """ import logging +import os +import sys class LoggingFormatter(logging.Formatter): @@ -34,9 +36,10 @@ class LoggingFormatter(logging.Formatter): formatter = logging.Formatter(log_fmt) return formatter.format(record) - +os.system('COLOR 0') # enable colors in Windows terminal logger = logging.getLogger() logger.setLevel(logging.DEBUG) stdout_handler = logging.StreamHandler() stdout_handler.setFormatter(LoggingFormatter()) logger.addHandler(stdout_handler) +sys.tracebacklimit = -1 \ No newline at end of file diff --git a/rendercv/__main__.py b/rendercv/__main__.py index cb12757..223579e 100644 --- a/rendercv/__main__.py +++ b/rendercv/__main__.py @@ -4,16 +4,18 @@ import os from .rendering import read_input_file, render_template, run_latex -def main(): +def main(input_file_path=None): if len(sys.argv) < 2: - raise ValueError("Please provide the input file path.") + if input_file_path is None: + raise ValueError("Please provide the input file path.") elif len(sys.argv) == 2: input_file_path = sys.argv[1] else: - raise ValueError( - "More than one input is provided. Please provide only one input, which is" - " the input file path." - ) + if input_file_path is None: + raise ValueError( + "More than one input is provided. Please provide only one input, which is" + " the input file path." + ) file_path = os.path.join(os.getcwd(), input_file_path) data = read_input_file(file_path) diff --git a/rendercv/rendering.py b/rendercv/rendering.py index e816e4f..88f4544 100644 --- a/rendercv/rendering.py +++ b/rendercv/rendering.py @@ -428,7 +428,7 @@ def run_latex(latex_file_path: str) -> str: ], cwd=os.path.dirname(latex_file_path), check=True, - # stdout=subprocess.DEVNULL, # suppress latexmk output + stdout=subprocess.DEVNULL, # suppress latexmk output timeout=45, ) except subprocess.CalledProcessError or subprocess.TimeoutExpired as e: diff --git a/run_rendercv.py b/run_rendercv.py index 639aa1d..2aea5b8 100644 --- a/run_rendercv.py +++ b/run_rendercv.py @@ -1,14 +1,9 @@ -""" -This module is a script to run the RenderCV and generate a CV as a PDF. -""" - -import os - - import rendercv.__main__ as rendercv -input_name = "personal" -workspace = os.path.dirname(__file__) -file_path = os.path.join(workspace, "tests", "inputs", f"{input_name}.yaml") +input_file_path = "personal.yaml" +rendercv.main(input_file_path) -rendercv.main(args=[file_path]) +# This script is equivalent to running the following command in the terminal: +# python -m rendercv personal.yaml +# or +# rendercv personal.yaml \ No newline at end of file diff --git a/tests/test_rendering.py b/tests/test_rendering.py index 032e4e4..562f1b1 100644 --- a/tests/test_rendering.py +++ b/tests/test_rendering.py @@ -485,7 +485,7 @@ class TestRendering(unittest.TestCase): ): rendering.run_latex(nonexistent_latex_file_path) - def test_main(self): + def test_entry_point(self): # Change the working directory to the root of the project: workspace_path = os.path.dirname(os.path.dirname(__file__)) @@ -515,3 +515,15 @@ class TestRendering(unittest.TestCase): reference_pdf_file_size, pdf_file_size ) self.assertTrue(ratio > 0.99, msg="PDF file didn't match the reference.") + + # Wrong input: + with self.subTest(msg="Wrong input"): + with self.assertRaises(ValueError, msg="Value error didn't raise."): + subprocess.run( + [ + sys.executable, + "-m", + "rendercv", + "wrong_input.yaml", + ], + )