mirror of https://github.com/eyhc1/rendercv.git
make run_rendercv.py work
This commit is contained in:
parent
a9a004ab04
commit
0ec1ef1ee2
|
@ -178,6 +178,7 @@ rendercv/vendor/TinyTeX/texmf-var/luatex-cache/
|
||||||
tests/outputs/
|
tests/outputs/
|
||||||
tests/inputs/personal.json
|
tests/inputs/personal.json
|
||||||
tests/inputs/personal.yaml
|
tests/inputs/personal.yaml
|
||||||
|
personal.yaml
|
||||||
output/
|
output/
|
||||||
|
|
||||||
# VSCode
|
# VSCode
|
||||||
|
|
|
@ -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/).
|
$\LaTeX$ file and renders it with [TinyTeX](https://yihui.org/tinytex/).
|
||||||
"""
|
"""
|
||||||
import logging
|
import logging
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
class LoggingFormatter(logging.Formatter):
|
class LoggingFormatter(logging.Formatter):
|
||||||
|
@ -34,9 +36,10 @@ class LoggingFormatter(logging.Formatter):
|
||||||
formatter = logging.Formatter(log_fmt)
|
formatter = logging.Formatter(log_fmt)
|
||||||
return formatter.format(record)
|
return formatter.format(record)
|
||||||
|
|
||||||
|
os.system('COLOR 0') # enable colors in Windows terminal
|
||||||
logger = logging.getLogger()
|
logger = logging.getLogger()
|
||||||
logger.setLevel(logging.DEBUG)
|
logger.setLevel(logging.DEBUG)
|
||||||
stdout_handler = logging.StreamHandler()
|
stdout_handler = logging.StreamHandler()
|
||||||
stdout_handler.setFormatter(LoggingFormatter())
|
stdout_handler.setFormatter(LoggingFormatter())
|
||||||
logger.addHandler(stdout_handler)
|
logger.addHandler(stdout_handler)
|
||||||
|
sys.tracebacklimit = -1
|
|
@ -4,12 +4,14 @@ import os
|
||||||
from .rendering import read_input_file, render_template, run_latex
|
from .rendering import read_input_file, render_template, run_latex
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main(input_file_path=None):
|
||||||
if len(sys.argv) < 2:
|
if len(sys.argv) < 2:
|
||||||
|
if input_file_path is None:
|
||||||
raise ValueError("Please provide the input file path.")
|
raise ValueError("Please provide the input file path.")
|
||||||
elif len(sys.argv) == 2:
|
elif len(sys.argv) == 2:
|
||||||
input_file_path = sys.argv[1]
|
input_file_path = sys.argv[1]
|
||||||
else:
|
else:
|
||||||
|
if input_file_path is None:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
"More than one input is provided. Please provide only one input, which is"
|
"More than one input is provided. Please provide only one input, which is"
|
||||||
" the input file path."
|
" the input file path."
|
||||||
|
|
|
@ -428,7 +428,7 @@ def run_latex(latex_file_path: str) -> str:
|
||||||
],
|
],
|
||||||
cwd=os.path.dirname(latex_file_path),
|
cwd=os.path.dirname(latex_file_path),
|
||||||
check=True,
|
check=True,
|
||||||
# stdout=subprocess.DEVNULL, # suppress latexmk output
|
stdout=subprocess.DEVNULL, # suppress latexmk output
|
||||||
timeout=45,
|
timeout=45,
|
||||||
)
|
)
|
||||||
except subprocess.CalledProcessError or subprocess.TimeoutExpired as e:
|
except subprocess.CalledProcessError or subprocess.TimeoutExpired as e:
|
||||||
|
|
|
@ -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
|
import rendercv.__main__ as rendercv
|
||||||
|
|
||||||
input_name = "personal"
|
input_file_path = "personal.yaml"
|
||||||
workspace = os.path.dirname(__file__)
|
rendercv.main(input_file_path)
|
||||||
file_path = os.path.join(workspace, "tests", "inputs", f"{input_name}.yaml")
|
|
||||||
|
|
||||||
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
|
|
@ -485,7 +485,7 @@ class TestRendering(unittest.TestCase):
|
||||||
):
|
):
|
||||||
rendering.run_latex(nonexistent_latex_file_path)
|
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:
|
# Change the working directory to the root of the project:
|
||||||
workspace_path = os.path.dirname(os.path.dirname(__file__))
|
workspace_path = os.path.dirname(os.path.dirname(__file__))
|
||||||
|
|
||||||
|
@ -515,3 +515,15 @@ class TestRendering(unittest.TestCase):
|
||||||
reference_pdf_file_size, pdf_file_size
|
reference_pdf_file_size, pdf_file_size
|
||||||
)
|
)
|
||||||
self.assertTrue(ratio > 0.99, msg="PDF file didn't match the reference.")
|
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",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in New Issue