From 8c677e9697d18924ee8f5e3462548b690abc5bae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lubom=C3=ADr=20Sedl=C3=A1=C5=99?= Date: Mon, 2 Dec 2024 09:39:54 +0100 Subject: [PATCH] Add disabling source inclusion Not all users care about source packages, so let's make life easier for them. With the new option, the tool will not do anything about source rpms, including not printing a warning for each RPM. --- CHANGELOG.md | 8 ++++++++ rpm_lockfile/__init__.py | 24 +++++++++++++++--------- rpm_lockfile/schema.py | 1 + 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ce8ac00..50611bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## Unreleased + +### Added + +- Inclusion of source packages in the final manifest can now be disabled with a + toplevel config option `noSources: true`. This is mostly useful for cases + where there are no source repos available to silence the many warnings. + ## [0.11.0] - 2024-11-20 ### Added diff --git a/rpm_lockfile/__init__.py b/rpm_lockfile/__init__.py index 4d3e284..7ee357a 100644 --- a/rpm_lockfile/__init__.py +++ b/rpm_lockfile/__init__.py @@ -116,6 +116,7 @@ def resolver( reinstall_packages: set[str], module_enable: set[str], module_disable: set[str], + no_sources: bool, ): packages = set() sources = set() @@ -180,15 +181,16 @@ def resolver( modular_repos.add(pkg.repoid) packages.add(PackageItem.from_dnf(pkg)) # Find the corresponding source package - n, v, r = strip_suffix(pkg.sourcerpm, ".src.rpm").rsplit("-", 2) - results = base.sack.query().filter( - name=n, version=v, release=r, arch="src" - ) - if len(results) == 0: - logging.warning("No sources found for %s", pkg) - else: - src = results[0] - sources.add(PackageItem.from_dnf(src)) + if not no_sources: + n, v, r = strip_suffix(pkg.sourcerpm, ".src.rpm").rsplit("-", 2) + results = base.sack.query().filter( + name=n, version=v, release=r, arch="src" + ) + if len(results) == 0: + logging.warning("No sources found for %s", pkg) + else: + src = results[0] + sources.add(PackageItem.from_dnf(src)) for repoid in modular_repos: repo = base.repos[repoid] @@ -245,6 +247,7 @@ def process_arch( reinstall_packages: set[str], module_enable: set[str], module_disable: set[str], + no_sources: bool, ): logging.info("Running solver for %s", arch) @@ -258,6 +261,7 @@ def process_arch( reinstall_packages, module_enable, module_disable, + no_sources, ) return { @@ -404,6 +408,7 @@ def main(): context = config.get("context", {}) allowerasing = args.allowerasing or config.get("allowerasing", False) + no_sources = config.get("noSources", False) local = args.local_system or context.get("localSystem") if local and arches != [platform.machine()]: @@ -459,6 +464,7 @@ def main(): module_disable=set( filter_for_arch(arch, config.get("moduleDisable", [])) ), + no_sources=no_sources, ) ) diff --git a/rpm_lockfile/schema.py b/rpm_lockfile/schema.py index 77563c4..78e79b9 100644 --- a/rpm_lockfile/schema.py +++ b/rpm_lockfile/schema.py @@ -126,6 +126,7 @@ def get_schema(): ], }, "allowerasing": {"type": "boolean"}, + "noSources": {"type": "boolean"}, }, "required": ["contentOrigin"], "additionalProperties": False,