commit: 7a17fbda4e1faab973adc6720aed633cfd7e48d9
Author: Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
AuthorDate: Fri Jan 2 10:54:48 2026 +0000
Commit: Arthur Zamarin <arthurzam <AT> gentoo <DOT> org>
CommitDate: Fri Jan 2 10:55:05 2026 +0000
URL:
https://gitweb.gentoo.org/proj/pkgcore/pkgcheck.git/commit/?id=7a17fbda
enable ruff linter
Signed-off-by: Arthur Zamarin <arthurzam <AT> gentoo.org>
.github/workflows/test.yml | 4 ++++
pyproject.toml | 3 +++
src/pkgcheck/checks/imlate.py | 4 ++--
src/pkgcheck/checks/network.py | 4 ++--
src/pkgcheck/reporters.py | 4 +++-
src/pkgcheck/scripts/argparse_actions.py | 4 +++-
tests/checks/test_metadata.py | 15 +++++++--------
tests/scripts/test_pkgcheck_scan.py | 2 +-
8 files changed, 25 insertions(+), 15 deletions(-)
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index 1a772f19..646eafb3 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -126,6 +126,10 @@ jobs:
- name: Run linting tools
run: pylint --exit-zero src/pkgcheck
+ - uses: astral-sh/ruff-action@v3
+ with:
+ args: "check --check --diff"
+
format:
runs-on: ubuntu-latest
if: inputs.disable-format-check == ''
diff --git a/pyproject.toml b/pyproject.toml
index ab822cdf..52f118c6 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -89,6 +89,9 @@ line-length = 100
target-version = "py311"
[tool.ruff.lint]
extend-select = ["I"]
+ignore = [
+ "E741", # ambiguous variable name
+]
[tool.black]
line-length = 100
diff --git a/src/pkgcheck/checks/imlate.py b/src/pkgcheck/checks/imlate.py
index ee0da6d8..661b6a50 100644
--- a/src/pkgcheck/checks/imlate.py
+++ b/src/pkgcheck/checks/imlate.py
@@ -105,14 +105,14 @@ class ImlateCheck(Check):
lagging -= {"~" + x for x in newer_slot_stables}
lagging -= stable
if lagging:
- stable_kwds = (x for x in pkg.keywords if not x[0] in
("~", "-"))
+ stable_kwds = (x for x in pkg.keywords if x[0] not in
("~", "-"))
yield LaggingStable(slot, sorted(stable_kwds),
sorted(lagging), pkg=pkg)
unstable_keywords = {x for x in pkg.keywords if x[0] == "~"}
potential = self.target_arches.intersection(unstable_keywords)
potential -= lagging | stable
if potential:
- stable_kwds = (x for x in pkg.keywords if not x[0] in
("~", "-"))
+ stable_kwds = (x for x in pkg.keywords if x[0] not in
("~", "-"))
yield PotentialStable(slot, sorted(stable_kwds),
sorted(potential), pkg=pkg)
break
diff --git a/src/pkgcheck/checks/network.py b/src/pkgcheck/checks/network.py
index fb5e2fd1..3ea8214a 100644
--- a/src/pkgcheck/checks/network.py
+++ b/src/pkgcheck/checks/network.py
@@ -388,10 +388,10 @@ class PyPIAttestationAvailableCheck(NetworkCheck):
result = None
try:
self.session.head(url, allow_redirects=False)
- except RequestError as e:
+ except RequestError:
pass
except SSLError as e:
- result = SSLCertificateError(attr, url, str(e), pkg=pkg)
+ result = SSLCertificateError("SRC_URI", url, str(e), pkg=pkg)
else:
result = PyPIAttestationAvailable(filename, pkg=pkg)
return result
diff --git a/src/pkgcheck/reporters.py b/src/pkgcheck/reporters.py
index 0a6119cf..5ced131e 100644
--- a/src/pkgcheck/reporters.py
+++ b/src/pkgcheck/reporters.py
@@ -177,7 +177,9 @@ class JsonReporter(StreamReporter):
def _consume_reports_generator(self) -> T_process_report:
# arbitrarily nested defaultdicts
- json_dict = lambda: defaultdict(json_dict)
+ def json_dict():
+ return defaultdict(json_dict)
+
# scope to data conversion mapping
scope_map = {
base.version_scope: lambda data, r:
data[r.category][r.package][r.version],
diff --git a/src/pkgcheck/scripts/argparse_actions.py
b/src/pkgcheck/scripts/argparse_actions.py
index 4507e10f..508b0f8e 100644
--- a/src/pkgcheck/scripts/argparse_actions.py
+++ b/src/pkgcheck/scripts/argparse_actions.py
@@ -282,8 +282,10 @@ class KeywordArgs(arghparse.CommaSeparatedNegations):
"""Filter enabled keywords by selected keywords."""
def __call__(self, parser, namespace, values, option_string=None):
+ def replace_aliases(x):
+ return objects.KEYWORDS.aliases.get(x, [x])
+
disabled, enabled = self.parse_values(values)
- replace_aliases = lambda x: objects.KEYWORDS.aliases.get(x, [x])
# expand keyword aliases to keyword lists
disabled = list(chain.from_iterable(map(replace_aliases, disabled)))
diff --git a/tests/checks/test_metadata.py b/tests/checks/test_metadata.py
index 6e0d310b..b194b726 100644
--- a/tests/checks/test_metadata.py
+++ b/tests/checks/test_metadata.py
@@ -408,26 +408,26 @@ class TestSourcingCheck(misc.ReportTestCase, misc.Tmpdir):
self.assertNoReport(check, self.mk_pkg(eapi=eapi_str))
def test_unknown_eapis(self):
- for eapi in ("blah", "9999"):
+ for eapi_val in ("blah", "9999"):
check = self.mk_check()
pkg_path = pjoin(self.repo.location, "dev-util", "foo")
os.makedirs(pkg_path)
with open(pjoin(pkg_path, "foo-0.ebuild"), "w") as f:
- f.write(f"EAPI={eapi}\n")
+ f.write(f"EAPI={eapi_val}\n")
r = self.assertReport(check, self.repo)
assert isinstance(r, metadata.InvalidEapi)
- assert f"EAPI '{eapi}' is not supported" in str(r)
+ assert f"EAPI '{eapi_val}' is not supported" in str(r)
def test_invalid_eapis(self):
- for eapi in ("invalid!", "${EAPI}"):
+ for eapi_val in ("invalid!", "${EAPI}"):
check = self.mk_check()
pkg_path = pjoin(self.repo.location, "dev-util", "foo")
os.makedirs(pkg_path)
with open(pjoin(pkg_path, "foo-0.ebuild"), "w") as f:
- f.write(f"EAPI={eapi}\n")
+ f.write(f"EAPI={eapi_val}\n")
r = self.assertReport(check, self.repo)
assert isinstance(r, metadata.InvalidEapi)
- assert f"invalid EAPI '{eapi}'" in str(r)
+ assert f"invalid EAPI '{eapi_val}'" in str(r)
def test_sourcing_error(self):
check = self.mk_check()
@@ -619,7 +619,6 @@ def use_based():
def mk_check(self, *args, options=None, **kwargs):
options = options if options is not None else {}
options = self.get_options(**options)
- profiles = [misc.FakeProfile(iuse_effective=["x86"])]
use_addon = addons.UseAddon(options)
check = self.check_kls(options, *args, use_addon=use_addon,
**kwargs)
return check
@@ -1378,5 +1377,5 @@ class TestMissingUnpackerDepCheck(use_based(),
misc.ReportTestCase):
self.mk_check(), self.mk_pkg([".zip", ".7z"],
DEPEND="app-arch/unzip")
)
assert isinstance(r, metadata.MissingUnpackerDep)
- assert r.filenames == (f"diffball-2.7.1.7z",)
+ assert r.filenames == ("diffball-2.7.1.7z",)
assert r.unpackers == ("app-arch/7zip",)
diff --git a/tests/scripts/test_pkgcheck_scan.py
b/tests/scripts/test_pkgcheck_scan.py
index 4462d8e5..8ae93637 100644
--- a/tests/scripts/test_pkgcheck_scan.py
+++ b/tests/scripts/test_pkgcheck_scan.py
@@ -604,7 +604,7 @@ class TestPkgcheckScan:
custom_handler = None
try:
- with (custom_handler_path := base / "handler.py").open() as f:
+ with (custom_handler_path := base / "handler.py").open():
# We can't import since it's not a valid python directory
layout, nor do
# want to pollute the namespace.
module = importlib.machinery.SourceFileLoader(