From d4a0500774b7208a1276f8aefd4013d8e7b544f6 Mon Sep 17 00:00:00 2001 From: Stephen-RA-King <33905365+Stephen-RA-King@users.noreply.github.com> Date: Sat, 27 Aug 2022 19:13:01 +0100 Subject: [PATCH] feat: add find_yaml_config_file function --- src/piptools_sync/piptools_sync.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/piptools_sync/piptools_sync.py b/src/piptools_sync/piptools_sync.py index 01effa5..8040629 100644 --- a/src/piptools_sync/piptools_sync.py +++ b/src/piptools_sync/piptools_sync.py @@ -257,3 +257,26 @@ def generate_file() -> dict: print(end - start) return mapping + + +def find_yaml_config_file() -> Path: + """Find the '.pre-commit-config.yaml' config file in the project directory. + + Returns: + pc_file : Path + Path object for the configuration file. + + Raise + FileNotFoundError : + If the config file cannot be found. + """ + + logger.debug("starting **** find_yaml_config_file ****") + file_list_text = list(ROOT_DIR.iterdir()) + file_list_path = [Path(i) for i in file_list_text] + for filepath in file_list_path: + if filepath.name == PRECOMMIT_CONFIG_FILE: + pc_file = filepath + logger.debug(f"found file: {pc_file}") + return pc_file + raise FileNotFoundError(f"Cannot locate '{PRECOMMIT_CONFIG_FILE}'")