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..4cd9cc2 100644 --- a/getdeck/fetch/utils.py +++ b/getdeck/fetch/utils.py @@ -4,6 +4,15 @@ 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 + return None + + def get_path_and_name(location: Optional[str]) -> Tuple[str, str]: # None if location is None: @@ -15,16 +24,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)