Skip to content

Commit b3686fc

Browse files
committed
chore: use pre-commit with ruff
1 parent a95e12f commit b3686fc

File tree

12 files changed

+82
-32
lines changed

12 files changed

+82
-32
lines changed

.pre-commit-config.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
default_language_version:
2+
python: python3.10
3+
exclude: LICENSE
4+
repos:
5+
- repo: https://github.com/pre-commit/pre-commit-hooks
6+
rev: v4.4.0
7+
hooks:
8+
- id: check-merge-conflict
9+
- id: check-json
10+
- id: check-yaml
11+
- id: debug-statements
12+
- id: end-of-file-fixer
13+
exclude: ^docs/.*$
14+
- id: pretty-format-json
15+
args:
16+
- --autofix
17+
- id: trailing-whitespace
18+
- repo: https://github.com/psf/black
19+
rev: 23.7.0
20+
hooks:
21+
- id: black
22+
- repo: https://github.com/astral-sh/ruff-pre-commit
23+
rev: v0.0.282
24+
hooks:
25+
- id: ruff
26+
args: [--fix, --exit-non-zero-on-fix, --show-fixes]

.ruff.toml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
select = [
2+
"E", # pycodestyle
3+
"W", # pycodestyle
4+
"F", # pyflake
5+
"I", # isort
6+
"B", # flake8-bugbear
7+
"UP", # pyupgrade
8+
]
9+
10+
ignore = [
11+
"E501", # line-too-long
12+
"B904", # check for raise statements in exception handlers that lack a from clause
13+
]
14+
15+
exclude = [
16+
"**/docs",
17+
]
18+
19+
target-version = "py38"
20+
21+
[per-file-ignores]
22+
# Ignore unused imports (F401) in these files
23+
"__init__.py" = ["F401"]
24+
25+
[isort]
26+
known-first-party = ["graphql_server"]
27+
force-wrap-aliases = true
28+
combine-as-imports = true

CONTRIBUTING.md

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ Activate the virtualenv and install dependencies by running:
3131
python pip install -e ".[test]"
3232
```
3333

34-
If you are using Linux or MacOS, you can make use of Makefile command
35-
`make dev-setup`, which is a shortcut for the above python command.
34+
If you are using Linux or MacOS, you can make use of Makefile command `make dev-setup`, which is a shortcut for the above python command.
3635

3736
### Development on Conda
3837

@@ -60,8 +59,7 @@ After developing, the full test suite can be evaluated by running:
6059
pytest tests --cov=graphql-server -vv
6160
```
6261

63-
If you are using Linux or MacOS, you can make use of Makefile command
64-
`make tests`, which is a shortcut for the above python command.
62+
If you are using Linux or MacOS, you can make use of Makefile command `make tests`, which is a shortcut for the above python command.
6563

6664
You can also test on several python environments by using tox.
6765

@@ -73,8 +71,7 @@ Install tox:
7371
pip install tox
7472
```
7573

76-
Run `tox` on your virtualenv (do not forget to activate it!)
77-
and that's it!
74+
Run `tox` on your virtualenv (do not forget to activate it!) and that's it!
7875

7976
### Running tox on Conda
8077

@@ -89,5 +86,4 @@ This install tox underneath so no need to install it before.
8986

9087
Then uncomment the `requires = tox-conda` line on `tox.ini` file.
9188

92-
Run `tox` and you will see all the environments being created
93-
and all passing tests. :rocket:
89+
Run `tox` and you will see all the environments being created and all passing tests. :rocket:

codecov.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ coverage:
77
status:
88
project:
99
default:
10-
target: auto
10+
target: auto

graphql_server/aiohttp/graphqlview.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ class GraphQLView:
5656
encode = staticmethod(json_encode)
5757

5858
def __init__(self, **kwargs):
59-
super(GraphQLView, self).__init__()
59+
super().__init__()
6060
for key, value in kwargs.items():
6161
if hasattr(self, key):
6262
setattr(self, key, value)
@@ -194,9 +194,9 @@ async def __call__(self, request):
194194
if is_graphiql:
195195
graphiql_data = GraphiQLData(
196196
result=result,
197-
query=getattr(all_params[0], "query"),
198-
variables=getattr(all_params[0], "variables"),
199-
operation_name=getattr(all_params[0], "operation_name"),
197+
query=all_params[0].query,
198+
variables=all_params[0].variables,
199+
operation_name=all_params[0].operation_name,
200200
subscription_url=self.subscriptions,
201201
headers=self.headers,
202202
)

graphql_server/error.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def __init__(self, status_code, message=None, is_graphql_error=False, headers=No
1616
self.message = message
1717
self.is_graphql_error = is_graphql_error
1818
self.headers = headers
19-
super(HttpQueryError, self).__init__(message)
19+
super().__init__(message)
2020

2121
def __eq__(self, other):
2222
"""Check whether this HTTP query error is equal to another one."""

graphql_server/flask/graphqlview.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class GraphQLView(View):
5353
encode = staticmethod(json_encode)
5454

5555
def __init__(self, **kwargs):
56-
super(GraphQLView, self).__init__()
56+
super().__init__()
5757
for key, value in kwargs.items():
5858
if hasattr(self, key):
5959
setattr(self, key, value)
@@ -126,9 +126,9 @@ def dispatch_request(self):
126126
if show_graphiql:
127127
graphiql_data = GraphiQLData(
128128
result=result,
129-
query=getattr(all_params[0], "query"),
130-
variables=getattr(all_params[0], "variables"),
131-
operation_name=getattr(all_params[0], "operation_name"),
129+
query=all_params[0].query,
130+
variables=all_params[0].variables,
131+
operation_name=all_params[0].operation_name,
132132
subscription_url=self.subscriptions,
133133
headers=self.headers,
134134
)

graphql_server/quart/graphqlview.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class GraphQLView(View):
5757
encode = staticmethod(json_encode)
5858

5959
def __init__(self, **kwargs):
60-
super(GraphQLView, self).__init__()
60+
super().__init__()
6161
for key, value in kwargs.items():
6262
if hasattr(self, key):
6363
setattr(self, key, value)
@@ -142,9 +142,9 @@ async def dispatch_request(self):
142142
if show_graphiql:
143143
graphiql_data = GraphiQLData(
144144
result=result,
145-
query=getattr(all_params[0], "query"),
146-
variables=getattr(all_params[0], "variables"),
147-
operation_name=getattr(all_params[0], "operation_name"),
145+
query=all_params[0].query,
146+
variables=all_params[0].variables,
147+
operation_name=all_params[0].operation_name,
148148
subscription_url=self.subscriptions,
149149
headers=self.headers,
150150
)

graphql_server/sanic/graphqlview.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class GraphQLView(HTTPMethodView):
5858
encode = staticmethod(json_encode)
5959

6060
def __init__(self, **kwargs):
61-
super(GraphQLView, self).__init__()
61+
super().__init__()
6262
for key, value in kwargs.items():
6363
if hasattr(self, key):
6464
setattr(self, key, value)
@@ -147,9 +147,9 @@ async def __handle_request(self, request, *args, **kwargs):
147147
if show_graphiql:
148148
graphiql_data = GraphiQLData(
149149
result=result,
150-
query=getattr(all_params[0], "query"),
151-
variables=getattr(all_params[0], "variables"),
152-
operation_name=getattr(all_params[0], "operation_name"),
150+
query=all_params[0].query,
151+
variables=all_params[0].variables,
152+
operation_name=all_params[0].operation_name,
153153
subscription_url=self.subscriptions,
154154
headers=self.headers,
155155
)

graphql_server/webob/graphqlview.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class GraphQLView:
5252
encode = staticmethod(json_encode)
5353

5454
def __init__(self, **kwargs):
55-
super(GraphQLView, self).__init__()
55+
super().__init__()
5656
for key, value in kwargs.items():
5757
if hasattr(self, key):
5858
setattr(self, key, value)
@@ -128,9 +128,9 @@ def dispatch_request(self, request):
128128
if show_graphiql:
129129
graphiql_data = GraphiQLData(
130130
result=result,
131-
query=getattr(all_params[0], "query"),
132-
variables=getattr(all_params[0], "variables"),
133-
operation_name=getattr(all_params[0], "operation_name"),
131+
query=all_params[0].query,
132+
variables=all_params[0].variables,
133+
operation_name=all_params[0].operation_name,
134134
subscription_url=self.subscriptions,
135135
headers=self.headers,
136136
)

tests/test_helpers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ def test_encode_execution_results_with_format_error():
139139
def format_error(error):
140140
return {
141141
"msg": error.message,
142-
"loc": "{}:{}".format(error.locations[0].line, error.locations[0].column),
142+
"loc": f"{error.locations[0].line}:{error.locations[0].column}",
143143
"pth": "/".join(error.path),
144144
}
145145

tests/webob/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def url_string(url="/graphql", **url_params):
1111
return f"{url}?{urlencode(url_params)}" if url_params else url
1212

1313

14-
class Client(object):
14+
class Client:
1515
def __init__(self, **kwargs):
1616
self.schema = kwargs.pop("schema", None) or Schema
1717
self.settings = kwargs.pop("settings", None) or {}

0 commit comments

Comments
 (0)