Skip to content

Commit e3c86db

Browse files
authored
Merge pull request #346 from ewoks-kit/use_ruff
convert to ruff
2 parents e7fa8cd + 4536036 commit e3c86db

10 files changed

Lines changed: 63 additions & 19 deletions

File tree

.flake8

Lines changed: 0 additions & 4 deletions
This file was deleted.

.github/workflows/test.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,11 @@ jobs:
216216
# Run linter / checks
217217
checks:
218218
uses: ewoks-kit/.github/.github/workflows/python-check.yml@main
219+
with:
220+
enable-black: "false"
221+
enable-flake8: "false"
222+
enable-isort: "false"
223+
enable-ruff: "true"
219224

220225
# Build documentation
221226
docs:

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
!.gitignore
44
!.github
55
!.readthedocs.yaml
6-
!.flake8
76

87
# Byte / compiled / optimized
98
*.py[cod]

pyproject.toml

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,7 @@ test = [
7676
]
7777
dev = [
7878
"ewoksjob[test]",
79-
"black >=25",
80-
"flake8 >=4",
81-
"isort",
79+
"ruff>=0.16.0",
8280
]
8381
doc = [
8482
"ewoksjob[worker]",
@@ -111,6 +109,25 @@ cancel = "ewoksjob.cli_utils.cancel:cancel"
111109
[tool.pytest.ini_options]
112110
timeout = 120
113111

114-
[tool.isort]
115-
profile = "black"
116-
force_single_line = "True"
112+
[tool.ruff.lint]
113+
select = [
114+
"E", # pycodestyle errors
115+
"F", # pyflakes
116+
"I", # isort
117+
"S", # flake8-bandit
118+
]
119+
ignore = [
120+
"E501", # line too long
121+
]
122+
123+
[tool.ruff.lint.per-file-ignores]
124+
"src/ewoksjob/tests/*.py" = [
125+
"S101" # allow asserts
126+
]
127+
"scripts/*.py" = [
128+
"S101" # allow asserts
129+
]
130+
131+
[tool.ruff.lint.isort]
132+
force-single-line = true
133+
known-first-party = ["ewoksjob"]

src/ewoksjob/cli_utils/cancel.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010

1111

1212
@click.command("cancel")
13-
@add_click_options(cli_cancel_utils.cancel_arguments(shell=True))
13+
@add_click_options(cli_cancel_utils.cancel_arguments(shell=True)) # noqa: S604
1414
def cancel(cli_args: Namespace) -> Optional[Literal[0, 1]]:
1515
"""Abort an Ewoks job."""
16-
result = command_cancel(cli_args, shell=True)
16+
result = command_cancel(cli_args, shell=True) # noqa: S604
1717
if result:
1818
click.get_current_context().exit(result)
1919

src/ewoksjob/cli_utils/submit.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515

1616

1717
@click.command("submit")
18-
@add_click_options(cli_submit_utils.submit_arguments(shell=True))
18+
@add_click_options(cli_submit_utils.submit_arguments(shell=True)) # noqa: S604
1919
def submit(cli_args: Namespace) -> Union[List[dict], Literal[0, 1]]:
2020
"""Submit an Ewoks workflow."""
21-
result = command_submit(cli_args, shell=True)
21+
result = command_submit(cli_args, shell=True) # noqa: S604
2222
if result:
2323
click.get_current_context().exit(result)
2424

src/ewoksjob/client/local/futures.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ class RemoteExit(Exception):
2525

2626

2727
class LocalFuture(FutureInterface):
28-
2928
def __init__(self, uuid: str, future: Optional[NATIVE_FUTURE_TYPES] = None) -> None:
3029
if future is None:
3130
from .pool import get_active_pool

src/ewoksjob/events/readers/redis.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import json
22
import os
3+
import re
34
import socket
45
from typing import Iterator
56

@@ -22,7 +23,7 @@ def get_events(self, job_id=None, **filters) -> Iterator[EventType]:
2223
is_equal_filter, post_filter = self.split_filter(**filters)
2324

2425
if job_id:
25-
pattern = f"ewoks:{job_id}:*"
26+
pattern = f"ewoks:{_escape_glob(job_id)}:*"
2627
else:
2728
pattern = "ewoks:*"
2829
keys = sorted(
@@ -36,3 +37,11 @@ def get_events(self, job_id=None, **filters) -> Iterator[EventType]:
3637
):
3738
continue
3839
yield event
40+
41+
42+
# Escape glob-special characters so `job_id` is matched literally in a SCAN pattern.
43+
_GLOB_SPECIAL_RE = re.compile(r"([\\*?\[\]])")
44+
45+
46+
def _escape_glob(value: str) -> str:
47+
return _GLOB_SPECIAL_RE.sub(r"\\\1", value)

src/ewoksjob/tests/test_events.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import pytest
55
from ewokscore import events
66

7+
from ..events.readers.redis import _escape_glob
78
from .utils import has_redis
89

910

@@ -88,3 +89,16 @@ def assert_stop_event(reader):
8889
stop_event.set()
8990
thread.join(timeout=3)
9091
assert not thread.is_alive()
92+
93+
94+
@pytest.mark.parametrize(
95+
"job_id,expected",
96+
[
97+
("plainid", "plainid"),
98+
("has*star", "has\\*star"),
99+
("has?mark", "has\\?mark"),
100+
("has[bracket]", "has\\[bracket\\]"),
101+
],
102+
)
103+
def test_redis_escape_glob(job_id, expected):
104+
assert _escape_glob(job_id) == expected

src/ewoksjob/tests/utils.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import logging
2+
import shutil
23
import subprocess
34
import time
45
from types import ModuleType
@@ -15,9 +16,13 @@ def has_redis() -> bool:
1516

1617

1718
def _check_redis_server() -> bool:
19+
redis_server = shutil.which("redis-server")
20+
if redis_server is None:
21+
logger.debug("Unable to find 'redis-server' executable.'")
22+
return False
1823
try:
19-
result = subprocess.run(
20-
["redis-server", "--version"], capture_output=True, text=True, check=True
24+
result = subprocess.run( # noqa: S603 (resolved via shutil.which)
25+
[redis_server, "--version"], capture_output=True, text=True, check=True
2126
)
2227
return bool(result.stdout.strip())
2328
except Exception:

0 commit comments

Comments
 (0)