From 22f7c0b03d349050e81468d8eb9cda3f0b0f52f1 Mon Sep 17 00:00:00 2001 From: Chris Laplante Date: Mon, 27 Jul 2020 16:18:57 +0200 Subject: [PATCH] config: Make common repository check a bit more Pythonic Shortens code and makes the intent clearer. Signed-off-by: Chris Laplante Signed-off-by: Jan Kiszka --- kas/config.py | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/kas/config.py b/kas/config.py index ba159f3..3b0fb79 100644 --- a/kas/config.py +++ b/kas/config.py @@ -39,19 +39,16 @@ class Config: self._override_target = target self._override_task = task self._config = {} - self.filenames = [] + self.filenames = [os.path.abspath(configfile) + for configfile in filename.split(':')] - for configfile in filename.split(':'): - configfile = os.path.abspath(configfile) - repo_path = Repo.get_root_path(os.path.dirname(configfile), - fallback=False) - if self.filenames == []: - common_path = repo_path - elif repo_path != common_path: - raise IncludeException('All concatenated config files must ' - 'belong to the same repository or all ' - 'must be outside of versioning control') - self.filenames.append(configfile) + 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.repo_dict = self._get_repo_dict()