diff --git a/rendercv/__main__.py b/rendercv/__main__.py index 6f4e9f9..9f34256 100644 --- a/rendercv/__main__.py +++ b/rendercv/__main__.py @@ -29,9 +29,7 @@ def main(args=sys.argv[1:]): file_path = os.path.join(os.getcwd(), input_file_path) data = read_input_file(file_path) output_latex_file = render_template(data) - output_pdf_file = run_latex(output_latex_file) - logger.info(f"RenderCV: PDF file generated at {output_pdf_file}") - + run_latex(output_latex_file) if __name__ == "__main__": main(args=["tests/inputs/personal.yaml"]) diff --git a/rendercv/data_model.py b/rendercv/data_model.py index 89346fc..d458bb7 100644 --- a/rendercv/data_model.py +++ b/rendercv/data_model.py @@ -403,7 +403,7 @@ class ClassicThemeOptions(BaseModel): class Design(BaseModel): """This class stores the theme name of the CV and the theme's options.""" - theme: Literal["classic", "awesome-cv"] = Field( + theme: Literal["classic"] = Field( default="classic", title="Theme name", description='The only option is "Classic" for now.', @@ -426,12 +426,31 @@ class Design(BaseModel): description="The page size of the CV. It can be a4paper or letterpaper.", examples=["a4paper", "letterpaper"], ) - options: ClassicThemeOptions = Field( - default=ClassicThemeOptions(), + options: Optional[ClassicThemeOptions] = Field( + default=None, title="Theme Options", description="The options of the theme.", ) + @model_validator(mode="after") + @classmethod + def check_theme_options(cls, model): + if model.options is None: + if model.theme == "classic": + model.options = ClassicThemeOptions() + else: + raise RuntimeError("Unknown theme!") + else: + if model.theme == "classic": + if not isinstance(model.options, ClassicThemeOptions): + raise ValueError( + "Theme is classic but options is not classic theme options!" + ) + else: + raise RuntimeError("Theme is neither classic nor awesome-cv!") + + return model + @field_validator("font") @classmethod def check_font(cls, font: str) -> str: diff --git a/rendercv/rendering.py b/rendercv/rendering.py index ead3c5c..d0014c3 100644 --- a/rendercv/rendering.py +++ b/rendercv/rendering.py @@ -331,8 +331,8 @@ def render_template(data: RenderCVDataModel, output_path: Optional[str] = None) file_name = data.cv.name.replace(" ", "_") + "_CV.tex" output_file_path = os.path.join(output_folder, file_name) os.makedirs(os.path.dirname(output_file_path), exist_ok=True) - with open(output_file_path, "w") as file: - file.write(output_latex_file) + with open(output_file_path, "wb") as file: + file.write(output_latex_file.encode("utf-8")) # Copy the fonts directory to the output directory: # Remove the old fonts directory if it exists: @@ -347,6 +347,16 @@ def render_template(data: RenderCVDataModel, output_path: Optional[str] = None) dirs_exist_ok=True, ) + # Copy auxiliary files to the output directory (if there is any): + output_directory = os.path.dirname(output_file_path) + theme_directory = os.path.join(os.path.dirname(__file__), "templates", theme) + for file_name in os.listdir(theme_directory): + if file_name.endswith(".cls"): + shutil.copy( + os.path.join(theme_directory, file_name), + output_directory, + ) + end_time = time.time() time_taken = end_time - start_time logger.info(