Skip to content

Commit

Permalink
build!: drop support for python 3.8
Browse files Browse the repository at this point in the history
  • Loading branch information
tysmith committed Oct 31, 2024
1 parent 5a45099 commit 7ebfc53
Show file tree
Hide file tree
Showing 25 changed files with 140 additions and 101 deletions.
6 changes: 1 addition & 5 deletions .taskcluster.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ tasks:
- tox; tox -e codecov
jobs:
include:
- name: tests python 3.8
version: "3.8"
env:
TOXENV: py38,lint
- name: tests python 3.9
version: "3.9"
env:
Expand Down Expand Up @@ -79,7 +75,7 @@ tasks:
env:
TOXENV: py312,lint
- name: PyPI upload
version: "3.8"
version: "3.9"
env:
TOXENV: pypi
script:
Expand Down
6 changes: 4 additions & 2 deletions grizzly/adapter/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@

from abc import ABCMeta, abstractmethod
from pathlib import Path
from typing import TYPE_CHECKING, Any, Generator, final
from typing import TYPE_CHECKING, Any, final

from ..common.utils import DEFAULT_TIME_LIMIT, HARNESS_FILE

if TYPE_CHECKING:
from collections.abc import Generator

from sapphire import ServerMap

from ..common.storage import TestCase
Expand Down Expand Up @@ -187,7 +189,7 @@ def pre_launch(self) -> None:
None
"""

# TODO: update input_path type (str -> Path)
# TODO: update input_path type (str -> list[str])
def setup(self, input_path: str | None, server_map: ServerMap) -> None:
"""Optional. Automatically called once at startup.
Expand Down
5 changes: 4 additions & 1 deletion grizzly/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,17 @@
from pathlib import Path
from platform import system
from types import MappingProxyType
from typing import Iterable
from typing import TYPE_CHECKING

from FTB.ProgramConfiguration import ProgramConfiguration

from .common.fuzzmanager import FM_CONFIG
from .common.plugins import scan_plugins, scan_target_assets
from .common.utils import DEFAULT_TIME_LIMIT, TIMEOUT_DELAY, package_version

if TYPE_CHECKING:
from collections.abc import Iterable


# ref: https://stackoverflow.com/questions/12268602/sort-argparse-help-alphabetically
class SortingHelpFormatter(HelpFormatter):
Expand Down
5 changes: 4 additions & 1 deletion grizzly/common/bugzilla.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from pathlib import Path
from shutil import rmtree
from tempfile import mkdtemp
from typing import Generator
from typing import TYPE_CHECKING
from zipfile import ZipFile

from bugsy import Bug, Bugsy
Expand All @@ -19,6 +19,9 @@

from .utils import grz_tmp

if TYPE_CHECKING:
from collections.abc import Generator

# attachments that can be ignored
IGNORE_EXTS = frozenset({"c", "cpp", "diff", "exe", "log", "patch", "php", "py", "txt"})
# TODO: support all target assets
Expand Down
7 changes: 5 additions & 2 deletions grizzly/common/fuzzmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from re import search
from shutil import copyfileobj, rmtree
from tempfile import NamedTemporaryFile, mkdtemp
from typing import Any, Dict, Generator, cast
from typing import TYPE_CHECKING, Any, cast
from zipfile import BadZipFile, ZipFile

from Collector.Collector import Collector
Expand All @@ -22,6 +22,9 @@
from .storage import TEST_INFO
from .utils import grz_tmp

if TYPE_CHECKING:
from collections.abc import Generator

FM_CONFIG = Path.home() / ".fuzzmanagerconf"
LOG = getLogger(__name__)

Expand Down Expand Up @@ -79,7 +82,7 @@ def __getattr__(self, name: str) -> Any:
need_raw = "1" if name in self.RAW_FIELDS else "0"
# TODO: handle 403 and 404?
self._data = cast(
Dict[str, Any],
dict[str, Any],
self._coll.get(self._url, params={"include_raw": need_raw}).json(),
)
if name not in self._data:
Expand Down
3 changes: 2 additions & 1 deletion grizzly/common/status.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
from os import getpid
from sqlite3 import Connection, OperationalError, connect
from time import perf_counter, time
from typing import TYPE_CHECKING, Any, Callable, Generator, cast
from typing import TYPE_CHECKING, Any, Callable, cast

from .utils import grz_tmp

if TYPE_CHECKING:
from collections.abc import Generator
from pathlib import Path

from .reporter import FuzzManagerReporter
Expand Down
25 changes: 15 additions & 10 deletions grizzly/common/status_reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from platform import system
from re import match
from time import gmtime, localtime, strftime
from typing import Callable, Generator, Iterable
from typing import TYPE_CHECKING, Callable

from psutil import cpu_count, cpu_percent, disk_usage, getloadavg, virtual_memory

Expand All @@ -32,6 +32,9 @@
ReductionStep,
)

if TYPE_CHECKING:
from collections.abc import Generator, Iterable

__all__ = ("StatusReporter",)
__author__ = "Tyson Smith"
__credits__ = ["Tyson Smith"]
Expand Down Expand Up @@ -77,15 +80,17 @@ def from_file(
token = b"Traceback (most recent call last):"
assert len(token) < cls.READ_LIMIT
try:
with log_file.open("rb") as lfp:
with mmap(lfp.fileno(), 0, access=ACCESS_READ) as lmm:
idx = lmm.find(token)
if idx == -1:
# no traceback here, move along
return None
# seek back 2KB to collect preceding lines
lmm.seek(max(idx - len(token) - 2048, 0))
data = lmm.read(cls.READ_LIMIT)
with (
log_file.open("rb") as lfp,
mmap(lfp.fileno(), 0, access=ACCESS_READ) as lmm,
):
idx = lmm.find(token)
if idx == -1:
# no traceback here, move along
return None
# seek back 2KB to collect preceding lines
lmm.seek(max(idx - len(token) - 2048, 0))
data = lmm.read(cls.READ_LIMIT)
except (OSError, ValueError): # pragma: no cover
# OSError: in case the file goes away
# ValueError: cannot mmap an empty file on Windows
Expand Down
7 changes: 5 additions & 2 deletions grizzly/common/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@
from shutil import copyfile, copytree, move, rmtree
from tempfile import NamedTemporaryFile, mkdtemp
from time import time
from typing import Any, Generator, Iterator, cast
from typing import TYPE_CHECKING, Any, cast

from .utils import grz_tmp, package_version

if TYPE_CHECKING:
from collections.abc import Generator, Iterator

__all__ = ("TestCase", "TestCaseLoadFailure", "TestFileExists")
__author__ = "Tyson Smith"
__credits__ = ["Tyson Smith"]
Expand All @@ -35,7 +38,7 @@ class TestFileExists(Exception):
TestFile with the same name"""


@dataclass(eq=False)
@dataclass(eq=False, frozen=True)
class TestFileMap:
optional: dict[str, Path] = field(default_factory=dict)
required: dict[str, Path] = field(default_factory=dict)
Expand Down
5 changes: 2 additions & 3 deletions grizzly/common/test_fuzzmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,8 @@ def test_crash_06(mocker):
"rawStderr": "",
"rawCrashData": "",
}
with raises(RuntimeError) as exc:
with CrashEntry(123) as crash:
crash.create_signature(None)
with raises(RuntimeError) as exc, CrashEntry(123) as crash:
crash.create_signature(None)
assert "insufficient data to generate" in str(exc).lower()
assert coll.return_value.get.call_count == 1

Expand Down
9 changes: 4 additions & 5 deletions grizzly/common/test_status_reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,10 @@ def test_reduce_status_reporter_04(mocker, tmp_path):
status.run_params["splines"] = "reticulated"
status.last_reports.append(45678)
status.record("init")
with status.measure("total"):
with status.measure("strategy_0"):
status.iterations = 1
status.attempts = 1
status.successes = 1
with status.measure("total"), status.measure("strategy_0"):
status.iterations = 1
status.attempts = 1
status.successes = 1
status.report(force=True)
rptr = ReductionStatusReporter.load(db_file)
assert rptr.reports
Expand Down
5 changes: 4 additions & 1 deletion grizzly/common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
from os import getenv
from pathlib import Path
from tempfile import gettempdir
from typing import Any, Generator, Iterable
from typing import TYPE_CHECKING, Any

if TYPE_CHECKING:
from collections.abc import Generator, Iterable

__all__ = (
"ConfigError",
Expand Down
6 changes: 4 additions & 2 deletions grizzly/reduce/strategies/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@
from pathlib import Path
from shutil import rmtree
from tempfile import mkdtemp
from typing import TYPE_CHECKING, Iterable, Iterator, Type, cast
from typing import TYPE_CHECKING, cast

from ...common.utils import grz_tmp

if TYPE_CHECKING:
from collections.abc import Iterable, Iterator

from ...common.storage import TestCase

try:
Expand Down Expand Up @@ -202,7 +204,7 @@ def _load_strategies() -> dict[str, type[Strategy]]:
strategies: dict[str, type[Strategy]] = {}
for entry_point in iter_entry_points("grizzly_reduce_strategies"):
try:
strategy_cls = cast(Type[Strategy], entry_point.load())
strategy_cls = cast(type[Strategy], entry_point.load())
assert (
strategy_cls.name == entry_point.name
), f"entry_point name mismatch, check setup.py and {strategy_cls.__name__}"
Expand Down
4 changes: 3 additions & 1 deletion grizzly/reduce/strategies/beautify.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
import re
from abc import ABC, abstractmethod
from logging import getLogger
from typing import TYPE_CHECKING, Generator, Match, cast
from re import Match
from typing import TYPE_CHECKING, cast

from lithium.testcases import TestcaseLine

Expand All @@ -34,6 +35,7 @@
from . import Strategy, _contains_dd

if TYPE_CHECKING:
from collections.abc import Generator
from pathlib import Path

LOG = getLogger(__name__)
Expand Down
3 changes: 2 additions & 1 deletion grizzly/reduce/strategies/lithium.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from abc import ABC
from logging import getLogger
from typing import TYPE_CHECKING, Iterator
from typing import TYPE_CHECKING

from lithium.strategies import CheckOnly, Minimize, ReductionIterator
from lithium.strategies import CollapseEmptyBraces as LithCollapseEmptyBraces
Expand All @@ -18,6 +18,7 @@
from . import Strategy, _contains_dd

if TYPE_CHECKING:
from collections.abc import Iterator
from pathlib import Path

LOG = getLogger(__name__)
Expand Down
5 changes: 4 additions & 1 deletion grizzly/reduce/strategies/testcases.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@

from logging import getLogger
from shutil import rmtree
from typing import Generator
from typing import TYPE_CHECKING

from ...common.storage import TestCase
from . import Strategy

if TYPE_CHECKING:
from collections.abc import Generator

LOG = getLogger(__name__)


Expand Down
5 changes: 2 additions & 3 deletions grizzly/reduce/test_reduce.py
Original file line number Diff line number Diff line change
Expand Up @@ -734,9 +734,8 @@ def fake_iter():
["fake"],
log_path,
use_analysis=False,
) as mgr:
with raises(KeyboardInterrupt):
mgr.run()
) as mgr, raises(KeyboardInterrupt):
mgr.run()

n_reports = 1
reports = {"20"}
Expand Down
Loading

0 comments on commit 7ebfc53

Please sign in to comment.