Skip to content

Commit

Permalink
refactor: add basic configuration for ruff + apply
Browse files Browse the repository at this point in the history
  • Loading branch information
KarelZe committed Jan 8, 2024
1 parent 8ca3587 commit 9ec6b93
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 17 deletions.
3 changes: 3 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
42 changes: 42 additions & 0 deletions ruff.toml
Original file line number Diff line number Diff line change
@@ -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
14 changes: 7 additions & 7 deletions utils/consts.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
XTRACT_HEADER = """
_____ _ _
| ___|__ _ __ ___ _ __ ___(_) ___ ___ (_)_ __ ___
| |_ / _ \| '__/ _ \ '_ \/ __| |/ __/ __| | | '_ ` _ \\
| _| (_) | | | __/ | | \__ \ | (__\__ \_| | | | | | |
|_| \___/|_| \___|_| |_|___/_|\___|___(_)_|_| |_| |_|
| |_ / _ \\| '__/ _ \\ '_ \\/ __| |/ __/ __| | | '_ ` _ \\
| _| (_) | | | __/ | | \\__ \\ | (__\\__ \\_| | | | | | |
|_| \\___/|_| \\___|_| |_|___/_|\\___|___(_)_|_| |_| |_|
__ ___ _ _____ _
\ \/ / |_ _ __ __ _ ___| |_ |_ _|__ ___ | |
\ /| __| '__/ _` |/ __| __| | |/ _ \ / _ \| |
/ \| |_| | | (_| | (__| |_ | | (_) | (_) | |
/_/\_\\\\__|_| \__,_|\___|\__| |_|\___/ \___/|_|
\\ \\/ / |_ _ __ __ _ ___| |_ |_ _|__ ___ | |
\\ /| __| '__/ _` |/ __| __| | |/ _ \\ / _ \\| |
/ \\| |_| | | (_| | (__| |_ | | (_) | (_) | |
/_/\\_\\\\__|_| \\__,_|\\___|\\__| |_|\\___/ \\___/|_|
"""
20 changes: 10 additions & 10 deletions utils/main.py
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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():
Expand Down

0 comments on commit 9ec6b93

Please sign in to comment.