make run_rendercv.py work

This commit is contained in:
Sina Atalay 2023-10-18 20:00:41 +02:00
parent a9a004ab04
commit 0ec1ef1ee2
6 changed files with 33 additions and 20 deletions

1
.gitignore vendored
View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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:

View File

@ -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

View File

@ -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",
],
)