Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added the rendercv_settings block #166

Merged
merged 31 commits into from
Sep 7, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
680df52
chore: started working on the rendercv_settings pipeline
akib1689 Aug 31, 2024
e1fbc4a
feat: added the data model class
akib1689 Aug 31, 2024
49526d3
feat: Add `no_html` and `no_png` options to `rendercv_settings`
akib1689 Sep 1, 2024
35b1511
feat: added to use the output directory
akib1689 Sep 1, 2024
54adb66
feat: Refactor output directory handling
akib1689 Sep 1, 2024
419706a
fix: fixed the number of steps bug in the command.py
akib1689 Sep 1, 2024
3a013a7
fix: added some default values to the file.
akib1689 Sep 1, 2024
d8c7650
chore: update the output directory
akib1689 Sep 1, 2024
4bd10a6
fix: test case passing
akib1689 Sep 1, 2024
7c78eaf
refactor: Improve handling of output directory in cli_command_render
akib1689 Sep 1, 2024
f2aa0b8
refactor: update schema
akib1689 Sep 1, 2024
898e85f
refactor: update-example
akib1689 Sep 1, 2024
b387509
refactor: generate pdf with script
akib1689 Sep 1, 2024
492eb3f
Merge pull request #1 from akib1689/add-settings
akib1689 Sep 1, 2024
e77bc58
refactor: Update rendercv_settings to allow disabling HTML and PNG ge…
akib1689 Sep 3, 2024
22d8124
refactor: Update rendercv_settings to allow disabling HTML and PNG ge…
akib1689 Sep 3, 2024
1b17856
refactor: Remove unused rendercv_settings properties
akib1689 Sep 3, 2024
eb728a9
Merge pull request #2 from akib1689/add-settings
akib1689 Sep 3, 2024
d7b4106
Merge pull request #3 from sinaatalay/main
akib1689 Sep 4, 2024
d10045e
refactor: Update rendercv_settings to allow disabling HTML and PNG ge…
akib1689 Sep 4, 2024
2a728b8
refactor: Update rendercv_settings to allow disabling HTML and PNG ge…
akib1689 Sep 4, 2024
8096c85
refactor: updated examples
akib1689 Sep 4, 2024
26c7a21
Merge branch 'main' of akib1689/rendercv into add-settings
akib1689 Sep 4, 2024
878c149
merge from add branch
akib1689 Sep 4, 2024
36cd3b0
refactor: removed the `render_options` from `rendercv_settings`
akib1689 Sep 4, 2024
91281a2
chore: update the examples
akib1689 Sep 4, 2024
ff17345
chore: Update on schema
akib1689 Sep 4, 2024
56cb87d
Merge branch 'main' of https://github.com/akib1689/rendercv
akib1689 Sep 4, 2024
0cc14c4
docs: Add `rendercv_settings` to YAML input file structure
akib1689 Sep 7, 2024
ab14bbf
fix: changed the name of the description variable with name of the fu…
akib1689 Sep 7, 2024
9a1c74a
Merge pull request #5 from akib1689/add-settings
akib1689 Sep 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified docs/assets/images/classic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/assets/images/sb2nov.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/John_Doe_ClassicTheme_CV.pdf
Binary file not shown.
5 changes: 5 additions & 0 deletions examples/John_Doe_ClassicTheme_CV.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,8 @@ design:
bottom: 0.3 cm
horizontal_between_connections: 0.5 cm
show_timespan_in: []
rendercv_settings:
output_folder_name: rendercv_output
no_html: false
no_markdown: false
no_png: false
Binary file modified examples/John_Doe_EngineeringresumesTheme_CV.pdf
Binary file not shown.
5 changes: 5 additions & 0 deletions examples/John_Doe_EngineeringresumesTheme_CV.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,8 @@ design:
vertical_between_name_and_connections: 5 pt
bottom: 5 pt
horizontal_between_connections: 10 pt
rendercv_settings:
output_folder_name: rendercv_output
no_html: false
no_markdown: false
no_png: false
Binary file modified examples/John_Doe_ModerncvTheme_CV.pdf
Binary file not shown.
5 changes: 5 additions & 0 deletions examples/John_Doe_ModerncvTheme_CV.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,8 @@ design:
content_scale: 0.75
show_only_years: false
disable_page_numbers: false
rendercv_settings:
output_folder_name: rendercv_output
no_html: false
no_markdown: false
no_png: false
Binary file modified examples/John_Doe_Sb2novTheme_CV.pdf
Binary file not shown.
5 changes: 5 additions & 0 deletions examples/John_Doe_Sb2novTheme_CV.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,8 @@ design:
vertical_between_name_and_connections: 0.3 cm
bottom: 0.3 cm
horizontal_between_connections: 0.5 cm
rendercv_settings:
output_folder_name: rendercv_output
no_html: false
no_markdown: false
no_png: false
117 changes: 82 additions & 35 deletions rendercv/cli/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import os
import pathlib
from typing import Annotated, Literal, Optional
from typing import Annotated, Optional

import typer
from rich import print
Expand Down Expand Up @@ -141,18 +141,38 @@ def cli_command_render(
input_file_path: pathlib.Path = utilities.string_to_file_path(
input_file_name
) # type: ignore
output_directory = pathlib.Path.cwd() / output_folder_name

paths: dict[
Literal["latex", "pdf", "markdown", "html", "png"], Optional[pathlib.Path]
] = {
"latex": utilities.string_to_file_path(latex_path),
"pdf": utilities.string_to_file_path(pdf_path),
"markdown": utilities.string_to_file_path(markdown_path),
"html": utilities.string_to_file_path(html_path),
"png": utilities.string_to_file_path(png_path),

# dictionary for command line arguments:
cli_args = {
"use_local_latex_command": use_local_latex_command,
"output_folder_name": output_folder_name,
"latex_path": utilities.string_to_file_path(latex_path),
"pdf_path": utilities.string_to_file_path(pdf_path),
"markdown_path": utilities.string_to_file_path(markdown_path),
"html_path": utilities.string_to_file_path(html_path),
"png_path": utilities.string_to_file_path(png_path),
"no_markdown": dont_generate_markdown,
"no_html": dont_generate_html,
"no_png": dont_generate_png,
}

# Create the default values for the cli_args:
cli_args_default = {
akib1689 marked this conversation as resolved.
Show resolved Hide resolved
"use_local_latex_command": None,
"output_folder_name": "rendercv_output",
"latex_path": None,
"pdf_path": None,
"markdown_path": None,
"html_path": None,
"png_path": None,
"no_markdown": False,
"no_html": False,
"no_png": False,
}

# keep the current working directory:
working_directory = pathlib.Path.cwd()

# change the current working directory to the input file's directory (because
# the template overrides are looked up in the current working directory):
os.chdir(input_file_path.parent)
Expand All @@ -164,17 +184,8 @@ def cli_command_render(
# 4. render PNG files from the PDF
# 5. generate the Markdown file
# 6. render the Markdown file to a HTML (for Grammarly)
number_of_steps = 6
if dont_generate_png:
number_of_steps = number_of_steps - 1
if dont_generate_markdown:
# if the Markdown file is not generated, then the HTML file is not generated
number_of_steps = number_of_steps - 2
else:
if dont_generate_html:
number_of_steps = number_of_steps - 1

with printer.LiveProgressReporter(number_of_steps) as progress:
initial_steps = 1
akib1689 marked this conversation as resolved.
Show resolved Hide resolved
with printer.LiveProgressReporter(number_of_steps=initial_steps) as progress:
progress.start_a_step("Reading and validating the input file")
data_as_a_dict = data.read_a_yaml_file(input_file_path)

Expand All @@ -187,60 +198,96 @@ def cli_command_render(
data_as_a_dict = utilities.set_or_update_values(
data_as_a_dict, key_and_values
)
# update the data of the rendercv settings:
render_cv_settings = data_as_a_dict.get("rendercv_settings", dict())
render_cv_settings = utilities.build_rendercv_settings(
render_cv_settings, cli_args, cli_args_default
)

# update the data model with the rendercv settings:
data_as_a_dict["rendercv_settings"] = render_cv_settings

data_model = data.validate_input_dictionary_and_return_the_data_model(
data_as_a_dict
)

output_directory = (
working_directory / data_model.rendercv_settings.output_folder_name
)

progress.finish_the_current_step()

# Calculate the number of steps:
number_of_steps = 6
if data_model.rendercv_settings.no_png:
number_of_steps -= 1
if data_model.rendercv_settings.no_markdown:
number_of_steps -= 2
else:
if data_model.rendercv_settings.no_html:
number_of_steps -= 1

progress.update_total_steps(number_of_steps)

progress.start_a_step("Generating the LaTeX file")
latex_file_path_in_output_folder = (
renderer.create_a_latex_file_and_copy_theme_files(
data_model, output_directory
)
)
if paths["latex"]:
utilities.copy_files(latex_file_path_in_output_folder, paths["latex"])
if data_model.rendercv_settings.latex_path:
utilities.copy_files(
latex_file_path_in_output_folder,
data_model.rendercv_settings.latex_path,
)
progress.finish_the_current_step()

progress.start_a_step("Rendering the LaTeX file to a PDF")
pdf_file_path_in_output_folder = renderer.render_a_pdf_from_latex(
latex_file_path_in_output_folder, use_local_latex_command
)
if paths["pdf"]:
utilities.copy_files(pdf_file_path_in_output_folder, paths["pdf"])
if data_model.rendercv_settings.pdf_path:
utilities.copy_files(
pdf_file_path_in_output_folder, data_model.rendercv_settings.pdf_path
)
progress.finish_the_current_step()

if not dont_generate_png:
if not data_model.rendercv_settings.no_png:
progress.start_a_step("Rendering PNG files from the PDF")
png_file_paths_in_output_folder = renderer.render_pngs_from_pdf(
pdf_file_path_in_output_folder
)
if paths["png"]:
utilities.copy_files(png_file_paths_in_output_folder, paths["png"])
if data_model.rendercv_settings.png_path:
utilities.copy_files(
png_file_paths_in_output_folder,
data_model.rendercv_settings.png_path,
)
progress.finish_the_current_step()

if not dont_generate_markdown:
if not data_model.rendercv_settings.no_markdown:
progress.start_a_step("Generating the Markdown file")
markdown_file_path_in_output_folder = renderer.create_a_markdown_file(
data_model, output_directory
)
if paths["markdown"]:
if data_model.rendercv_settings.markdown_path:
utilities.copy_files(
markdown_file_path_in_output_folder, paths["markdown"]
markdown_file_path_in_output_folder,
data_model.rendercv_settings.markdown_path,
)
progress.finish_the_current_step()

if not dont_generate_html:
if not data_model.rendercv_settings.no_html:
progress.start_a_step(
"Rendering the Markdown file to a HTML (for Grammarly)"
)
html_file_path_in_output_folder = renderer.render_an_html_from_markdown(
markdown_file_path_in_output_folder
)
if paths["html"]:
utilities.copy_files(html_file_path_in_output_folder, paths["html"])
if data_model.rendercv_settings.html_path:
utilities.copy_files(
html_file_path_in_output_folder,
data_model.rendercv_settings.html_path,
)
progress.finish_the_current_step()


Expand Down
16 changes: 16 additions & 0 deletions rendercv/cli/printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,22 @@ def start_a_step(self, step_name: str):
f"{self.current_step_name} has started."
)

def update_total_steps(self, total_steps: int):
akib1689 marked this conversation as resolved.
Show resolved Hide resolved
"""Update the total number of steps.

Args:
total_steps (int): The total number of steps.
"""
self.number_of_steps = total_steps
self.overall_progress.update(
self.overall_task_id,
total=total_steps,
description=(
f"[bold #AAAAAA]({self.current_step} out of"
f" {self.number_of_steps} steps finished)"
),
)

def finish_the_current_step(self):
"""Finish the current step and update the progress bars."""
self.step_progress.stop_task(self.current_step_id)
Expand Down
32 changes: 32 additions & 0 deletions rendercv/cli/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,3 +260,35 @@ def parse_render_command_override_arguments(
key_and_values[key] = value

return key_and_values


def build_rendercv_settings(
akib1689 marked this conversation as resolved.
Show resolved Hide resolved
dictionary: dict,
command_line_arguments: dict[str, str],
command_line_arguments_default_values: dict[str, str],
) -> dict[str, str]:
"""Build the RenderCV settings dictionary by combining the dictionary and the command line arguments.
akib1689 marked this conversation as resolved.
Show resolved Hide resolved

Args:
dictionary (dict): The dictionary to be combined with the command line
arguments.
command_line_arguments (dict[str, str]): The command line arguments.

Returns:
dict[str, str]: The combined dictionary.
"""
# Combine the dictionary and the command line arguments if the values are not None:
for key, value in command_line_arguments.items():
# check if the key is present in the both command line arguments and the default values:
if key in command_line_arguments_default_values:
default_value = command_line_arguments_default_values[key]
if value != default_value:
dictionary = set_or_update_a_value(dictionary, key, str(value))
else:
# The key is not present in the default values, set the value:
# throw an error reporting this
raise ValueError(
f"The key ({key}) is not present in the default values of the command"
" line arguments!"
)
return dictionary
18 changes: 18 additions & 0 deletions rendercv/data/models/rendercv_data_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from .curriculum_vitae import CurriculumVitae
from .design import RenderCVDesign
from .locale_catalog import LocaleCatalog
from .rendercv_settings import RenderCVSettings


class RenderCVDataModel(RenderCVBaseModelWithoutExtraKeys):
Expand All @@ -36,6 +37,11 @@ class RenderCVDataModel(RenderCVBaseModelWithoutExtraKeys):
),
validate_default=True,
)
rendercv_settings: RenderCVSettings = pydantic.Field(
sinaatalay marked this conversation as resolved.
Show resolved Hide resolved
default=RenderCVSettings(),
title="RenderCV Settings",
description="The settings of the RenderCV.",
akib1689 marked this conversation as resolved.
Show resolved Hide resolved
)

@pydantic.field_validator("locale_catalog")
@classmethod
Expand All @@ -46,3 +52,15 @@ def initialize_locale_catalog(cls, locale_catalog: LocaleCatalog) -> LocaleCatal
LocaleCatalog()

return locale_catalog

@pydantic.field_validator("rendercv_settings")
@classmethod
def initialize_rendercv_settings(
cls, rendercv_settings: RenderCVSettings
) -> RenderCVSettings:
"""Even if the rendercv settings are not provided, initialize them with the default
values."""
if rendercv_settings is None:
RenderCVSettings()

return rendercv_settings
Loading