From bce8a916fa4a78ec57fe5c64cea80c5bda9b571f Mon Sep 17 00:00:00 2001 From: Johann Neuhauser Date: Fri, 29 Jul 2022 07:46:19 +0200 Subject: [PATCH] config: Symplify .config.yaml file handling If no configuration file is specified, we try to load a single .config.yaml from KAS_WORK_DIR and set the top_repo_path to the repo root of this file with fallback to the containing directory. This process is identical to loading explicitly specified configuration files and can therefore be combined into one case. Signed-off-by: Johann Neuhauser Signed-off-by: Jan Kiszka --- kas/config.py | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/kas/config.py b/kas/config.py index 236d106..091e727 100644 --- a/kas/config.py +++ b/kas/config.py @@ -41,23 +41,22 @@ class Config: self._override_target = target self._override_task = task self._config = {} - if filename: - self.filenames = [os.path.abspath(configfile) - for configfile in filename.split(':')] - self.top_repo_path = Repo.get_root_path( - os.path.dirname(self.filenames[0])) + if not filename: + filename = os.path.join(ctx.kas_work_dir, CONFIG_YAML_FILE) - repo_paths = [Repo.get_root_path(os.path.dirname(configfile), - fallback=False) - for configfile in self.filenames] + self.filenames = [os.path.abspath(configfile) + for configfile in filename.split(':')] + self.top_repo_path = Repo.get_root_path( + os.path.dirname(self.filenames[0])) - if len(set(repo_paths)) > 1: - raise IncludeException('All concatenated config files must ' - 'belong to the same repository or all ' - 'must be outside of versioning control') - else: - self.filenames = [os.path.join(ctx.kas_work_dir, CONFIG_YAML_FILE)] - self.top_repo_path = Repo.get_root_path(ctx.kas_work_dir) + repo_paths = [Repo.get_root_path(os.path.dirname(configfile), + fallback=False) + for configfile in self.filenames] + + if len(set(repo_paths)) > 1: + raise IncludeException('All concatenated config files must ' + 'belong to the same repository or all ' + 'must be outside of versioning control') self.handler = IncludeHandler(self.filenames, self.top_repo_path) self.repo_dict = self._get_repo_dict()