reset checks after each package, thanks to Daniel García Moreno

This commit is contained in:
Tom Callaway 2024-01-04 08:42:22 -05:00
parent b63b18b807
commit 6ea1ab8f37
2 changed files with 79 additions and 1 deletions

71
1163.patch Normal file
View File

@ -0,0 +1,71 @@
From 50a33b41c67342c4b0817670a184c0ba263e77b5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Moreno?= <dani@danigm.net>
Date: Wed, 3 Jan 2024 15:00:55 +0100
Subject: [PATCH] lint: Reset all checks for each package
Some check classes keep state during checking and this cause problems
when checking several files with the same call.
This patch resets all the checks for each package to check. This is a
quick solution, maybe the best way to handle this is to reset the state
for each check in with a common method in the AbstractCheck, a common
way to handle and reset the state to avoid this problem in the future.
Fix https://github.com/rpm-software-management/rpmlint/issues/1161
---
rpmlint/lint.py | 10 ++++++++++
test/test_cli.py | 9 +++++++++
2 files changed, 19 insertions(+)
diff --git a/rpmlint/lint.py b/rpmlint/lint.py
index 5372e749c..b00937ca2 100644
--- a/rpmlint/lint.py
+++ b/rpmlint/lint.py
@@ -224,6 +224,7 @@ def _print_header(self):
def validate_installed_packages(self, packages):
for pkg in packages:
self.run_checks(pkg, pkg == packages[-1])
+ self.reset_checks()
def validate_files(self, files):
"""
@@ -243,6 +244,7 @@ def validate_files(self, files):
packages = sorted(packages)
for pkg in packages:
self.validate_file(pkg, pkg == packages[-1])
+ self.reset_checks()
def _expand_filelist(self, files):
packages = []
@@ -331,6 +333,14 @@ def load_checks(self):
if not selected_checks or check in selected_checks:
self.checks[check] = self.load_check(check)
+ def reset_checks(self):
+ """
+ Reset all check objects to set to the default state
+ """
+ to_reset = self.checks.keys()
+ for check in to_reset:
+ self.checks[check] = self.load_check(check)
+
def load_check(self, name):
"""Load a (check) module by its name, unless it is already loaded."""
module = importlib.import_module(f'.{name}', package='rpmlint.checks')
diff --git a/test/test_cli.py b/test/test_cli.py
index 2f0c55f08..03aea43a1 100644
--- a/test/test_cli.py
+++ b/test/test_cli.py
@@ -83,3 +83,12 @@ def test_parsing_fedora_conf(test_arguments):
if score_key.startswith('percent-in-'):
continue
assert score_key in checks
+
+
+def test_reset_check():
+ files = ['test/spec/SpecCheck2.spec', 'test/spec/SpecCheck3.spec']
+ options = process_lint_args(['--checks', 'SpecCheck'] + files)
+ lint = Lint(options)
+ lint.run()
+ out = lint.output.print_results(lint.output.results, lint.config)
+ assert 'more-than-one-%changelog-section' not in out

View File

@ -3,7 +3,7 @@
Name: rpmlint
Version: 2.5.0
Release: 2%{?dist}
Release: 3%{?dist}
Summary: Tool for checking common errors in RPM packages
License: GPL-2.0-or-later
URL: https://github.com/rpm-software-management/rpmlint
@ -14,6 +14,10 @@ Source3: scoring.toml
Source4: users-groups.toml
Source5: warn-on-functions.toml
# Fix from @danigm to reset checks for each package
# https://github.com/rpm-software-management/rpmlint/pull/1163
Patch0: https://patch-diff.githubusercontent.com/raw/rpm-software-management/rpmlint/pull/1163.patch
BuildArch: noarch
# use git to apply patches; it handles binary diffs
@ -99,6 +103,9 @@ cp -a %{SOURCE1} %{SOURCE3} %{SOURCE4} %{SOURCE5} %{buildroot}%{_sysconfdir}/xdg
%{_bindir}/rpmlint
%changelog
* Thu Jan 4 2024 Tom Callaway <spot@fedoraproject.org> - 2.5.0-3
- reset checks after each package, thanks to Daniel García Moreno
* Sat Nov 25 2023 Zephyr Lykos <fedora@mochaa.ws> - 2.5.0-2
- Migrate patches to pyproject.toml (rhbz#1899279)