[get_package_config_from_repo] separate the searching and loading parts
so that the 'no config found' is not after the loading part
@@ -230,31 +230,36 @@ def get_package_config_from_repo(
config_file_content = sourcegit_project.get_file_content(
path=config_file_name, ref=ref
)
+ except FileNotFoundError:
+ # do nothing
+ pass
+ else:
logger.debug(
f"Found a config file '{config_file_name}' "
f"on ref '{ref}' "
f"of the {sourcegit_project.full_repo_name} repository."
)
- except FileNotFoundError:
- continue
+ break
+ else:
+ logger.warning(
+ f"No config file ({CONFIG_FILE_NAMES}) found on ref '{ref}' "
+ f"of the {sourcegit_project.full_repo_name} repository."
+ )
+ return None
try:
loaded_config = safe_load(config_file_content)
except Exception as ex:
- logger.error(f"Cannot load package config '{config_file_name}'.")
- raise PackitConfigException(f"Cannot load package config: {ex}.")
+ logger.error(f"Cannot load package config {config_file_name!r}. {ex}")
+ raise PackitConfigException(
+ f"Cannot load package config {config_file_name!r}. {ex}"
+ )
return parse_loaded_config(
loaded_config=loaded_config,
config_file_path=config_file_name,
repo_name=sourcegit_project.repo,
)
- logger.warning(
- f"No config file ({CONFIG_FILE_NAMES}) found on ref '{ref}' "
- f"of the {sourcegit_project.full_repo_name} repository."
- )
- return None
-
def parse_loaded_config(
loaded_config: dict, config_file_path: str = None, repo_name: str = None
