Skip to content

Commit 11b7272

Browse files
authored
Merge pull request #474 from TheHive-Project/473-experiment-with-ruff-as-an-alternative-linterformatter
#473 - Introduce ruff to replace flake8 and black
2 parents 127aecb + f0373d5 commit 11b7272

15 files changed

+13
-34
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2024 StrangeBee
3+
Copyright (c) 2025 StrangeBee
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

examples/alert/observable_from_file.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
hive = TheHiveApi(url="http://localhost:9000", apikey="h1v3b33")
99

1010
with tempfile.TemporaryDirectory() as tmpdir:
11-
1211
observable_filepath = os.path.join(tmpdir, "my-observable.txt")
1312
with open(observable_filepath, "w") as observable_file:
1413
observable_file.write("some observable content")

examples/case/observable_file.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
)
1414

1515
with tempfile.TemporaryDirectory() as tmpdir:
16-
1716
observable_filepath = os.path.join(tmpdir, "my-observable.txt")
1817
with open(observable_filepath) as observable_file:
1918
observable_file.write("some observable content")

noxfile.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,24 @@
55
PROJECT_DIR = os.path.dirname(__file__)
66
THEHIVE4PY_DIR = os.path.join(PROJECT_DIR, "thehive4py/")
77
TESTS_DIR = os.path.join(PROJECT_DIR, "tests/")
8+
EXAMPLES_DIR = os.path.join(PROJECT_DIR, "examples/")
89

910
nox.options.default_venv_backend = "none"
1011
nox.options.tags = ["audit", "lint"]
1112

1213

1314
@nox.session(tags=["ci", "lint"])
1415
def style(session: nox.Session):
15-
"""Run style checks with flake8."""
16-
session.run("flake8", THEHIVE4PY_DIR, TESTS_DIR)
16+
"""Run style checks with ruff."""
17+
session.run("ruff", "check", THEHIVE4PY_DIR, TESTS_DIR, EXAMPLES_DIR, __file__)
1718

1819

1920
@nox.session(tags=["ci", "lint"])
2021
def format(session: nox.Session):
21-
"""Run format checks with black."""
22-
session.run("black", "--check", THEHIVE4PY_DIR, TESTS_DIR)
22+
"""Run format checks with ruff."""
23+
session.run(
24+
"ruff", "format", "--check", THEHIVE4PY_DIR, TESTS_DIR, EXAMPLES_DIR, __file__
25+
)
2326

2427

2528
@nox.session(tags=["ci", "lint"])

pyproject.toml

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ authors = [{ name = "Szabolcs Antal", email = "antalszabolcs01@gmail.com" }]
2828
audit = ["bandit", "pip-audit"]
2929
build = ["build", "twine"]
3030
docs = ["mkdocs", "mkdocs-material", "mkdocstrings-python", "mike"]
31-
lint = ["black", "flake8-pyproject", "mypy", "pre-commit"]
31+
lint = ["mypy", "ruff", "pre-commit"]
3232
test = ["pytest", "pytest-cov"]
3333
dev = ["thehive4py[audit, lint, test, build, docs]", "nox"]
3434

@@ -41,10 +41,7 @@ thehive4py = ["py.typed"]
4141
[tool.coverage.run]
4242
omit = ["tests/*", "thehive4py/types/*"]
4343

44-
[tool.flake8]
45-
max-line-length = 88
46-
per-file-ignores = [
47-
"thehive4py/__init__.py:F401",
48-
"thehive4py/endpoints/__init__.py:F401",
49-
"thehive4py/query/__init__.py:F401",
50-
]
44+
[tool.ruff.lint.per-file-ignores]
45+
"thehive4py/__init__.py" = ["F401"]
46+
"thehive4py/endpoints/__init__.py" = ["F401"]
47+
"thehive4py/query/__init__.py" = ["F401"]

scripts/linkify_release_notes.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ def parse_arguments():
9898

9999

100100
def main():
101-
102101
args = parse_arguments()
103102

104103
release_notes_path = "docs/release-notes.md"

tests/test_alert_endpoint.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ def test_bulk_delete(self, thehive: TheHiveApi, test_alerts: List[OutputAlert]):
152152
def test_get_similar_observables(
153153
self, thehive: TheHiveApi, test_alerts: List[OutputAlert]
154154
):
155-
156155
similar_observables = thehive.alert.get_similar_observables(
157156
alert_id=test_alerts[0]["_id"], alert_or_case_id=test_alerts[1]["_id"]
158157
)

tests/test_case_endpoint.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,6 @@ def test_apply_case_template(
179179
test_case: OutputCase,
180180
test_case_template: OutputCaseTemplate,
181181
):
182-
183182
assert (
184183
set(test_case_template.get("tags", [])).issubset(
185184
set(test_case.get("tags", []))
@@ -212,7 +211,6 @@ def test_change_owner_organisation(
212211
)
213212

214213
def test_manage_access(self, thehive: TheHiveApi, test_case: OutputCase):
215-
216214
assert test_case["access"]["_kind"] == "OrganisationAccessKind"
217215
thehive.case.manage_access(
218216
case_id=test_case["_id"],
@@ -226,7 +224,6 @@ def test_manage_access(self, thehive: TheHiveApi, test_case: OutputCase):
226224
def test_get_similar_observables(
227225
self, thehive: TheHiveApi, test_cases: List[OutputCase]
228226
):
229-
230227
similar_observables = thehive.case.get_similar_observables(
231228
case_id=test_cases[0]["_id"], alert_or_case_id=test_cases[1]["_id"]
232229
)
@@ -236,7 +233,6 @@ def test_get_similar_observables(
236233
def test_link_and_unlink_case_with_case(
237234
self, thehive: TheHiveApi, test_cases: List[OutputCase]
238235
):
239-
240236
case_link: InputCaseLink = {"type": "whatever", "caseId": test_cases[1]["_id"]}
241237

242238
thehive.case.link_case(
@@ -262,7 +258,6 @@ def test_link_and_unlink_case_with_case(
262258
def test_link_and_unlink_case_with_url(
263259
self, thehive: TheHiveApi, test_case: OutputCase
264260
):
265-
266261
external_url = "https://example.com"
267262
url_link: InputURLLink = {"type": "whatever", "url": external_url}
268263

@@ -283,7 +278,6 @@ def test_link_and_unlink_case_with_url(
283278
assert unlinked_case["extraData"]["links"]["externalLinks"] == []
284279

285280
def test_link_types(self, thehive: TheHiveApi):
286-
287281
assert thehive.case.get_link_types() == []
288282

289283
def test_add_and_download_attachment(

tests/test_observable_endpoint.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ def test_create_single_in_alert_and_get(
3838
def test_create_multiple_in_alert(
3939
self, thehive: TheHiveApi, test_alert: OutputAlert
4040
):
41-
4241
observable_count = 3
4342
created_observables = thehive.observable.create_in_alert(
4443
alert_id=test_alert["_id"],
@@ -105,7 +104,6 @@ def test_create_single_in_case_and_get(
105104
assert created_observable == fetched_observable
106105

107106
def test_create_multiple_in_case(self, thehive: TheHiveApi, test_case: OutputCase):
108-
109107
observable_count = 3
110108
created_observables = thehive.observable.create_in_case(
111109
case_id=test_case["_id"],
@@ -199,7 +197,6 @@ def test_share_and_unshare(
199197
test_observable: OutputObservable,
200198
test_config: TestConfig,
201199
):
202-
203200
thehive.observable.share(
204201
observable_id=test_observable["_id"], organisations=[test_config.main_org]
205202
)

tests/test_organisation_endpoint.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77

88
class TestOrganisationEndpoint:
9-
109
def test_add_and_download_attachment_to_main_org(
1110
self, thehive: TheHiveApi, tmp_path: Path
1211
):
@@ -57,7 +56,6 @@ def test_get_organisation(self, thehive_admin: TheHiveApi, test_config: TestConf
5756
def test_find_organisations(
5857
self, thehive_admin: TheHiveApi, test_config: TestConfig
5958
):
60-
6159
organisations = thehive_admin.organisation.find(
6260
filters=Eq("name", test_config.main_org)
6361
)

0 commit comments

Comments
 (0)