update rendering.py for new template structure

This commit is contained in:
Sina Atalay 2023-10-14 18:32:10 +02:00
parent 58835d553a
commit 31449a5872
1 changed files with 6 additions and 4 deletions

View File

@ -285,9 +285,11 @@ def render_template(data: RenderCVDataModel, output_path: Optional[str] = None)
""" """
start_time = time.time() start_time = time.time()
logger.info("Rendering the LaTeX file has started.") logger.info("Rendering the LaTeX file has started.")
# create a Jinja2 environment: # create a Jinja2 environment:
theme = data.design.theme
environment = Environment( environment = Environment(
loader=PackageLoader("rendercv", "templates"), loader=PackageLoader("rendercv", os.path.join("templates", theme)),
trim_blocks=True, trim_blocks=True,
lstrip_blocks=True, lstrip_blocks=True,
) )
@ -312,7 +314,6 @@ def render_template(data: RenderCVDataModel, output_path: Optional[str] = None)
environment.filters["divide_length_by"] = divide_length_by environment.filters["divide_length_by"] = divide_length_by
# load the template: # load the template:
theme = data.design.theme
template = environment.get_template(f"{theme}.tex.j2") template = environment.get_template(f"{theme}.tex.j2")
output_latex_file = template.render( output_latex_file = template.render(
@ -410,9 +411,10 @@ 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=30,
) )
except subprocess.CalledProcessError as e: except subprocess.CalledProcessError or subprocess.TimeoutExpired as e:
raise RuntimeError( raise RuntimeError(
"Running TinyTeX has failed with the following error:\n\n" "Running TinyTeX has failed with the following error:\n\n"
f'command "{e.cmd}" return with error (code {e.returncode}): {e.output}\n\n' f'command "{e.cmd}" return with error (code {e.returncode}): {e.output}\n\n'