From 9ec6b930411c859b7991b72c551b27a0c1dbc87a Mon Sep 17 00:00:00 2001 From: Markus Bilz Date: Mon, 8 Jan 2024 10:09:25 +0100 Subject: [PATCH] refactor: add basic configuration for ruff + apply --- .pre-commit-config.yaml | 3 +++ ruff.toml | 42 +++++++++++++++++++++++++++++++++++++++++ utils/consts.py | 14 +++++++------- utils/main.py | 20 ++++++++++---------- 4 files changed, 62 insertions(+), 17 deletions(-) create mode 100644 ruff.toml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7557b1f..88fb5be 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -17,5 +17,8 @@ repos: - repo: https://github.com/astral-sh/ruff-pre-commit rev: v0.1.11 hooks: + - id: ruff + args: + - --fix - id: ruff-format exclude: "^(export|populationdata|testdata)" diff --git a/ruff.toml b/ruff.toml new file mode 100644 index 0000000..425d4ac --- /dev/null +++ b/ruff.toml @@ -0,0 +1,42 @@ +# Same as Black. +line-length = 88 +indent-width = 4 + +# Assume Python 3.9 +target-version = "py39" + +# See rules: https://beta.rs/docs/rules/ +select = [ + "C", # flake8-comprehensions + "F", # pyflakes + "FURB", # refurb + "I", # isort + "N", # pep8-naming + "PIE", # misc lints + "PTH", # flake8-use-pathlib + "PGH", # pygrep + "RET", # return + "RUF", # ruff-specific rules + "UP", # pyupgrade + "SIM", # flake8-simplify + "W", # pycodestyle warnings +] + +# disable for now to keep current PR small +exclude = ["utils/ccl_chrome_indexeddb/*.py", "utils/dump_*.py", "utils/populate_*.py","utils/const.py", "utils/shared.py", "utils/scout_leveldb.py", "Forensicsim_Parser.py"] + + +ignore = [ + "E501", # line too long, handled by black + "N803", # argument name should be lowercase + "N806", # variable name should be lowercase + "C901", # too complex + "D206", # indent with white space + "W191", # tab identation +] + +[lint] +preview = true + +[format] +preview = true diff --git a/utils/consts.py b/utils/consts.py index 8bce69f..3182400 100644 --- a/utils/consts.py +++ b/utils/consts.py @@ -1,13 +1,13 @@ XTRACT_HEADER = """ _____ _ _ | ___|__ _ __ ___ _ __ ___(_) ___ ___ (_)_ __ ___ -| |_ / _ \| '__/ _ \ '_ \/ __| |/ __/ __| | | '_ ` _ \\ -| _| (_) | | | __/ | | \__ \ | (__\__ \_| | | | | | | -|_| \___/|_| \___|_| |_|___/_|\___|___(_)_|_| |_| |_| +| |_ / _ \\| '__/ _ \\ '_ \\/ __| |/ __/ __| | | '_ ` _ \\ +| _| (_) | | | __/ | | \\__ \\ | (__\\__ \\_| | | | | | | +|_| \\___/|_| \\___|_| |_|___/_|\\___|___(_)_|_| |_| |_| __ ___ _ _____ _ -\ \/ / |_ _ __ __ _ ___| |_ |_ _|__ ___ | | - \ /| __| '__/ _` |/ __| __| | |/ _ \ / _ \| | - / \| |_| | | (_| | (__| |_ | | (_) | (_) | | -/_/\_\\\\__|_| \__,_|\___|\__| |_|\___/ \___/|_| +\\ \\/ / |_ _ __ __ _ ___| |_ |_ _|__ ___ | | + \\ /| __| '__/ _` |/ __| __| | |/ _ \\ / _ \\| | + / \\| |_| | | (_| | (__| |_ | | (_) | (_) | | +/_/\\_\\\\__|_| \\__,_|\\___|\\__| |_|\\___/ \\___/|_| """ diff --git a/utils/main.py b/utils/main.py index 37387e2..440b173 100644 --- a/utils/main.py +++ b/utils/main.py @@ -1,15 +1,15 @@ -from datetime import datetime import json -from pathlib import Path import sys +from dataclasses import dataclass, field +from datetime import datetime +from pathlib import Path from typing import Any, Optional -from bs4 import BeautifulSoup import click -from dataclasses import dataclass, field -from dataclasses_json import config, LetterCase, dataclass_json, Undefined -from shared import parse_db, write_results_to_json +from bs4 import BeautifulSoup from consts import XTRACT_HEADER +from dataclasses_json import LetterCase, Undefined, config, dataclass_json +from shared import parse_db, write_results_to_json @dataclass_json(letter_case=LetterCase.CAMEL, undefined=Undefined.EXCLUDE) @@ -31,7 +31,7 @@ def __eq__(self, other): return self.cached_deduplication_key == other.cachedDeduplicationKey def __hash__(self): - return hash((self.cached_deduplication_key)) + return hash(self.cached_deduplication_key) def __lt__(self, other): return self.cached_deduplication_key < other.cached_deduplication_key @@ -75,7 +75,7 @@ def __eq__(self, other): ) def __hash__(self): - return hash((self.cached_deduplication_key)) + return hash(self.cached_deduplication_key) def __lt__(self, other): return self.cached_deduplication_key < other.cached_deduplication_key @@ -100,7 +100,7 @@ def __eq__(self, other): return self.mri == other.mri def __hash__(self): - return hash((self.mri)) + return hash(self.mri) def __lt__(self, other): return self.mri < other.mri @@ -186,7 +186,7 @@ def _parse_reply_chains(reply_chains: list[dict]) -> set[Message]: for rc in reply_chains: # Reassign new keys to old identifiers kwargs = rc.get("value", {}) - keys = [LUT_KEYS_MSTEAMS_2_0.get(k, k) for k in kwargs.keys()] + keys = [LUT_KEYS_MSTEAMS_2_0.get(k, k) for k in kwargs] kwargs.update(zip(keys, kwargs.values())) for message_values in kwargs.get("messages", {}).values():