From da6d3135d17c19aa14055eb8da3f58d3228d2b30 Mon Sep 17 00:00:00 2001 From: Sina Atalay Date: Sun, 22 Oct 2023 16:39:02 +0200 Subject: [PATCH] check input file extension before running --- rendercv/rendering.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/rendercv/rendering.py b/rendercv/rendering.py index dfa7e03..fb5880a 100644 --- a/rendercv/rendering.py +++ b/rendercv/rendering.py @@ -261,6 +261,14 @@ def read_input_file(file_path: str) -> RenderCVDataModel: if not os.path.exists(file_path): raise FileNotFoundError(f"The file {file_path} doesn't exist!") + # check the file extension: + accepted_extensions = [".yaml", ".yml", ".json", ".json5"] + if not any(file_path.endswith(extension) for extension in accepted_extensions): + raise ValueError( + f"The file {file_path} doesn't have an accepted extension!" + f" Accepted extensions are: {accepted_extensions}" + ) + with open(file_path) as file: yaml = YAML() raw_json = yaml.load(file)