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 18 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.
Binary file modified examples/John_Doe_EngineeringresumesTheme_CV.pdf
Binary file not shown.
Binary file modified examples/John_Doe_ModerncvTheme_CV.pdf
Binary file not shown.
Binary file modified examples/John_Doe_Sb2novTheme_CV.pdf
Binary file not shown.
145 changes: 96 additions & 49 deletions rendercv/cli/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
commands of RenderCV.
"""

import inspect
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 @@ -98,23 +99,23 @@ def cli_command_render(
help="Copy the PNG file to the given path.",
),
] = None,
dont_generate_markdown: Annotated[
no_markdown: Annotated[
bool,
typer.Option(
"--dont-generate-markdown",
"-nomd",
help="Don't generate the Markdown and HTML file.",
),
] = False,
dont_generate_html: Annotated[
no_html: Annotated[
bool,
typer.Option(
"--dont-generate-html",
"-nohtml",
help="Don't generate the HTML file.",
),
] = False,
dont_generate_png: Annotated[
no_png: Annotated[
bool,
typer.Option(
"--dont-generate-png",
Expand All @@ -141,57 +142,90 @@ 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": no_markdown,
"no_html": no_html,
"no_png": no_png,
}

# Use inspect to get the default values of the arguments:
sig = inspect.signature(cli_command_render)
sinaatalay marked this conversation as resolved.
Show resolved Hide resolved
cli_args_default = {
akib1689 marked this conversation as resolved.
Show resolved Hide resolved
k: v.default
for k, v in sig.parameters.items()
if v.default is not inspect.Parameter.empty
}

# 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)

# compute the number of steps
# 1. read and validate the input file
# 0. read the input file
# 1. validate the input file
# 2. generate the LaTeX file
# 3. render the LaTeX file to a PDF
# 4. render PNG files from the PDF
# 5. generate the Markdown file
# 6. render the Markdown file to a HTML (for Grammarly)

data_as_a_dict = data.read_a_yaml_file(input_file_path)

# update the data if there are extra override arguments:
if extra_data_model_override_argumets:
key_and_values = dict()
key_and_values = utilities.parse_render_command_override_arguments(
extra_data_model_override_argumets
)
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())
if render_cv_settings is None:
akib1689 marked this conversation as resolved.
Show resolved Hide resolved
render_cv_settings = dict()

# get the render options:
render_options = render_cv_settings.get("render", dict())
akib1689 marked this conversation as resolved.
Show resolved Hide resolved
render_options = utilities.update_render_settings(
akib1689 marked this conversation as resolved.
Show resolved Hide resolved
render_options, cli_args, cli_args_default
)

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

# Calculate the number of steps:
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
if data_as_a_dict["rendercv_settings"]["render"]["no_png"]:
number_of_steps -= 1
if data_as_a_dict["rendercv_settings"]["render"]["no_markdown"]:
number_of_steps -= 2
else:
if dont_generate_html:
number_of_steps = number_of_steps - 1

with printer.LiveProgressReporter(number_of_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)

# update the data if there are extra override arguments:
if extra_data_model_override_argumets:
key_and_values = dict()
key_and_values = utilities.parse_render_command_override_arguments(
extra_data_model_override_argumets
)
data_as_a_dict = utilities.set_or_update_values(
data_as_a_dict, key_and_values
)
if data_as_a_dict["rendercv_settings"]["render"]["no_html"]:
number_of_steps -= 1

with printer.LiveProgressReporter(number_of_steps=number_of_steps) as progress:
progress.start_a_step("Validating the input file")

data_model = data.validate_input_dictionary_and_return_the_data_model(
data_as_a_dict
)

render_options = data_model.rendercv_settings.render
output_directory = working_directory / render_options.output_folder_name

progress.finish_the_current_step()

progress.start_a_step("Generating the LaTeX file")
Expand All @@ -200,47 +234,60 @@ def cli_command_render(
data_model, output_directory
)
)
if paths["latex"]:
utilities.copy_files(latex_file_path_in_output_folder, paths["latex"])
if render_options.latex_path:
utilities.copy_files(
latex_file_path_in_output_folder,
render_options.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 render_options.pdf_path:
utilities.copy_files(
pdf_file_path_in_output_folder,
render_options.pdf_path,
)
progress.finish_the_current_step()

if not dont_generate_png:
if not render_options.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 render_options.png_path:
utilities.copy_files(
png_file_paths_in_output_folder,
render_options.png_path,
)
progress.finish_the_current_step()

if not dont_generate_markdown:
if not render_options.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 render_options.markdown_path:
utilities.copy_files(
markdown_file_path_in_output_folder, paths["markdown"]
markdown_file_path_in_output_folder,
render_options.markdown_path,
)
progress.finish_the_current_step()

if not dont_generate_html:
if not render_options.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 render_options.html_path:
utilities.copy_files(
html_file_path_in_output_folder,
render_options.html_path,
)
progress.finish_the_current_step()


Expand Down
38 changes: 38 additions & 0 deletions rendercv/cli/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,3 +260,41 @@ def parse_render_command_override_arguments(
key_and_values[key] = value

return key_and_values


def update_render_settings(
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.

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.
"""
# if the dictionary is empty, initialize it from the default values:
if not dictionary:
dictionary = command_line_arguments_default_values

# 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
Loading
Loading