Skip to content

Commit 7a17fbd

Browse files
committed
enable ruff linter
Signed-off-by: Arthur Zamarin <arthurzam@gentoo.org>
1 parent e1129c0 commit 7a17fbd

File tree

8 files changed

+25
-15
lines changed

8 files changed

+25
-15
lines changed

.github/workflows/test.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ jobs:
126126
- name: Run linting tools
127127
run: pylint --exit-zero src/pkgcheck
128128

129+
- uses: astral-sh/ruff-action@v3
130+
with:
131+
args: "check --check --diff"
132+
129133
format:
130134
runs-on: ubuntu-latest
131135
if: inputs.disable-format-check == ''

pyproject.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ line-length = 100
8989
target-version = "py311"
9090
[tool.ruff.lint]
9191
extend-select = ["I"]
92+
ignore = [
93+
"E741", # ambiguous variable name
94+
]
9295

9396
[tool.black]
9497
line-length = 100

src/pkgcheck/checks/imlate.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,14 @@ def feed(self, pkgset):
105105
lagging -= {"~" + x for x in newer_slot_stables}
106106
lagging -= stable
107107
if lagging:
108-
stable_kwds = (x for x in pkg.keywords if not x[0] in ("~", "-"))
108+
stable_kwds = (x for x in pkg.keywords if x[0] not in ("~", "-"))
109109
yield LaggingStable(slot, sorted(stable_kwds), sorted(lagging), pkg=pkg)
110110

111111
unstable_keywords = {x for x in pkg.keywords if x[0] == "~"}
112112
potential = self.target_arches.intersection(unstable_keywords)
113113
potential -= lagging | stable
114114
if potential:
115-
stable_kwds = (x for x in pkg.keywords if not x[0] in ("~", "-"))
115+
stable_kwds = (x for x in pkg.keywords if x[0] not in ("~", "-"))
116116
yield PotentialStable(slot, sorted(stable_kwds), sorted(potential), pkg=pkg)
117117

118118
break

src/pkgcheck/checks/network.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -388,10 +388,10 @@ def _provenance_check(self, filename, url, *, pkg):
388388
result = None
389389
try:
390390
self.session.head(url, allow_redirects=False)
391-
except RequestError as e:
391+
except RequestError:
392392
pass
393393
except SSLError as e:
394-
result = SSLCertificateError(attr, url, str(e), pkg=pkg)
394+
result = SSLCertificateError("SRC_URI", url, str(e), pkg=pkg)
395395
else:
396396
result = PyPIAttestationAvailable(filename, pkg=pkg)
397397
return result

src/pkgcheck/reporters.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,9 @@ class JsonReporter(StreamReporter):
177177

178178
def _consume_reports_generator(self) -> T_process_report:
179179
# arbitrarily nested defaultdicts
180-
json_dict = lambda: defaultdict(json_dict)
180+
def json_dict():
181+
return defaultdict(json_dict)
182+
181183
# scope to data conversion mapping
182184
scope_map = {
183185
base.version_scope: lambda data, r: data[r.category][r.package][r.version],

src/pkgcheck/scripts/argparse_actions.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,10 @@ class KeywordArgs(arghparse.CommaSeparatedNegations):
282282
"""Filter enabled keywords by selected keywords."""
283283

284284
def __call__(self, parser, namespace, values, option_string=None):
285+
def replace_aliases(x):
286+
return objects.KEYWORDS.aliases.get(x, [x])
287+
285288
disabled, enabled = self.parse_values(values)
286-
replace_aliases = lambda x: objects.KEYWORDS.aliases.get(x, [x])
287289

288290
# expand keyword aliases to keyword lists
289291
disabled = list(chain.from_iterable(map(replace_aliases, disabled)))

tests/checks/test_metadata.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -408,26 +408,26 @@ def test_repo_with_no_settings(self):
408408
self.assertNoReport(check, self.mk_pkg(eapi=eapi_str))
409409

410410
def test_unknown_eapis(self):
411-
for eapi in ("blah", "9999"):
411+
for eapi_val in ("blah", "9999"):
412412
check = self.mk_check()
413413
pkg_path = pjoin(self.repo.location, "dev-util", "foo")
414414
os.makedirs(pkg_path)
415415
with open(pjoin(pkg_path, "foo-0.ebuild"), "w") as f:
416-
f.write(f"EAPI={eapi}\n")
416+
f.write(f"EAPI={eapi_val}\n")
417417
r = self.assertReport(check, self.repo)
418418
assert isinstance(r, metadata.InvalidEapi)
419-
assert f"EAPI '{eapi}' is not supported" in str(r)
419+
assert f"EAPI '{eapi_val}' is not supported" in str(r)
420420

421421
def test_invalid_eapis(self):
422-
for eapi in ("invalid!", "${EAPI}"):
422+
for eapi_val in ("invalid!", "${EAPI}"):
423423
check = self.mk_check()
424424
pkg_path = pjoin(self.repo.location, "dev-util", "foo")
425425
os.makedirs(pkg_path)
426426
with open(pjoin(pkg_path, "foo-0.ebuild"), "w") as f:
427-
f.write(f"EAPI={eapi}\n")
427+
f.write(f"EAPI={eapi_val}\n")
428428
r = self.assertReport(check, self.repo)
429429
assert isinstance(r, metadata.InvalidEapi)
430-
assert f"invalid EAPI '{eapi}'" in str(r)
430+
assert f"invalid EAPI '{eapi_val}'" in str(r)
431431

432432
def test_sourcing_error(self):
433433
check = self.mk_check()
@@ -619,7 +619,6 @@ def test_required_addons(self):
619619
def mk_check(self, *args, options=None, **kwargs):
620620
options = options if options is not None else {}
621621
options = self.get_options(**options)
622-
profiles = [misc.FakeProfile(iuse_effective=["x86"])]
623622
use_addon = addons.UseAddon(options)
624623
check = self.check_kls(options, *args, use_addon=use_addon, **kwargs)
625624
return check
@@ -1378,5 +1377,5 @@ def test_with_multiple_unpackers_one_missing(self):
13781377
self.mk_check(), self.mk_pkg([".zip", ".7z"], DEPEND="app-arch/unzip")
13791378
)
13801379
assert isinstance(r, metadata.MissingUnpackerDep)
1381-
assert r.filenames == (f"diffball-2.7.1.7z",)
1380+
assert r.filenames == ("diffball-2.7.1.7z",)
13821381
assert r.unpackers == ("app-arch/7zip",)

tests/scripts/test_pkgcheck_scan.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ def _load_expected_data(self, base: pathlib.Path) -> _expected_data_result:
604604

605605
custom_handler = None
606606
try:
607-
with (custom_handler_path := base / "handler.py").open() as f:
607+
with (custom_handler_path := base / "handler.py").open():
608608
# We can't import since it's not a valid python directory layout, nor do
609609
# want to pollute the namespace.
610610
module = importlib.machinery.SourceFileLoader(

0 commit comments

Comments
 (0)