upload macos tinytex binaries

This commit is contained in:
Sina Atalay 2023-10-15 18:34:37 +02:00
parent 30252a75bf
commit ab503f9c79
1 changed files with 27 additions and 21 deletions

View File

@ -9,6 +9,7 @@ import logging
import time import time
from typing import Optional from typing import Optional
import sys import sys
from importlib.resources import files
from rendercv.data_model import RenderCVDataModel from rendercv.data_model import RenderCVDataModel
@ -241,7 +242,7 @@ def get_path_to_font_directory(font_name: str) -> str:
Returns: Returns:
str: The path to the fonts directory. str: The path to the fonts directory.
""" """
return os.path.join(os.path.dirname(__file__), "templates", "fonts", font_name) return str(files("rendercv").joinpath("templates", "fonts", font_name))
def read_input_file(file_path: str) -> RenderCVDataModel: def read_input_file(file_path: str) -> RenderCVDataModel:
@ -332,8 +333,8 @@ def render_template(data: RenderCVDataModel, output_path: Optional[str] = None)
file_name = data.cv.name.replace(" ", "_") + "_CV.tex" file_name = data.cv.name.replace(" ", "_") + "_CV.tex"
output_file_path = os.path.join(output_folder, file_name) output_file_path = os.path.join(output_folder, file_name)
os.makedirs(os.path.dirname(output_file_path), exist_ok=True) os.makedirs(os.path.dirname(output_file_path), exist_ok=True)
with open(output_file_path, "wb") as file: with open(output_file_path, "w") as file:
file.write(output_latex_file.encode("utf-8")) file.write(output_latex_file)
# Copy the fonts directory to the output directory: # Copy the fonts directory to the output directory:
# Remove the old fonts directory if it exists: # Remove the old fonts directory if it exists:
@ -350,7 +351,7 @@ def render_template(data: RenderCVDataModel, output_path: Optional[str] = None)
# Copy auxiliary files to the output directory (if there is any): # Copy auxiliary files to the output directory (if there is any):
output_directory = os.path.dirname(output_file_path) output_directory = os.path.dirname(output_file_path)
theme_directory = os.path.join(os.path.dirname(__file__), "templates", theme) theme_directory = str(files("rendercv").joinpath("templates", theme))
for file_name in os.listdir(theme_directory): for file_name in os.listdir(theme_directory):
if file_name.endswith(".cls"): if file_name.endswith(".cls"):
shutil.copy( shutil.copy(
@ -388,24 +389,29 @@ def run_latex(latex_file_path: str) -> str:
output_file_path = os.path.join(os.path.dirname(latex_file_path), output_file_name) output_file_path = os.path.join(os.path.dirname(latex_file_path), output_file_name)
if os.name == "nt": if os.name == "nt":
tinytex_path = os.path.join( # Windows
os.path.dirname(__file__), executable = str(
"vendor", files("rendercv").joinpath(
"TinyTeX", "vendor", "TinyTeX", "bin", "windows", "lualatex.exe"
"bin", )
"windows",
) )
executable = os.path.join(tinytex_path, "lualatex.exe")
else: elif os.name == "posix":
tinytex_path = os.path.join( # Linux
os.path.dirname(__file__), executable = str(
"vendor", files("rendercv").joinpath(
"TinyTeX", "vendor", "TinyTeX", "bin", "x86_64-linux", "lualatex"
"bin",
"x86_64-linux",
) )
executable = os.path.join(tinytex_path, "lualatex") )
elif os.name == "darwin":
# MacOS
executable = str(
files("rendercv").joinpath(
"vendor", "TinyTeX", "bin", "universal-darwin", "lualatex"
)
)
else:
raise OSError(f"Unknown OS {os.name}!")
# Check if the executable exists: # Check if the executable exists:
if not os.path.exists(executable): if not os.path.exists(executable):
@ -428,7 +434,7 @@ def run_latex(latex_file_path: str) -> str:
except subprocess.CalledProcessError or subprocess.TimeoutExpired as e: except subprocess.CalledProcessError or subprocess.TimeoutExpired as e:
raise RuntimeError( raise RuntimeError(
"Running TinyTeX has failed with the following error:\n\ncommand" "Running TinyTeX has failed with the following error:\n\ncommand"
f" \"{e.cmd}\" return with error (code {e.returncode}): {e.output}\n\nIf" f' "{e.cmd}" return with error (code {e.returncode}): {e.output}\n\nIf'
" you can't find the problem, please try to re-install RenderCV, or open" " you can't find the problem, please try to re-install RenderCV, or open"
" an issue on GitHub." " an issue on GitHub."
) )