From 3790b4e53d0037d5a870d64267edcc74ecb8663d Mon Sep 17 00:00:00 2001 From: Christian Busch Date: Fri, 28 Oct 2022 09:57:27 +0200 Subject: [PATCH 1/2] fix: reading deckfile info --- getdeck/fetch/fetch.py | 22 +++++++++++++++------- getdeck/fetch/utils.py | 24 ++++++++++++++---------- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/getdeck/fetch/fetch.py b/getdeck/fetch/fetch.py index f7f2241..aa05bc9 100644 --- a/getdeck/fetch/fetch.py +++ b/getdeck/fetch/fetch.py @@ -9,7 +9,7 @@ select_deck_fetch_behavior, ) from getdeck.fetch.types import DataAux -from getdeck.fetch.utils import get_path_and_name +from getdeck.fetch.utils import detect_deckfile, get_path_and_name from getdeck.deckfile.file import DeckfileDeck from getdeck.deckfile.selector import deckfile_selector @@ -83,20 +83,28 @@ def fetch_data( delete returned DataAux to clean up temporary resources """ - logger.info(f"Reading Deckfile from: {location}") + # info + display_location = location + if display_location == ".": + display_location = detect_deckfile() + + logger.info(f"Reading Deckfile: {display_location}") + + # fetch deck data_aux = DataAux() data_aux = _fetch_deck(data_aux=data_aux, location=location) # validate - file = os.path.join(data_aux.deckfile_aux.path, data_aux.deckfile_aux.name) - if not os.path.isfile(file): + file_detected = os.path.join(data_aux.deckfile_aux.path, data_aux.deckfile_aux.name) + if not os.path.isfile(file_detected): + logger.debug(f"Absolute file location: {file_detected}") del data_aux - raise RuntimeError(f"Cannot identify Deckfile at location: '{location}'") + raise RuntimeError(f"Cannot identify Deckfile at location: {display_location}") - deckfile = deckfile_selector.get(file) + deckfile = deckfile_selector.get(file_detected) data_aux.deckfile = deckfile - # parse + fetch sources + # fetch sources if fetch_sources: deck = deckfile.get_deck(deck_name) source_auxs = _fetch_sources(deck=deck) diff --git a/getdeck/fetch/utils.py b/getdeck/fetch/utils.py index 86c84c8..1a5def2 100644 --- a/getdeck/fetch/utils.py +++ b/getdeck/fetch/utils.py @@ -4,6 +4,16 @@ from getdeck import configuration +def detect_deckfile() -> Optional[str]: + for extension in [".yaml", ".yml"]: + name = os.path.splitext(configuration.DECKFILE_FILE)[0] + extension + location = os.path.join(os.getcwd(), name) + if os.path.isfile(location): + return name + else: + return None + + def get_path_and_name(location: Optional[str]) -> Tuple[str, str]: # None if location is None: @@ -15,16 +25,10 @@ def get_path_and_name(location: Optional[str]) -> Tuple[str, str]: # ".", "" if location in [".", ""]: - for extension in [".yaml", ".yml"]: - location_default = os.path.join( - os.getcwd(), - os.path.splitext(configuration.DECKFILE_FILE)[0] + extension, - ) - if os.path.isfile(location_default): - location = location_default - break - else: - location = os.path.join(os.getcwd(), configuration.DECKFILE_FILE) + name = detect_deckfile() + if not name: + name = configuration.DECKFILE_FILE + location = os.path.join(os.getcwd(), name) name = os.path.basename(location) dirname = os.path.dirname(location) From 74dd5210409b46fa4a259fe354fb183a20455b0b Mon Sep 17 00:00:00 2001 From: Christian Busch Date: Fri, 28 Oct 2022 10:52:33 +0200 Subject: [PATCH 2/2] fix: remove code smell --- getdeck/fetch/utils.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/getdeck/fetch/utils.py b/getdeck/fetch/utils.py index 1a5def2..4cd9cc2 100644 --- a/getdeck/fetch/utils.py +++ b/getdeck/fetch/utils.py @@ -10,8 +10,7 @@ def detect_deckfile() -> Optional[str]: location = os.path.join(os.getcwd(), name) if os.path.isfile(location): return name - else: - return None + return None def get_path_and_name(location: Optional[str]) -> Tuple[str, str]: