Skip to content

Commit 03362db

Browse files
committed
enable ruff linters
1 parent 21c9c86 commit 03362db

File tree

6 files changed

+33
-18
lines changed

6 files changed

+33
-18
lines changed

nested_diff_restful/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# -*- coding: utf-8 -*-
2-
#
31
# Copyright 2024 Michael Samoglyadov
42
#
53
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -24,6 +22,7 @@
2422

2523
def start_wsgi_server():
2624
import gunicorn.app.base
25+
2726
import nested_diff_restful.api
2827

2928
class WSGIServer(gunicorn.app.base.Application):

nested_diff_restful/api.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# -*- coding: utf-8 -*-
2-
#
31
# Copyright 2021-2024 Michael Samoglyadov
42
#
53
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -17,18 +15,16 @@
1715
import os
1816

1917
from flask import Flask, Response, jsonify, render_template, request
20-
2118
from nested_diff import Differ, Patcher
22-
from nested_diff.formatters import HtmlFormatter, TextFormatter, TermFormatter
19+
from nested_diff.formatters import HtmlFormatter, TermFormatter, TextFormatter
2320
from nested_diff.handlers import TextHandler
2421

25-
2622
flask_kwargs = {}
2723

2824
for kw in ('static_folder', 'static_url_path', 'template_folder'):
2925
try:
3026
flask_kwargs[kw] = os.environ['NESTED_DIFF_REST_' + kw.upper()]
31-
except KeyError:
27+
except KeyError: # noqa: PERF203
3228
pass
3329

3430
app = Flask(__name__, **flask_kwargs)
@@ -76,7 +72,7 @@ def diff():
7672
try:
7773
old = request.json.get('a', None)
7874
new = request.json.get('b', None)
79-
except Exception:
75+
except Exception: # noqa: BLE001
8076
return Response('Bad request', status=400)
8177

8278
try:
@@ -87,7 +83,7 @@ def diff():
8783

8884
if text_diff_ctx >= 0:
8985
differ.set_handler(TextHandler(context=text_diff_ctx))
90-
except Exception:
86+
except Exception: # noqa: BLE001
9187
return Response('Incorrect diff options', status=400)
9288

9389
_, diff = differ.diff(old, new)
@@ -102,7 +98,7 @@ def diff():
10298

10399

104100
@app.route('/api/v1/format', methods=['POST'])
105-
def format():
101+
def format_diff():
106102
try:
107103
diff = request.json.get('diff', {})
108104
ofmt = request.json.get('ofmt', None)
@@ -112,7 +108,7 @@ def format():
112108
ofmt_opts = request.json.get('ofmt_opts', {})
113109

114110
return format_diff_response(ofmt, diff, ofmt_opts)
115-
except Exception:
111+
except Exception: # noqa: BLE001
116112
return Response('Incorrect arguments', status=400)
117113

118114

@@ -123,9 +119,9 @@ def patch():
123119
Patcher().patch(
124120
request.json['target'],
125121
request.json['patch'],
126-
)
122+
),
127123
)
128-
except Exception:
124+
except Exception: # noqa: BLE001
129125
return Response('Incorrect arguments', status=400)
130126

131127

@@ -155,5 +151,5 @@ def nested_diff_script():
155151
app.run(
156152
host=os.environ.get('NESTED_DIFF_REST_HOST', 'localhost'),
157153
port=os.environ.get('NESTED_DIFF_REST_PORT', 8080),
158-
debug=True if 'NESTED_DIFF_REST_DEBUG' in os.environ else False,
154+
debug='NESTED_DIFF_REST_DEBUG' in os.environ,
159155
)

pyproject.toml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ test = [
3030
'pytest',
3131
'pytest-cov',
3232
'pytest-ruff',
33+
'ruff==0.1.15', # pin version for reproducible results
3334
]
3435

3536
[project.urls]
@@ -49,6 +50,23 @@ addopts = """
4950

5051
[tool.ruff]
5152
line-length = 79
53+
select = ['ALL']
54+
ignore = [
55+
'ANN', # type annotations
56+
'D', # docstrings
57+
'SIM105', # contextlib.suppress is slower than try-except-pass
58+
]
59+
60+
[tool.ruff.extend-per-file-ignores]
61+
'tests/*' = [
62+
'E501', # long lines
63+
'PLR2004', # hardcoded value used in comparison
64+
'S101', # use of `assert`
65+
]
5266

5367
[tool.ruff.format]
5468
quote-style = 'single'
69+
70+
[tool.ruff.lint]
71+
flake8-quotes.inline-quotes = 'single'
72+
isort.lines-between-types = 1

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from nested_diff_restful.api import app
44

55

6-
@pytest.fixture
6+
@pytest.fixture()
77
def client():
88
with app.test_client() as client:
99
yield client

tests/test_api_patch.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ def test_invalid_request(client):
66

77
def test_patch(client):
88
rv = client.post(
9-
'/api/v1/patch', json={'target': 'a', 'patch': {'N': 'b'}}
9+
'/api/v1/patch',
10+
json={'target': 'a', 'patch': {'N': 'b'}},
1011
)
1112

1213
assert rv.status_code == 200

tests/test_cli.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import pytest
21
import unittest.mock
32

3+
import pytest
4+
45
import nested_diff_restful
56

67

0 commit comments

Comments
 (0)