From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 4F58115800F for ; Tue, 17 Jan 2023 20:50:52 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 84117E0825; Tue, 17 Jan 2023 20:50:51 +0000 (UTC) Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 6A28BE0825 for ; Tue, 17 Jan 2023 20:50:51 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 7734E340D82 for ; Tue, 17 Jan 2023 20:50:50 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id DDDBA851 for ; Tue, 17 Jan 2023 20:50:48 +0000 (UTC) From: "Arthur Zamarin" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Arthur Zamarin" Message-ID: <1673988586.f1c58b74df5eab2dac1e8e5810d9a042785f60cc.arthurzam@gentoo> Subject: [gentoo-commits] proj/pkgcore/pkgcore:master commit in: tests/ebuild/, src/pkgcore/ebuild/ X-VCS-Repository: proj/pkgcore/pkgcore X-VCS-Files: src/pkgcore/ebuild/portage_conf.py tests/ebuild/test_portage_conf.py X-VCS-Directories: src/pkgcore/ebuild/ tests/ebuild/ X-VCS-Committer: arthurzam X-VCS-Committer-Name: Arthur Zamarin X-VCS-Revision: f1c58b74df5eab2dac1e8e5810d9a042785f60cc X-VCS-Branch: master Date: Tue, 17 Jan 2023 20:50:48 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: cd8cfca7-c9b7-46c4-bc7a-fafe432ed848 X-Archives-Hash: c41aca80245ff67e95fa4f66f2e15b33 commit: f1c58b74df5eab2dac1e8e5810d9a042785f60cc Author: Brian Harring gmail com> AuthorDate: Wed Jan 11 05:52:01 2023 +0000 Commit: Arthur Zamarin gentoo org> CommitDate: Tue Jan 17 20:49:46 2023 +0000 URL: https://gitweb.gentoo.org/proj/pkgcore/pkgcore.git/commit/?id=f1c58b74 refactor(portage_conf): Push fallback (and path awareness) logic of repos.conf into methods. The previous code had the exception + fallback handling in the init; this is already a long init, and there are changes needed for repos conf, thus introduce a method to do the fallback logic. Said method will be extended to essentially bury the complexity of repos.conf- that problem- into an encapsulated method to try and reduce the cognitive burden of dealing with it. Why this matters: this work is prep for extension of repos.conf to add in various syncing features portage grew over the last decade+. Signed-off-by: Brian Harring gmail.com> Signed-off-by: Arthur Zamarin gentoo.org> src/pkgcore/ebuild/portage_conf.py | 56 ++++++++++++++++++++------------------ tests/ebuild/test_portage_conf.py | 2 +- 2 files changed, 31 insertions(+), 27 deletions(-) diff --git a/src/pkgcore/ebuild/portage_conf.py b/src/pkgcore/ebuild/portage_conf.py index 815d563d4..9e5fffac7 100644 --- a/src/pkgcore/ebuild/portage_conf.py +++ b/src/pkgcore/ebuild/portage_conf.py @@ -172,24 +172,7 @@ class PortageConfig(DictMixin): } ) - try: - repos_conf_defaults, repos_conf = self.load_repos_conf( - pjoin(self.dir, "repos.conf") - ) - except config_errors.ParsingError as e: - if not getattr(getattr(e, "exc", None), "errno", None) == errno.ENOENT: - raise - try: - # fallback to defaults provided by pkgcore - repos_conf_defaults, repos_conf = self.load_repos_conf( - pjoin(const.CONFIG_PATH, "repos.conf") - ) - except IGNORED_EXCEPTIONS: - raise - except Exception as e: - raise config_errors.ParsingError( - "failed to find a usable repos.conf" - ) from e + repos_conf_defaults, repos_conf = self.load_repos_conf() self["ebuild-repo-common"] = basics.AutoConfigSection( { @@ -332,9 +315,31 @@ class PortageConfig(DictMixin): # quirk of read_bash_dict; it returns only what was mutated. vars_dict.update(new_vars) + def load_repos_conf(self) -> tuple[dict, dict]: + """parse and return repos.conf content, tracing the default and the fallback location""" + try: + repos_conf_defaults, repos_conf = self.parse_repos_conf_path( + pjoin(self.dir, "repos.conf") + ) + except config_errors.ParsingError as e: + if not getattr(getattr(e, "exc", None), "errno", None) == errno.ENOENT: + raise + try: + # fallback to defaults provided by pkgcore + repos_conf_defaults, repos_conf = self.parse_repos_conf_path( + pjoin(const.CONFIG_PATH, "repos.conf") + ) + except IGNORED_EXCEPTIONS: + raise + except Exception as e: + raise config_errors.ParsingError( + "failed to find a usable repos.conf" + ) from e + return repos_conf_defaults, repos_conf + @classmethod - def load_repos_conf(cls, path): - """parse repos.conf files + def parse_repos_conf_path(cls, path: str): + """parse repos.conf files from a given entrypoint Args: path (str): path to the repos.conf which can be a regular file or @@ -372,9 +377,7 @@ class PortageConfig(DictMixin): ) from e if defaults and main_defaults: - logger.warning( - f"repos.conf: parsing {fp!r}: overriding DEFAULT section" - ) + logger.warning("repos.conf: parsing %r: overriding DEFAULT section", fp) main_defaults.update(defaults) if not had_repo_conf and not repo_confs: @@ -385,15 +388,16 @@ class PortageConfig(DictMixin): for name, repo_conf in repo_confs.items(): if name in repos: logger.warning( - f"repos.conf: parsing {fp!r}: overriding {name!r} repo" + "repos.conf: parsing %r: overriding %r repo", fp, name ) # ignore repo if location is unset location = repo_conf.get("location", None) if location is None: logger.warning( - f"repos.conf: parsing {fp!r}: " - f"{name!r} repo missing location setting, ignoring repo" + "repos.conf: parsing %r: %r repo missing location setting, ignoring repo", + fp, + name, ) continue location = os.path.expanduser(location) diff --git a/tests/ebuild/test_portage_conf.py b/tests/ebuild/test_portage_conf.py index edb3d89b6..b939ee09e 100644 --- a/tests/ebuild/test_portage_conf.py +++ b/tests/ebuild/test_portage_conf.py @@ -13,7 +13,7 @@ from pkgcore.config import errors as config_errors from pkgcore.ebuild.portage_conf import PortageConfig load_make_conf = PortageConfig.load_make_conf -load_repos_conf = PortageConfig.load_repos_conf +load_repos_conf = PortageConfig.parse_repos_conf_path class TestMakeConf: