From 8285fe7c794df3b5167e738d7c241eee24612f5a Mon Sep 17 00:00:00 2001 From: Sina Atalay Date: Wed, 18 Oct 2023 19:33:19 +0200 Subject: [PATCH] move entry function to __main__.py --- pyproject.toml | 4 ++-- rendercv/__main__.py | 25 +++++++------------------ rendercv/rendering.py | 22 +--------------------- 3 files changed, 10 insertions(+), 41 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 18ac2b3..1ce5062 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,7 +1,7 @@ [project] name = 'rendercv' description = 'LaTeX CV generator from a YAML/JSON file' -version = '0.2' +version = '0.3' authors = [{ name = 'Sina Atalay' }] requires-python = '>=3.10' readme = "README.md" @@ -35,7 +35,7 @@ Documentation = 'https://sinaatalay.github.io/rendercv/' Source = 'https://github.com/sinaatalay/rendercv' [project.scripts] -rendercv = 'rendercv.rendering:main' +rendercv = 'rendercv.__main__:main' [project.optional-dependencies] docs = ["mkdocs", "mkdocs-material", "mkdocstrings-python"] diff --git a/rendercv/__main__.py b/rendercv/__main__.py index 6508a6f..cb12757 100644 --- a/rendercv/__main__.py +++ b/rendercv/__main__.py @@ -1,31 +1,20 @@ -""" -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 +import os -from rendercv.rendering import read_input_file, render_template, run_latex +from .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: +def main(): + if len(sys.argv) < 2: raise ValueError("Please provide the input file path.") - elif len(args) == 1: - input_file_path = args[0] + elif len(sys.argv) == 2: + input_file_path = sys.argv[1] 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) @@ -33,4 +22,4 @@ def main(args=sys.argv[1:]): if __name__ == "__main__": - main(args=["tests/inputs/personal.yaml"]) + main() diff --git a/rendercv/rendering.py b/rendercv/rendering.py index f2d3d86..e816e4f 100644 --- a/rendercv/rendering.py +++ b/rendercv/rendering.py @@ -11,7 +11,7 @@ from typing import Optional import sys from importlib.resources import files -from rendercv.data_model import RenderCVDataModel +from .data_model import RenderCVDataModel from jinja2 import Environment, PackageLoader from ruamel.yaml import YAML @@ -464,23 +464,3 @@ def run_latex(latex_file_path: str) -> str: ) return output_file_path - - -def main(): - """ - This is the main function to run RenderCV. - """ - if len(sys.argv) < 2: - raise ValueError("Please provide the input file path.") - elif len(sys.argv) == 2: - input_file_path = sys.argv[1] - else: - raise ValueError( - "More than one input is provided. Please provide only one input, which is" - " the input file path." - ) - - file_path = os.path.join(os.getcwd(), input_file_path) - data = read_input_file(file_path) - output_latex_file = render_template(data) - run_latex(output_latex_file)