Skip to content

Commit dea3d9a

Browse files
akxpetyaslavova
authored andcommitted
Replace flake8+isort+black with ruff (redis#3147)
* Replace flake8 + isort + flynt with ruff * Replace black with `ruff format`; run it
1 parent 5eb9939 commit dea3d9a

36 files changed

+123
-120
lines changed

.flake8

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

.isort.cfg

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

benchmarks/basic_operations.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def wrapper(*args, **kwargs):
5454
count = args[1]
5555
print(f"{func.__name__} - {count} Requests")
5656
print(f"Duration = {duration}")
57-
print(f"Rate = {count/duration}")
57+
print(f"Rate = {count / duration}")
5858
print()
5959
return ret
6060

benchmarks/command_packer_benchmark.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ def pack_command(self, *args):
7878

7979

8080
class CommandPackerBenchmark(Benchmark):
81-
8281
ARGUMENTS = (
8382
{
8483
"name": "connection_class",

benchmarks/socket_read_size.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55

66
class SocketReadBenchmark(Benchmark):
7-
87
ARGUMENTS = (
98
{"name": "parser", "values": [PythonParser, _HiredisParser]},
109
{

dev_requirements.txt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
build
2-
black==24.3.0
32
click==8.0.4
4-
flake8-isort
5-
flake8
6-
flynt~=0.69.0
73
invoke==2.2.0
84
mock
95
packaging>=20.4
@@ -12,6 +8,7 @@ pytest-asyncio>=0.23.0,<0.24.0
128
pytest-cov
139
pytest-profiling==1.8.1
1410
pytest-timeout
11+
ruff==0.9.6
1512
ujson>=4.2.0
1613
uvloop
1714
vulture>=2.3.0

doctests/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ pip uninstall -y redis # uninstall Redis package installed via redis-entraid
2121
pip install -r doctests/requirements.txt
2222
```
2323

24-
Note - the CI process, runs the basic ```black``` and ```isort``` linters against the examples. Assuming
25-
the requirements above have been installed you can run ```black yourfile.py``` and ```isort yourfile.py```
24+
Note - the CI process, runs linters against the examples. Assuming
25+
the requirements above have been installed you can run ```ruff check yourfile.py``` and ```ruff format yourfile.py```
2626
locally to validate the linting, prior to CI.
2727

2828
Just include necessary assertions in the example file and run

pyproject.toml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,3 +96,53 @@ filterwarnings = [
9696
# Ignore a coverage warning when COVERAGE_CORE=sysmon for Pythons < 3.12.
9797
"ignore:sys.monitoring isn't available:coverage.exceptions.CoverageWarning",
9898
]
99+
100+
[tool.ruff]
101+
target-version = "py38"
102+
line-length = 88
103+
exclude = [
104+
"*.egg-info",
105+
"*.pyc",
106+
".git",
107+
".venv*",
108+
"build",
109+
"dist",
110+
"docker",
111+
"docs/*",
112+
"doctests/*",
113+
"tasks.py",
114+
"venv*",
115+
"whitelist.py",
116+
]
117+
118+
[tool.ruff.lint]
119+
ignore = [
120+
"E501", # line too long (taken care of with ruff format)
121+
"E741", # ambiguous variable name
122+
"N818", # Errors should have Error suffix
123+
]
124+
125+
select = [
126+
"E",
127+
"F",
128+
"FLY",
129+
"I",
130+
"N",
131+
"W",
132+
]
133+
134+
[tool.ruff.lint.per-file-ignores]
135+
"redis/commands/bf/*" = [
136+
# the `bf` module uses star imports, so this is required there.
137+
"F405", # name may be undefined, or defined from star imports
138+
]
139+
"redis/commands/{bf,timeseries,json,search}/*" = [
140+
"N",
141+
]
142+
"tests/*" = [
143+
"I", # TODO: could be enabled, plenty of changes
144+
"N801", # class name should use CapWords convention
145+
"N803", # argument name should be lowercase
146+
"N802", # function name should be lowercase
147+
"N806", # variable name should be lowercase
148+
]

redis/_parsers/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@
3232
from .encoders import Encoder
3333
from .socket import SERVER_CLOSED_CONNECTION_ERROR, SocketBuffer
3434

35-
MODULE_LOAD_ERROR = "Error loading the extension. " "Please check the server logs."
35+
MODULE_LOAD_ERROR = "Error loading the extension. Please check the server logs."
3636
NO_SUCH_MODULE_ERROR = "Error unloading module: no such module with that name"
37-
MODULE_UNLOAD_NOT_POSSIBLE_ERROR = "Error unloading module: operation not " "possible."
37+
MODULE_UNLOAD_NOT_POSSIBLE_ERROR = "Error unloading module: operation not possible."
3838
MODULE_EXPORTS_DATA_TYPES_ERROR = (
3939
"Error unloading module: the module "
4040
"exports one or more module-side data "

redis/asyncio/cluster.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,9 +1167,7 @@ def get_node(
11671167
return self.nodes_cache.get(node_name)
11681168
else:
11691169
raise DataError(
1170-
"get_node requires one of the following: "
1171-
"1. node name "
1172-
"2. host and port"
1170+
"get_node requires one of the following: 1. node name 2. host and port"
11731171
)
11741172

11751173
def set_nodes(
@@ -1351,7 +1349,7 @@ async def initialize(self) -> None:
13511349
if len(disagreements) > 5:
13521350
raise RedisClusterException(
13531351
f"startup_nodes could not agree on a valid "
1354-
f'slots cache: {", ".join(disagreements)}'
1352+
f"slots cache: {', '.join(disagreements)}"
13551353
)
13561354

13571355
# Validate if all slots are covered or if we should try next startup node

0 commit comments

Comments
 (0)