Files
rendercv/scripts/update_examples.py
2026-03-20 03:45:08 +03:00

52 lines
1.8 KiB
Python

import pathlib
import shutil
import tempfile
from rendercv.cli.render_command.progress_panel import ProgressPanel
from rendercv.cli.render_command.run_rendercv import run_rendercv
from rendercv.schema.models.design.built_in_design import available_themes
from rendercv.schema.sample_generator import create_sample_yaml_input_file
repository_root = pathlib.Path(__file__).parent.parent
rendercv_path = repository_root / "rendercv"
image_assets_directory = repository_root / "docs" / "assets" / "images" / "examples"
examples_directory_path = pathlib.Path(__file__).parent.parent / "examples"
# Check if examples directory exists. If not, create it
if not examples_directory_path.exists():
examples_directory_path.mkdir()
for theme in available_themes:
yaml_file_path = (
examples_directory_path / f"John_Doe_{theme.capitalize()}Theme_CV.yaml"
)
create_sample_yaml_input_file(
file_path=yaml_file_path,
name="John Doe",
theme=theme,
locale="english",
)
with tempfile.TemporaryDirectory() as temp_directory:
temp_directory_path = pathlib.Path(temp_directory)
run_rendercv(
yaml_file_path,
progress=ProgressPanel(),
typst_path=temp_directory_path / f"{yaml_file_path.stem}.typ",
pdf_path=examples_directory_path / f"{yaml_file_path.stem}.pdf",
png_path=temp_directory_path / f"{yaml_file_path.stem}.png",
dont_generate_html=True,
dont_generate_markdown=True,
)
image_assets_directory.mkdir(parents=True, exist_ok=True)
shutil.copy(
temp_directory_path / f"{yaml_file_path.stem}_1.png",
image_assets_directory / f"{theme}.png",
)
print("Examples generated successfully.") # NOQA: T201