Skip to content

Commit

Permalink
Update linters
Browse files Browse the repository at this point in the history
  • Loading branch information
jschwartzentruber committed Jan 31, 2025
1 parent 45072bf commit 858860f
Show file tree
Hide file tree
Showing 14 changed files with 125 additions and 83 deletions.
33 changes: 9 additions & 24 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,27 +1,12 @@
repos:
- repo: https://github.com/pycqa/isort
rev: 5.13.2
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.9.4
hooks:
- id: isort
- repo: https://github.com/asottile/yesqa
rev: v1.5.0
hooks:
- id: yesqa
- repo: https://github.com/asottile/pyupgrade
rev: v3.16.0
hooks:
- id: pyupgrade
args: ['--py39-plus']
- repo: https://github.com/ambv/black
rev: 24.4.2
hooks:
- id: black
- repo: https://github.com/pycqa/flake8
rev: 7.1.0
hooks:
- id: flake8
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- id: ruff-format
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.6.0
rev: v5.0.0
hooks:
- id: check-ast
- id: check-docstring-first
Expand All @@ -37,17 +22,17 @@ repos:
args: ['--django']
- id: check-json
- repo: https://github.com/codespell-project/codespell
rev: v2.3.0
rev: v2.4.1
hooks:
- id: codespell
exclude_types: [json]
exclude: ^tests/cassettes/
- repo: https://github.com/marco-c/taskcluster_yml_validator
rev: v0.0.11
rev: v0.0.12
hooks:
- id: taskcluster_yml
- repo: https://github.com/MozillaSecurity/orion-ci
rev: v0.0.9
rev: v0.0.11
hooks:
- id: orion_ci
- repo: meta
Expand Down
4 changes: 4 additions & 0 deletions .taskcluster.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ tasks:
version: "3.12"
env:
TOXENV: py312,lint
- name: tests python 3.13
version: "3.13"
env:
TOXENV: py313,lint
- name: tests python 3.9 (macos)
version: "3.9"
platform: macos
Expand Down
34 changes: 30 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ exclude_lines = [
"pragma: no cover",
]

[tool.isort]
known_first_party = "fuzzfetch"
profile = "black"

[tool.mypy]
strict = true
ignore_missing_imports = true
Expand All @@ -47,4 +43,34 @@ disable = [
[tool.pytest.ini_options]
log_level = "DEBUG"

[tool.ruff]
fix = true
target-version = "py39"

[tool.ruff.lint]
select = [
# flake8-comprehensions
"C4",
# pycodestyle
"E",
# Pyflakes
"F",
# Flynt
"FLY",
# isort
"I",
# Perflint
"PERF",
# Ruff-specific rules
"RUF",
# flake8-simplify
"SIM",
# flake8-type-checking
"TCH",
# pyupgrade
"UP",
# pycodestyle
"W",
]

[tool.setuptools_scm]
7 changes: 5 additions & 2 deletions src/fuzzfetch/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,23 @@
import itertools
import platform as std_platform
from argparse import ArgumentParser, Namespace
from collections.abc import Sequence
from logging import getLogger
from pathlib import Path
from typing import TYPE_CHECKING

from .models import BuildSearchOrder, Platform
from .utils import extract_branch_from_ns, is_namespace

if TYPE_CHECKING:
from collections.abc import Sequence

LOG = getLogger("fuzzfetch")


class FetcherArgs:
"""Class for parsing and recording Fetcher arguments"""

DEFAULT_TARGETS = ["firefox"]
DEFAULT_TARGETS = ("firefox",)

BUILD_OPTIONS = (
# Build flags
Expand Down
23 changes: 12 additions & 11 deletions src/fuzzfetch/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
import re
import shutil
import tempfile
from collections.abc import Sequence
from contextlib import suppress
from datetime import datetime, timedelta
from importlib.metadata import PackageNotFoundError, version
from pathlib import Path
from typing import Any
from typing import TYPE_CHECKING, Any

from pytz import timezone

Expand All @@ -29,6 +29,9 @@
from .path import rmtree as junction_rmtree
from .utils import _create_utc_datetime, is_date, is_namespace, is_rev

if TYPE_CHECKING:
from collections.abc import Sequence

try:
__version__ = version("fuzzfetch")
except PackageNotFoundError:
Expand Down Expand Up @@ -402,7 +405,7 @@ def resolve_targets(self, targets: Sequence[str]) -> None:
for target in targets_remaining:
try:
resolve_url(self.artifact_url(f"{target}.tests.tar.gz"))
except FetcherException:
except FetcherException: # noqa: PERF203
resolve_url(self.artifact_url(f"{target}.tests.zip"))

def extract_build(self, path: PathArg) -> None:
Expand Down Expand Up @@ -500,16 +503,14 @@ def extract_build(self, path: PathArg) -> None:
else:
sym_path = path / "symbols"
sym_path.mkdir()
try:
# fuzzing debug builds no longer have crashreporter-symbols.zip
# (bug 1649062)
# we want to maintain support for older builds for now
with suppress(FetcherException):
self.extract_zip(
self.artifact_url("crashreporter-symbols.zip"),
path=sym_path,
)
except FetcherException:
# fuzzing debug builds no longer have crashreporter-symbols.zip
# (bug 1649062)
# we want to maintain support for older builds for now
pass

if "searchfox" in targets_remaining:
targets_remaining.remove("searchfox")
Expand All @@ -524,7 +525,7 @@ def extract_build(self, path: PathArg) -> None:
for target in targets_remaining:
try:
self.extract_tar(self.artifact_url(f"{target}.tests.tar.gz"), path=path)
except FetcherException:
except FetcherException: # noqa: PERF203
self.extract_zip(self.artifact_url(f"{target}.tests.zip"), path=path)

# used by Pernosco to locate source ('\n' is expected)
Expand Down Expand Up @@ -769,7 +770,7 @@ def main(cls) -> int:
(out / "download").mkdir(parents=True)
with (out / "download" / "firefox-temp.txt").open("a") as dl_fd:
dl_fd.write(f"buildID={obj.id}{os.linesep}")
except: # noqa
except:
if out.is_dir():
junction_rmtree(out)
raise
Expand Down
5 changes: 4 additions & 1 deletion src/fuzzfetch/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@

import time
from logging import getLogger
from typing import TYPE_CHECKING

from requests import Response, Session
from requests.exceptions import RequestException

from .errors import FetcherException
from .path import PathArg

if TYPE_CHECKING:
from .path import PathArg

HTTP_SESSION = Session()
LOG = getLogger("fuzzfetch")
Expand Down
77 changes: 46 additions & 31 deletions src/fuzzfetch/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@

import itertools
import platform as std_platform
from collections.abc import Iterable, Iterator
from dataclasses import dataclass, fields
from datetime import datetime
from enum import Enum
from logging import getLogger
from typing import Any
from types import MappingProxyType
from typing import TYPE_CHECKING, Any

from pytz import timezone
from requests import RequestException
Expand All @@ -21,6 +21,9 @@
from .errors import FetcherException
from .utils import is_date, is_namespace, is_rev

if TYPE_CHECKING:
from collections.abc import Iterable, Iterator

LOG = getLogger("fuzzfetch")


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

SUPPORTED = {
"Darwin": {
"arm64": "macosx64-aarch64",
"x86_64": "macosx64",
},
"Linux": {
"arm64": "linux64-aarch64",
"x86": "linux",
"x86_64": "linux64",
},
"Windows": {
"arm64": "win64-aarch64",
"x86": "win32",
"x86_64": "win64",
},
"Android": {
"arm": "android-arm",
"arm64": "android-aarch64",
"x86": "android-x86",
"x86_64": "android-x86_64",
},
}
CPU_ALIASES = {
"ARM64": "arm64",
"AMD64": "x86_64",
"aarch64": "arm64",
"i686": "x86",
"x64": "x86_64",
}
SUPPORTED = MappingProxyType(
{
"Darwin": MappingProxyType(
{
"arm64": "macosx64-aarch64",
"x86_64": "macosx64",
}
),
"Linux": MappingProxyType(
{
"arm64": "linux64-aarch64",
"x86": "linux",
"x86_64": "linux64",
}
),
"Windows": MappingProxyType(
{
"arm64": "win64-aarch64",
"x86": "win32",
"x86_64": "win64",
}
),
"Android": MappingProxyType(
{
"arm": "android-arm",
"arm64": "android-aarch64",
"x86": "android-x86",
"x86_64": "android-x86_64",
}
),
}
)
CPU_ALIASES = MappingProxyType(
{
"ARM64": "arm64",
"AMD64": "x86_64",
"aarch64": "arm64",
"i686": "x86",
"x64": "x86_64",
}
)

def __init__(
self,
Expand Down
1 change: 1 addition & 0 deletions src/fuzzfetch/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
"""Assorted fuzzfetch utilities"""

import re
from datetime import datetime

Expand Down
2 changes: 1 addition & 1 deletion tests/test_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
def test_default_target(fetcher_args):
"""Test default target is set to DEFAULT_TARGETS when --target not specified."""
args = fetcher_args.parse_args([])
assert args.target == FetcherArgs.DEFAULT_TARGETS
assert args.target == list(FetcherArgs.DEFAULT_TARGETS)


def test_custom_target(fetcher_args):
Expand Down
1 change: 1 addition & 0 deletions tests/test_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
"""Fuzzfetch download module tests"""

import pytest # pylint: disable=import-error

from fuzzfetch.download import (
Expand Down
18 changes: 9 additions & 9 deletions tests/test_fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,9 @@ def get_builds_to_test():
continue
if os_ == "Linux" and cpu == "x86" and flags.fuzzing and esr:
continue
if branch == "esr-stable":
if cpu.startswith("arm"):
# arm builds aren't available for esr-stable
continue
if branch == "esr-stable" and cpu.startswith("arm"):
# arm builds aren't available for esr-stable
continue

yield pytest.param(
branch,
Expand All @@ -139,12 +138,13 @@ def test_metadata(branch, build_flags, os_, cpu, as_args):
"""
platform_ = Platform(os_, cpu)
if as_args:
args = []
for field in fields(BuildFlags):
if getattr(build_flags, field.name):
args.append(f"--{field.name}")
args = [
f"--{field.name}"
for field in fields(BuildFlags)
if getattr(build_flags, field.name)
]
fetcher = Fetcher.from_args(
["--branch", branch, "--cpu", cpu, "--os", os_] + args
["--branch", branch, "--cpu", cpu, "--os", os_, *args]
)[0]
else:
if branch.startswith("esr"):
Expand Down
1 change: 1 addition & 0 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
"""Fuzzfetch internal model tests"""

from dataclasses import fields
from datetime import datetime
from unittest.mock import patch
Expand Down
Loading

0 comments on commit 858860f

Please sign in to comment.