Skip to content

Commit 8c529ab

Browse files
authored
Tooling updates (#388)
* Upgrade ruff and use it for formatting as well * Lint * Move coverage config to .coveragerc * Add a Ruff GH action for inline annotations
1 parent 806dd04 commit 8c529ab

18 files changed

Lines changed: 110 additions & 108 deletions

.coveragerc

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
[run]
2+
branch = True
3+
concurrency = multiprocessing, thread
4+
parallel = True
5+
source_pkgs = grapple
6+
omit = **/migrations/*,docs/*,tests/*
7+
8+
[paths]
9+
source = grapple,.tox/py*/**/site-packages
10+
11+
[report]
12+
show_missing = True
13+
ignore_errors = True
14+
skip_covered = True
15+
skip_empty = true
16+
17+
# Regexes for lines to exclude from consideration
18+
exclude_also =
19+
# Have to re-enable the standard pragma
20+
pragma: no cover
21+
22+
# Don't complain about missing debug-only code:
23+
def __repr__
24+
if self.debug
25+
if settings.DEBUG
26+
27+
# Don't complain if tests don't hit defensive assertion code:
28+
raise AssertionError
29+
raise NotImplementedError
30+
31+
# Don't complain if non-runnable code isn't run:
32+
if 0:
33+
if __name__ == .__main__.:
34+
35+
# Nor complain about type checking
36+
"if TYPE_CHECKING:",
37+
class .*\bProtocol\):
38+
@(abc\.)?abstractmethod

.github/workflows/ruff.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: Ruff
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- 'stable/**'
8+
pull_request:
9+
branches: [main]
10+
11+
jobs:
12+
ruff:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- uses: actions/checkout@v4
17+
18+
- run: python -Im pip install --user ruff
19+
20+
- name: Run ruff
21+
run: ruff --output-format=github grapple

.pre-commit-config.yaml

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ ci:
44

55
repos:
66
- repo: https://github.com/pre-commit/pre-commit-hooks
7-
rev: v4.4.0
7+
rev: v4.6.0
88
hooks:
99
- id: check-yaml
1010
- id: check-toml
@@ -17,20 +17,12 @@ repos:
1717
- id: detect-private-key
1818
- id: end-of-file-fixer
1919
- id: check-added-large-files
20-
- repo: https://github.com/psf/black-pre-commit-mirror
21-
rev: 23.9.1
22-
hooks:
23-
- id: black
2420
- repo: https://github.com/astral-sh/ruff-pre-commit
25-
rev: 'v0.0.287'
21+
rev: 'v0.3.7'
2622
hooks:
2723
- id: ruff
2824
args: [--fix, --exit-non-zero-on-fix]
29-
- repo: https://github.com/adamchainz/blacken-docs
30-
rev: 1.16.0
31-
hooks:
32-
- id: blacken-docs
33-
additional_dependencies: [black==23.9.1]
25+
- id: ruff-format
3426
- repo: https://github.com/rtts/djhtml
3527
rev: 3.0.6
3628
hooks:

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
# Wagtail Grapple
88

99
[![Build status](https://github.com/torchbox/wagtail-grapple/actions/workflows/ci.yml/badge.svg)](https://github.com/torchbox/wagtail-grapple/actions)
10+
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
1011
[![PyPi](https://img.shields.io/pypi/v/wagtail-grapple.svg)](https://pypi.org/project/wagtail-grapple/)
11-
[![black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
1212
[![pre-commit.ci status](https://results.pre-commit.ci/badge/github/torchbox/wagtail-grapple/main.svg)](https://results.pre-commit.ci/latest/github/torchbox/wagtail-grapple/main)
1313

1414
A library to build GraphQL endpoints easily so you can grapple your Wagtail data from anywhere!

grapple/exceptions.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,3 @@ class IllegalDeprecation(Exception):
44
55
This is invalid - a deprecated entity must be nullable.
66
"""
7-
8-
pass

grapple/helpers.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ def register_field_middleware(field_name: str, middleware_list: list):
6464
def register_query_field(
6565
field_name,
6666
plural_field_name=None,
67+
*,
6768
query_params=None,
6869
required=False,
6970
plural_required=False,
@@ -184,6 +185,7 @@ def resolve_plural(self, _, info, **kwargs):
184185
def register_paginated_query_field(
185186
field_name,
186187
plural_field_name=None,
188+
*,
187189
query_params=None,
188190
required=False,
189191
plural_required=False,
@@ -300,7 +302,7 @@ def resolve_plural(self, _, info, **kwargs):
300302

301303

302304
def register_singular_query_field(
303-
field_name, query_params=None, required=False, middleware=None
305+
field_name, *, query_params=None, required=False, middleware=None
304306
):
305307
def inner(cls):
306308
field_type = lambda: registry.models[cls] # noqa: E731

grapple/models.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ class GraphQLField:
1717
deprecation_reason: Optional[str]
1818

1919
def __init__(
20-
self, field_name: str, field_type: type = None, required: bool = None, **kwargs
20+
self,
21+
field_name: str,
22+
field_type: type = None,
23+
*,
24+
required: bool = None,
25+
**kwargs,
2126
):
2227
# Initiate and get specific field info.
2328
self.field_name = field_name
@@ -81,17 +86,14 @@ def Mixin():
8186
(app_label, model) = snippet_model.lower().split(".")
8287
mdl = apps.get_model(app_label, model)
8388

84-
if mdl:
85-
field_type = lambda: registry.snippets[mdl] # noqa: E731
86-
else:
87-
field_type = graphene.String
89+
field_type = (lambda: registry.snippets[mdl]) if mdl else graphene.String
8890

8991
return GraphQLField(field_name, field_type, **kwargs)
9092

9193
return Mixin
9294

9395

94-
def GraphQLForeignKey(field_name, content_type, is_list=False, **kwargs):
96+
def GraphQLForeignKey(field_name, content_type, **kwargs):
9597
def Mixin():
9698
field_type = None
9799
if isinstance(content_type, str):

grapple/settings.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
Wagtail Grapple settings, checking for user settings first, then falling
1010
back to the defaults.
1111
"""
12+
1213
import logging
1314

1415
from django.conf import settings as django_settings

grapple/types/images.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ def resolve_src_set(
197197
info: GraphQLResolveInfo,
198198
sizes: list[int],
199199
format: str | None = None,
200+
*,
200201
preserve_svg: bool = True,
201202
**kwargs,
202203
) -> str:

grapple/types/streamfield.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,11 @@ def resolve_blocks(self, info, **kwargs):
172172

173173
for field, value in stream_data.items():
174174
block = dict(child_blocks)[field]
175-
if issubclass(type(block), blocks.ChooserBlock) or not issubclass(
176-
type(block), blocks.StructBlock
175+
if isinstance(value, int) and (
176+
issubclass(type(block), blocks.ChooserBlock)
177+
or not issubclass(type(block), blocks.StructBlock)
177178
):
178-
if isinstance(value, int):
179-
value = block.to_python(value)
179+
value = block.to_python(value)
180180

181181
stream_blocks.append(StructBlockItem(field, block, value))
182182

0 commit comments

Comments
 (0)