diff --git a/services/nyx/nyx_ipc_manager.py b/services/nyx/nyx_ipc_manager.py index 1d358a26..d15f49e8 100644 --- a/services/nyx/nyx_ipc_manager.py +++ b/services/nyx/nyx_ipc_manager.py @@ -11,17 +11,20 @@ from pathlib import Path, PurePosixPath from random import choice, randint from subprocess import TimeoutExpired, check_call, run -from typing import Dict, List, Optional, Set, TextIO +from typing import TYPE_CHECKING + +if TYPE_CHECKING: + from io import TextIOBase def run_generic( - args: List[str], + args: list[str], bindir: Path, cache_path: Path, min_msg_size: int, - ignore_message_types: Set[str], + ignore_message_types: set[str], timeout: int, -) -> Dict[str, int]: +) -> dict[str, int]: unique_msgs = {} env = os.environ.copy() @@ -54,7 +57,7 @@ def run_generic( # PBackgroundIDBFactory::Msg_PBackgroundIDBDatabaseConstructor Size: 576 errlines = out.splitlines() errlines.extend(err.splitlines()) - maybe_too_small: Set[str] = set() + maybe_too_small: set[str] = set() for errline in errlines: if "[OnIPCMessage]" in errline and "unknown IPC msg name" not in errline: components = errline.split(" ") @@ -86,11 +89,11 @@ def run_generic( def run_mochitest_local( bindir: Path, testenv: Path, - mochitest_args: List[str], + mochitest_args: list[str], mochitest_cache_path: Path, min_msg_size: int, - ignore_message_types: Set[str], -) -> Dict[str, int]: + ignore_message_types: set[str], +) -> dict[str, int]: args = [ str(testenv / "venv" / "bin" / "python"), "-u", @@ -119,8 +122,8 @@ def run_file_local( local_file: Path, local_file_cache_path: Path, min_msg_size: int, - ignore_message_types, -) -> Dict[str, int]: + ignore_message_types: set[str], +) -> dict[str, int]: prefs_file = sharedir / "prefs.js" firefox_path = bindir / "firefox" @@ -139,7 +142,7 @@ def run_file_local( ) -def add_nyx_env_vars(fd: TextIO): +def add_nyx_env_vars(fd: TextIOBase) -> None: """Add env vars prefixed MOZ_FUZZ_ to config.sh which is passed through to the QEMU target. """ @@ -156,9 +159,9 @@ def run_afl( afldir: Path, sharedir: Path, runtime: int, - custom_mutator: Optional[str], + custom_mutator: str | None, debug: bool, -): +) -> None: env = os.environ.copy() # env["AFL_NO_UI"] = "1" @@ -203,7 +206,7 @@ def run_afl( shutil.rmtree(afldir) -def main(args: Optional[List[str]] = None) -> int: +def main(args: list[str] | None = None) -> int: """Command line options.""" # setup argparser @@ -329,7 +332,7 @@ def main(args: Optional[List[str]] = None) -> int: with opts.single_ignore_messages.open() as fd: ignore_message_types |= {line.strip() for line in fd} - mochitest_dir: Optional[Path] = None + mochitest_dir: Path | None = None if opts.mochitest is not None: if opts.mochitest == "plain": mochitest_dir = testenv / "tests" / "mochitest" / "tests" diff --git a/services/nyx/nyx_utils.py b/services/nyx/nyx_utils.py index e52439b1..7e3559ca 100644 --- a/services/nyx/nyx_utils.py +++ b/services/nyx/nyx_utils.py @@ -10,12 +10,11 @@ from google.cloud import storage -def ncpu(): +def ncpu() -> None: print(psutil.cpu_count(logical=False)) - -def gcs_cat(): +def gcs_cat() -> None: parser = ArgumentParser(prog="gcs-cat") parser.add_argument("bucket") parser.add_argument("path") diff --git a/services/nyx/pyproject.toml b/services/nyx/pyproject.toml index e5866b41..556001e2 100644 --- a/services/nyx/pyproject.toml +++ b/services/nyx/pyproject.toml @@ -2,21 +2,21 @@ requires = ["setuptools", "wheel"] build-backend = "setuptools.build_meta" -[tool.black] -target-version = ["py38"] - -[[tool.mypy.overrides]] -module = [ - "setuptools", -] +[tool.mypy] ignore_missing_imports = true +strict = true +show_error_codes = true +warn_unused_ignores = false [tool.pylint.format] max-line-length = 88 [tool.ruff] -ignore = [] line-length = 88 +target-version = "py39" + +[tool.ruff.lint] +ignore = [] select = [ # flake8 "E", @@ -29,4 +29,3 @@ select = [ # includes yesqa "RUF", ] -target-version = "py38" diff --git a/services/nyx/tox.ini b/services/nyx/tox.ini index ae782bab..34335a8b 100644 --- a/services/nyx/tox.ini +++ b/services/nyx/tox.ini @@ -4,13 +4,12 @@ tox_pip_extensions_ext_venv_update = true [testenv:lint] deps = - black==v23.11.0 - mypy==v1.7.1 - ruff==v0.1.6 + mypy==v1.13.0 + ruff==v0.7.4 usedevelop = true allowlist_externals = bash commands = + ruff format --diff {toxinidir} ruff check --fix --exit-non-zero-on-fix {toxinidir} - black --diff --check {toxinidir} mypy --install-types --non-interactive {toxinidir}