start setting up the entry point

This commit is contained in:
Sina Atalay 2023-10-08 19:02:25 +02:00
parent 6c079b68cf
commit 9d4e714157
4 changed files with 55 additions and 16 deletions

View File

@ -2,8 +2,6 @@ r"""RenderCV package.
It parses the user input YAML/JSON file and validates the data (checks spelling mistakes, checks if the dates are consistent, etc.). Then, with the data, it creates a $\LaTeX$ file and renders it with [TinyTeX](https://yihui.org/tinytex/).
"""
# initialize logging:
import logging
@ -36,7 +34,7 @@ class LoggingFormatter(logging.Formatter):
logger = logging.getLogger()
logger.setLevel(logging.DEBUG)
stdout_handler = logging.StreamHandler()
stdout_handler.setLevel(logging.INFO)
stdout_handler.setFormatter(LoggingFormatter())
logger.addHandler(stdout_handler)

36
rendercv/__main__.py Normal file
View File

@ -0,0 +1,36 @@
"""
This module is a script to run the RenderCV and generate a CV as a PDF. It is an entry
point for the RenderCV package.
"""
import os
import logging
import sys
from rendercv.rendering import read_input_file, render_template, run_latex
def main(args=sys.argv[1:]):
"""
This is the main function to run RenderCV.
"""
logger = logging.getLogger(__name__)
if len(args) != 1:
raise ValueError("Please provide the input file path.")
elif len(args) == 1:
input_file_path = args[0]
else:
raise ValueError(
"More than one input is provided. Please provide only one input, which is"
" the input file path."
)
input_file_path = 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}")
if __name__ == "__main__":
main()

View File

@ -4,20 +4,11 @@ This module is a script to run the RenderCV and generate a CV as a PDF.
import os
from ruamel.yaml import YAML
from rendercv.data_model import RenderCVDataModel
from rendercv.rendering import render_template, run_latex
import rendercv
input_name = "personal"
workspace = os.path.dirname(__file__)
file_path = os.path.join(workspace, "tests", "inputs", f"{input_name}.yaml")
input_file_path = os.path.join(workspace, "tests", "inputs", f"{input_name}.yaml")
with open(input_file_path) as file:
yaml = YAML()
raw_json = yaml.load(file)
data = RenderCVDataModel(**raw_json)
output_latex_file=render_template(data=data)
run_latex(output_latex_file)
rendercv(file_path)

View File

@ -0,0 +1,14 @@
from setuptools import setup, find_packages
setup(
name="rendercv",
version="1.0",
author="Sina Atalay",
description="A Python package to generate a CV as a PDF from a YAML or JSON file.",
packages=find_packages(),
entry_points={
"console_scripts": [
"rendercv = rendercv.cli:main",
]
},
)