Skip to content

Commit

Permalink
Merge pull request #1074 from onekey-sec/renovate/ruff-0.x
Browse files Browse the repository at this point in the history
chore(deps): update dependency ruff to v0.9.1
  • Loading branch information
vlaci authored Jan 14, 2025
2 parents ceff220 + d282e4f commit bac061b
Show file tree
Hide file tree
Showing 20 changed files with 141 additions and 138 deletions.
40 changes: 20 additions & 20 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pyright = "^1.1.349"
pytest = "^8.0.0"
pytest-cov = ">=3,<7"
pyyaml = "^6.0.1"
ruff = "0.8.6"
ruff = "0.9.1"
taplo = "^0.9.3"

[tool.poetry.group.docs]
Expand Down Expand Up @@ -90,12 +90,14 @@ select = [
"T10", # flake8-debugger
"T20", # flake8-print
"TC", # flake8-type-checking
"TID251", # flake8-tidy-imports; banned-api
"TRY", # tryceratops
"UP", # pyupgrade
"W", # pycodestyle (warnings)
]

ignore = [
"A005", # stdlib-module-shadowing: E.g. `unblog.logging` collides with stdlib `logging`. It's okay for us
"B027", # empty-method-without-abstract-decorator: It is okay to have empty methods in abstract classes
"D1", # undocumented-*: We are not documenting every public symbol
"D203", # one-blank-line-before-class: D211 (no-blank-line-before-class) is used instead
Expand Down Expand Up @@ -143,6 +145,9 @@ fixture-parentheses = false
mark-parentheses = false
parametrize-names-type = "csv"

[tool.ruff.lint.flake8-tidy-imports.banned-api]
"attr".msg = "Use `attrs` (with an 's') instead"

[tool.pytest.ini_options]
addopts = "--cov=unblob --cov=tests --cov-branch --cov-fail-under=90"
norecursedirs = """
Expand Down
6 changes: 3 additions & 3 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,9 @@ def test_skip_extraction(

assert result.exit_code == 0
process_file_mock.assert_called_once()
assert (
process_file_mock.call_args.args[0].skip_extraction == skip_extraction
), fail_message
assert process_file_mock.call_args.args[0].skip_extraction == skip_extraction, (
fail_message
)


@pytest.mark.parametrize(
Expand Down
4 changes: 2 additions & 2 deletions tests/test_finder.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import attr
import attrs
import pytest
from pyperscan import Scan

Expand Down Expand Up @@ -233,4 +233,4 @@ def test_search_chunks(content, expected_chunks, task_result):

assert len(chunks) == len(expected_chunks)
for expected_chunk, chunk in zip(expected_chunks, chunks):
assert attr.evolve(chunk, id="") == attr.evolve(expected_chunk, id="")
assert attrs.evolve(chunk, id="") == attrs.evolve(expected_chunk, id="")
4 changes: 2 additions & 2 deletions tests/test_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from statistics import mean
from typing import Optional, TypeVar

import attr
import attrs
import pytest

from unblob import handlers
Expand Down Expand Up @@ -54,7 +54,7 @@ def assert_same_chunks(expected, actual, explanation=None):
"""Assert ignoring the chunk.id-s."""
assert len(expected) == len(actual), explanation
for e, a in zip(expected, actual):
assert attr.evolve(e, id="") == attr.evolve(a, id=""), explanation
assert attrs.evolve(e, id="") == attrs.evolve(a, id=""), explanation


@pytest.mark.parametrize(
Expand Down
6 changes: 3 additions & 3 deletions unblob/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def __init__(
help=f"""Skip processing files with given magic prefix.
The provided values are appended to unblob's own skip magic list unless
--clear-skip-magic is provided.
[default: {', '.join(DEFAULT_SKIP_MAGIC)}]
[default: {", ".join(DEFAULT_SKIP_MAGIC)}]
""",
multiple=True,
)
Expand Down Expand Up @@ -481,12 +481,12 @@ def print_report(reports: ProcessResult):
chunks_distribution.items(), key=lambda item: item[1], reverse=True
):
chunks_table.add_row(
handler.upper(), human_size(size), f"{(size/total_size) * 100:0.2f}%"
handler.upper(), human_size(size), f"{(size / total_size) * 100:0.2f}%"
)

console.print(chunks_table)
console.print(
f"Chunk identification ratio: [#00FFC8]{(valid_size/total_size) * 100:0.2f}%[/#00FFC8]"
f"Chunk identification ratio: [#00FFC8]{(valid_size / total_size) * 100:0.2f}%[/#00FFC8]"
)

if len(reports.errors):
Expand Down
4 changes: 2 additions & 2 deletions unblob/dependencies.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import shutil

import attr
import attrs

from .models import DirectoryHandlers, Handlers


@attr.define
@attrs.define
class Dependency:
command: str
is_installed: bool
Expand Down
4 changes: 2 additions & 2 deletions unblob/finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from functools import lru_cache
from typing import Optional

import attr
import attrs
from pyperscan import Flag, Pattern, Scan, StreamDatabase
from structlog import get_logger

Expand All @@ -19,7 +19,7 @@
logger = get_logger()


@attr.define
@attrs.define
class HyperscanMatchContext:
file: File
file_size: int
Expand Down
4 changes: 2 additions & 2 deletions unblob/handlers/archive/cpio.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from pathlib import Path
from typing import Optional

import attr
import attrs
from structlog import get_logger

from ...file_utils import (
Expand Down Expand Up @@ -110,7 +110,7 @@
"""


@attr.define
@attrs.define
class CPIOEntry:
start_offset: int
size: int
Expand Down
4 changes: 2 additions & 2 deletions unblob/handlers/archive/qnap/qnap_nas.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from pathlib import Path
from typing import Optional

import attr
import attrs
from pyperscan import Flag, Pattern, Scan, StreamDatabase
from structlog import get_logger

Expand Down Expand Up @@ -36,7 +36,7 @@
]


@attr.define
@attrs.define
class QTSSearchContext:
start_offset: int
file: File
Expand Down
2 changes: 1 addition & 1 deletion unblob/handlers/archive/tar.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def _padded_field(re_content_char, size, leftpad_re=" ", rightpad_re=r"[ \0x00]"
field_regexes = []

for padsize in range(size):
content_re = f"{re_content_char}{{{size-padsize}}}"
content_re = f"{re_content_char}{{{size - padsize}}}"

for leftpadsize in range(padsize + 1):
rightpadsize = padsize - leftpadsize
Expand Down
3 changes: 1 addition & 2 deletions unblob/handlers/compression/_gzip_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ def read(self):
break
if buf == b"":
raise EOFError(
"Compressed file ended before the "
"end-of-stream marker was reached"
"Compressed file ended before the end-of-stream marker was reached"
)

self._add_read_data(uncompress)
Expand Down
4 changes: 2 additions & 2 deletions unblob/handlers/compression/bzip2.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Optional

import attr
import attrs
from pyperscan import Flag, Pattern, Scan, StreamDatabase
from structlog import get_logger

Expand Down Expand Up @@ -63,7 +63,7 @@ def build_stream_end_scan_db(pattern_list):
parser = StructParser(C_DEFINITIONS)


@attr.define
@attrs.define
class Bzip2SearchContext:
start_offset: int
file: File
Expand Down
4 changes: 2 additions & 2 deletions unblob/handlers/compression/xz.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import io
from typing import Optional

import attr
import attrs
from pyperscan import Flag, Pattern, Scan, StreamDatabase
from structlog import get_logger

Expand Down Expand Up @@ -61,7 +61,7 @@ def build_stream_end_scan_db(pattern_list):
hyperscan_stream_end_magic_db = build_stream_end_scan_db(STREAM_END_MAGIC_PATTERNS)


@attr.define
@attrs.define
class XZSearchContext:
start_offset: int
file: File
Expand Down
4 changes: 2 additions & 2 deletions unblob/handlers/executable/elf.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from pathlib import Path
from typing import Optional

import attr
import attrs
import lief
from structlog import get_logger

Expand All @@ -29,7 +29,7 @@
KERNEL_INIT_DATA_SECTION = ".init.data"


@attr.define(repr=False)
@attrs.define(repr=False)
class ElfChunk(ValidChunk):
def extract(self, inpath: Path, outdir: Path):
# ELF file extraction is special in that in the general case no new files are extracted, thus
Expand Down
Loading

0 comments on commit bac061b

Please sign in to comment.