Skip to content

Commit 858860f

Browse files
Update linters
1 parent 45072bf commit 858860f

14 files changed

+125
-83
lines changed

.pre-commit-config.yaml

+9-24
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,12 @@
11
repos:
2-
- repo: https://github.com/pycqa/isort
3-
rev: 5.13.2
2+
- repo: https://github.com/astral-sh/ruff-pre-commit
3+
rev: v0.9.4
44
hooks:
5-
- id: isort
6-
- repo: https://github.com/asottile/yesqa
7-
rev: v1.5.0
8-
hooks:
9-
- id: yesqa
10-
- repo: https://github.com/asottile/pyupgrade
11-
rev: v3.16.0
12-
hooks:
13-
- id: pyupgrade
14-
args: ['--py39-plus']
15-
- repo: https://github.com/ambv/black
16-
rev: 24.4.2
17-
hooks:
18-
- id: black
19-
- repo: https://github.com/pycqa/flake8
20-
rev: 7.1.0
21-
hooks:
22-
- id: flake8
5+
- id: ruff
6+
args: [--fix, --exit-non-zero-on-fix]
7+
- id: ruff-format
238
- repo: https://github.com/pre-commit/pre-commit-hooks
24-
rev: v4.6.0
9+
rev: v5.0.0
2510
hooks:
2611
- id: check-ast
2712
- id: check-docstring-first
@@ -37,17 +22,17 @@ repos:
3722
args: ['--django']
3823
- id: check-json
3924
- repo: https://github.com/codespell-project/codespell
40-
rev: v2.3.0
25+
rev: v2.4.1
4126
hooks:
4227
- id: codespell
4328
exclude_types: [json]
4429
exclude: ^tests/cassettes/
4530
- repo: https://github.com/marco-c/taskcluster_yml_validator
46-
rev: v0.0.11
31+
rev: v0.0.12
4732
hooks:
4833
- id: taskcluster_yml
4934
- repo: https://github.com/MozillaSecurity/orion-ci
50-
rev: v0.0.9
35+
rev: v0.0.11
5136
hooks:
5237
- id: orion_ci
5338
- repo: meta

.taskcluster.yml

+4
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ tasks:
5050
version: "3.12"
5151
env:
5252
TOXENV: py312,lint
53+
- name: tests python 3.13
54+
version: "3.13"
55+
env:
56+
TOXENV: py313,lint
5357
- name: tests python 3.9 (macos)
5458
version: "3.9"
5559
platform: macos

pyproject.toml

+30-4
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ exclude_lines = [
1717
"pragma: no cover",
1818
]
1919

20-
[tool.isort]
21-
known_first_party = "fuzzfetch"
22-
profile = "black"
23-
2420
[tool.mypy]
2521
strict = true
2622
ignore_missing_imports = true
@@ -47,4 +43,34 @@ disable = [
4743
[tool.pytest.ini_options]
4844
log_level = "DEBUG"
4945

46+
[tool.ruff]
47+
fix = true
48+
target-version = "py39"
49+
50+
[tool.ruff.lint]
51+
select = [
52+
# flake8-comprehensions
53+
"C4",
54+
# pycodestyle
55+
"E",
56+
# Pyflakes
57+
"F",
58+
# Flynt
59+
"FLY",
60+
# isort
61+
"I",
62+
# Perflint
63+
"PERF",
64+
# Ruff-specific rules
65+
"RUF",
66+
# flake8-simplify
67+
"SIM",
68+
# flake8-type-checking
69+
"TCH",
70+
# pyupgrade
71+
"UP",
72+
# pycodestyle
73+
"W",
74+
]
75+
5076
[tool.setuptools_scm]

src/fuzzfetch/args.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,23 @@
88
import itertools
99
import platform as std_platform
1010
from argparse import ArgumentParser, Namespace
11-
from collections.abc import Sequence
1211
from logging import getLogger
1312
from pathlib import Path
13+
from typing import TYPE_CHECKING
1414

1515
from .models import BuildSearchOrder, Platform
1616
from .utils import extract_branch_from_ns, is_namespace
1717

18+
if TYPE_CHECKING:
19+
from collections.abc import Sequence
20+
1821
LOG = getLogger("fuzzfetch")
1922

2023

2124
class FetcherArgs:
2225
"""Class for parsing and recording Fetcher arguments"""
2326

24-
DEFAULT_TARGETS = ["firefox"]
27+
DEFAULT_TARGETS = ("firefox",)
2528

2629
BUILD_OPTIONS = (
2730
# Build flags

src/fuzzfetch/core.py

+12-11
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
import re
1313
import shutil
1414
import tempfile
15-
from collections.abc import Sequence
15+
from contextlib import suppress
1616
from datetime import datetime, timedelta
1717
from importlib.metadata import PackageNotFoundError, version
1818
from pathlib import Path
19-
from typing import Any
19+
from typing import TYPE_CHECKING, Any
2020

2121
from pytz import timezone
2222

@@ -29,6 +29,9 @@
2929
from .path import rmtree as junction_rmtree
3030
from .utils import _create_utc_datetime, is_date, is_namespace, is_rev
3131

32+
if TYPE_CHECKING:
33+
from collections.abc import Sequence
34+
3235
try:
3336
__version__ = version("fuzzfetch")
3437
except PackageNotFoundError:
@@ -402,7 +405,7 @@ def resolve_targets(self, targets: Sequence[str]) -> None:
402405
for target in targets_remaining:
403406
try:
404407
resolve_url(self.artifact_url(f"{target}.tests.tar.gz"))
405-
except FetcherException:
408+
except FetcherException: # noqa: PERF203
406409
resolve_url(self.artifact_url(f"{target}.tests.zip"))
407410

408411
def extract_build(self, path: PathArg) -> None:
@@ -500,16 +503,14 @@ def extract_build(self, path: PathArg) -> None:
500503
else:
501504
sym_path = path / "symbols"
502505
sym_path.mkdir()
503-
try:
506+
# fuzzing debug builds no longer have crashreporter-symbols.zip
507+
# (bug 1649062)
508+
# we want to maintain support for older builds for now
509+
with suppress(FetcherException):
504510
self.extract_zip(
505511
self.artifact_url("crashreporter-symbols.zip"),
506512
path=sym_path,
507513
)
508-
except FetcherException:
509-
# fuzzing debug builds no longer have crashreporter-symbols.zip
510-
# (bug 1649062)
511-
# we want to maintain support for older builds for now
512-
pass
513514

514515
if "searchfox" in targets_remaining:
515516
targets_remaining.remove("searchfox")
@@ -524,7 +525,7 @@ def extract_build(self, path: PathArg) -> None:
524525
for target in targets_remaining:
525526
try:
526527
self.extract_tar(self.artifact_url(f"{target}.tests.tar.gz"), path=path)
527-
except FetcherException:
528+
except FetcherException: # noqa: PERF203
528529
self.extract_zip(self.artifact_url(f"{target}.tests.zip"), path=path)
529530

530531
# used by Pernosco to locate source ('\n' is expected)
@@ -769,7 +770,7 @@ def main(cls) -> int:
769770
(out / "download").mkdir(parents=True)
770771
with (out / "download" / "firefox-temp.txt").open("a") as dl_fd:
771772
dl_fd.write(f"buildID={obj.id}{os.linesep}")
772-
except: # noqa
773+
except:
773774
if out.is_dir():
774775
junction_rmtree(out)
775776
raise

src/fuzzfetch/download.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@
77

88
import time
99
from logging import getLogger
10+
from typing import TYPE_CHECKING
1011

1112
from requests import Response, Session
1213
from requests.exceptions import RequestException
1314

1415
from .errors import FetcherException
15-
from .path import PathArg
16+
17+
if TYPE_CHECKING:
18+
from .path import PathArg
1619

1720
HTTP_SESSION = Session()
1821
LOG = getLogger("fuzzfetch")

src/fuzzfetch/models.py

+46-31
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77

88
import itertools
99
import platform as std_platform
10-
from collections.abc import Iterable, Iterator
1110
from dataclasses import dataclass, fields
1211
from datetime import datetime
1312
from enum import Enum
1413
from logging import getLogger
15-
from typing import Any
14+
from types import MappingProxyType
15+
from typing import TYPE_CHECKING, Any
1616

1717
from pytz import timezone
1818
from requests import RequestException
@@ -21,6 +21,9 @@
2121
from .errors import FetcherException
2222
from .utils import is_date, is_namespace, is_rev
2323

24+
if TYPE_CHECKING:
25+
from collections.abc import Iterable, Iterator
26+
2427
LOG = getLogger("fuzzfetch")
2528

2629

@@ -351,35 +354,47 @@ def hash(self) -> str:
351354
class Platform:
352355
"""Class representing target OS and CPU, and how it maps to a Gecko mozconfig"""
353356

354-
SUPPORTED = {
355-
"Darwin": {
356-
"arm64": "macosx64-aarch64",
357-
"x86_64": "macosx64",
358-
},
359-
"Linux": {
360-
"arm64": "linux64-aarch64",
361-
"x86": "linux",
362-
"x86_64": "linux64",
363-
},
364-
"Windows": {
365-
"arm64": "win64-aarch64",
366-
"x86": "win32",
367-
"x86_64": "win64",
368-
},
369-
"Android": {
370-
"arm": "android-arm",
371-
"arm64": "android-aarch64",
372-
"x86": "android-x86",
373-
"x86_64": "android-x86_64",
374-
},
375-
}
376-
CPU_ALIASES = {
377-
"ARM64": "arm64",
378-
"AMD64": "x86_64",
379-
"aarch64": "arm64",
380-
"i686": "x86",
381-
"x64": "x86_64",
382-
}
357+
SUPPORTED = MappingProxyType(
358+
{
359+
"Darwin": MappingProxyType(
360+
{
361+
"arm64": "macosx64-aarch64",
362+
"x86_64": "macosx64",
363+
}
364+
),
365+
"Linux": MappingProxyType(
366+
{
367+
"arm64": "linux64-aarch64",
368+
"x86": "linux",
369+
"x86_64": "linux64",
370+
}
371+
),
372+
"Windows": MappingProxyType(
373+
{
374+
"arm64": "win64-aarch64",
375+
"x86": "win32",
376+
"x86_64": "win64",
377+
}
378+
),
379+
"Android": MappingProxyType(
380+
{
381+
"arm": "android-arm",
382+
"arm64": "android-aarch64",
383+
"x86": "android-x86",
384+
"x86_64": "android-x86_64",
385+
}
386+
),
387+
}
388+
)
389+
CPU_ALIASES = MappingProxyType(
390+
{
391+
"ARM64": "arm64",
392+
"AMD64": "x86_64",
393+
"aarch64": "arm64",
394+
"i686": "x86",
395+
"x64": "x86_64",
396+
}
397+
)
383398

384399
def __init__(
385400
self,

src/fuzzfetch/utils.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
33
# You can obtain one at http://mozilla.org/MPL/2.0/.
44
"""Assorted fuzzfetch utilities"""
5+
56
import re
67
from datetime import datetime
78

tests/test_args.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
def test_default_target(fetcher_args):
1414
"""Test default target is set to DEFAULT_TARGETS when --target not specified."""
1515
args = fetcher_args.parse_args([])
16-
assert args.target == FetcherArgs.DEFAULT_TARGETS
16+
assert args.target == list(FetcherArgs.DEFAULT_TARGETS)
1717

1818

1919
def test_custom_target(fetcher_args):

tests/test_download.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
33
# You can obtain one at http://mozilla.org/MPL/2.0/.
44
"""Fuzzfetch download module tests"""
5+
56
import pytest # pylint: disable=import-error
67

78
from fuzzfetch.download import (

tests/test_fetch.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,9 @@ def get_builds_to_test():
115115
continue
116116
if os_ == "Linux" and cpu == "x86" and flags.fuzzing and esr:
117117
continue
118-
if branch == "esr-stable":
119-
if cpu.startswith("arm"):
120-
# arm builds aren't available for esr-stable
121-
continue
118+
if branch == "esr-stable" and cpu.startswith("arm"):
119+
# arm builds aren't available for esr-stable
120+
continue
122121

123122
yield pytest.param(
124123
branch,
@@ -139,12 +138,13 @@ def test_metadata(branch, build_flags, os_, cpu, as_args):
139138
"""
140139
platform_ = Platform(os_, cpu)
141140
if as_args:
142-
args = []
143-
for field in fields(BuildFlags):
144-
if getattr(build_flags, field.name):
145-
args.append(f"--{field.name}")
141+
args = [
142+
f"--{field.name}"
143+
for field in fields(BuildFlags)
144+
if getattr(build_flags, field.name)
145+
]
146146
fetcher = Fetcher.from_args(
147-
["--branch", branch, "--cpu", cpu, "--os", os_] + args
147+
["--branch", branch, "--cpu", cpu, "--os", os_, *args]
148148
)[0]
149149
else:
150150
if branch.startswith("esr"):

tests/test_models.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
33
# You can obtain one at http://mozilla.org/MPL/2.0/.
44
"""Fuzzfetch internal model tests"""
5+
56
from dataclasses import fields
67
from datetime import datetime
78
from unittest.mock import patch

0 commit comments

Comments
 (0)