Skip to content

Commit 4fa74a0

Browse files
committed
chore: Update pre-commit
1 parent 2aa31c4 commit 4fa74a0

File tree

12 files changed

+107
-74
lines changed

12 files changed

+107
-74
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525

2626
- uses: actions/setup-python@v3
2727
with:
28-
python-version: 3.7
28+
python-version: 3.9
2929

3030
- run: pip install pre-commit
3131
- run: SKIP=mypy pre-commit run --all-files
@@ -40,7 +40,7 @@ jobs:
4040

4141
- uses: actions/setup-python@v3
4242
with:
43-
python-version: 3.7
43+
python-version: 3.9
4444

4545
- run: pip install pre-commit
4646
- run: pre-commit run mypy --all-files

.pre-commit-config.yaml

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
default_language_version:
2-
python: python3.7
2+
python: python3.9
33

44
repos:
55
- repo: https://github.com/pre-commit/pre-commit-hooks
6-
rev: v4.4.0
6+
rev: v4.5.0
77
hooks:
88
- id: check-yaml
99
- id: end-of-file-fixer
1010
- id: trailing-whitespace
11-
exclude: ^.*\.(md|rst)$
11+
exclude: ^.*\.md$
1212
- id: debug-statements
1313
- id: mixed-line-ending
1414
args: [--fix=lf]
@@ -20,41 +20,23 @@ repos:
2020
- id: gitlint
2121

2222
- repo: https://github.com/adrienverge/yamllint
23-
rev: v1.30.0
23+
rev: v1.33.0
2424
hooks:
2525
- id: yamllint
2626

27-
- repo: https://github.com/ambv/black
28-
rev: 23.3.0
27+
- repo: https://github.com/pre-commit/mirrors-mypy
28+
rev: v1.7.1
2929
hooks:
30-
- id: black
31-
types: [python]
30+
- id: mypy
31+
exclude: ^(docs/|test/).*$
32+
args: ["--ignore-missing-imports"]
3233

33-
- repo: https://github.com/asottile/blacken-docs
34-
rev: 1.13.0
34+
- repo: https://github.com/astral-sh/ruff-pre-commit
35+
rev: v0.1.6
3536
hooks:
36-
- id: blacken-docs
37-
additional_dependencies: [ black==23.3.0 ]
37+
- id: ruff-format
3838

39-
- repo: https://github.com/charliermarsh/ruff-pre-commit
40-
rev: "v0.0.261"
39+
- repo: https://github.com/astral-sh/ruff-pre-commit
40+
rev: v0.1.6
4141
hooks:
4242
- id: ruff
43-
44-
- repo: https://github.com/asottile/seed-isort-config
45-
rev: v2.2.0
46-
hooks:
47-
- id: seed-isort-config
48-
49-
- repo: https://github.com/pre-commit/mirrors-isort
50-
rev: v5.10.1
51-
hooks:
52-
- id: isort
53-
additional_dependencies: ["isort[pyproject]"]
54-
55-
- repo: https://github.com/pre-commit/mirrors-mypy
56-
rev: v1.2.0
57-
hooks:
58-
- id: mypy
59-
exclude: ^(docs/|test/).*$
60-
args: ["--ignore-missing-imports"]

CODE_OF_CONDUCT.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ further defined and clarified by project maintainers.
5555
## Enforcement
5656

5757
Instances of abusive, harassing, or otherwise unacceptable behavior may be
58-
reported by contacting the project team at dadygalo@gmail.com. All
58+
reported by contacting the project team at dmitry@dygalo.dev. All
5959
complaints will be reviewed and investigated and will result in a response that
6060
is deemed necessary and appropriate to the circumstances. The project team is
6161
obligated to maintain confidentiality with regard to the reporter of an incident.

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ the problem.
2727

2828
3. Target the `master` branch.
2929

30-
4. Follow **PEP-8** for naming and [black](https://github.com/psf/black) for formatting.
30+
4. Follow [PEP-8](https://pep8.org) for naming and [ruff](https://github.com/astral-sh/ruff) for code formatting.
3131

3232
5. Tests are run using `tox`:
3333

pyproject.toml

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ classifiers = [
2424
"Programming Language :: Python :: Implementation :: CPython",
2525
"Topic :: Software Development :: Testing",
2626
]
27-
authors = [{ name = "Dmitry Dygalo", email = "dadygalo@gmail.com" }]
28-
maintainers = [{ name = "Dmitry Dygalo", email = "dadygalo@gmail.com" }]
27+
authors = [{ name = "Dmitry Dygalo", email = "dmitry@dygalo.dev" }]
28+
maintainers = [{ name = "Dmitry Dygalo", email = "dmitry@dygalo.dev" }]
2929
readme = "README.md"
3030
license = "MIT"
3131
include = ["src/hypothesis_graphql/py.typed"]
@@ -53,18 +53,6 @@ Changelog = "https://github.com/Stranger6667/hypothesis-graphql/blob/master/CHAN
5353
Funding = "https://github.com/sponsors/Stranger6667"
5454
"Source Code" = "https://github.com/Stranger6667/hypothesis-graphql"
5555

56-
[tool.black]
57-
line-length = 120
58-
target_version = ["py37"]
59-
60-
[tool.isort]
61-
line_length = 120
62-
multi_line_output = 3
63-
default_section = "THIRDPARTY"
64-
include_trailing_comma = true
65-
known_first_party = "hypothesis_graphql"
66-
known_third_party =["graphql", "hypothesis", "hypothesis_graphql", "pytest"]
67-
6856
[tool.coverage.run]
6957
parallel = true
7058
branch = true
@@ -84,6 +72,7 @@ exclude_lines = [
8472
]
8573

8674
[tool.ruff]
75+
line-length = 120
8776
select = [
8877
"E", # pycodestyle errors
8978
"W", # pycodestyle warnings
@@ -93,7 +82,7 @@ select = [
9382
"D", # pydocstyle
9483
]
9584
ignore = [
96-
"E501", # Line too long, handled by black
85+
"E501", # Line too long
9786
"B008", # Do not perform function calls in argument defaults
9887
"C901", # Too complex
9988
"D100", # Missing docstring in public module
@@ -113,3 +102,10 @@ target-version = "py37"
113102
[tool.ruff.per-file-ignores]
114103
"__init__.py" = ["F401"]
115104
"strategies.py" = ["F401"]
105+
106+
[tool.ruff.format]
107+
skip-magic-trailing-comma = false
108+
109+
[tool.ruff.isort]
110+
known-first-party = ["hypothesis_graphql"]
111+
known-third-party = ["graphql", "hypothesis", "pytest"]

src/hypothesis_graphql/_strategies/aliases.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ def maybe_add_alias_to_node(node: graphql.SelectionNode, seen: Dict[Tuple[str, s
2020

2121

2222
def maybe_add_alias(
23-
field_node: graphql.FieldNode, arguments: List[graphql.ArgumentNode], seen: Dict[Tuple[str, str], List]
23+
field_node: graphql.FieldNode,
24+
arguments: List[graphql.ArgumentNode],
25+
seen: Dict[Tuple[str, str], List],
2426
) -> None:
2527
for argument in arguments:
2628
key = (field_node.name.value, argument.name.value)

src/hypothesis_graphql/_strategies/primitives.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ def maybe_null(strategy: st.SearchStrategy[T], nullable: bool) -> st.SearchStrat
8686

8787

8888
def custom(
89-
strategy: st.SearchStrategy, nullable: bool = True, default: Optional[graphql.ValueNode] = None
89+
strategy: st.SearchStrategy,
90+
nullable: bool = True,
91+
default: Optional[graphql.ValueNode] = None,
9092
) -> st.SearchStrategy:
9193
return maybe_default(maybe_null(strategy, nullable), default=default)
9294

@@ -101,7 +103,9 @@ def maybe_default(
101103

102104
@lru_cache(maxsize=64)
103105
def enum(
104-
values: Tuple[str], nullable: bool = True, default: Optional[graphql.ValueNode] = None
106+
values: Tuple[str],
107+
nullable: bool = True,
108+
default: Optional[graphql.ValueNode] = None,
105109
) -> st.SearchStrategy[graphql.EnumValueNode]:
106110
return maybe_default(maybe_null(st.sampled_from(values).map(nodes.Enum), nullable), default=default)
107111

src/hypothesis_graphql/_strategies/strategy.py

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,14 @@
1212
from hypothesis.strategies._internal.utils import cacheable
1313

1414
from .. import nodes
15-
from ..types import AstPrinter, CustomScalarStrategies, Field, InputTypeNode, InterfaceOrObject, SelectionNodes
15+
from ..types import (
16+
AstPrinter,
17+
CustomScalarStrategies,
18+
Field,
19+
InputTypeNode,
20+
InterfaceOrObject,
21+
SelectionNodes,
22+
)
1623
from . import factories, primitives, validation
1724
from .ast import make_mutation, make_query
1825
from .containers import flatten
@@ -51,7 +58,9 @@ class GraphQLStrategy:
5158
_cache: Dict[str, Dict] = dataclasses.field(default_factory=dict)
5259

5360
def values(
54-
self, type_: graphql.GraphQLInputType, default: Optional[graphql.ValueNode] = None
61+
self,
62+
type_: graphql.GraphQLInputType,
63+
default: Optional[graphql.ValueNode] = None,
5564
) -> st.SearchStrategy[InputTypeNode]:
5665
"""Generate value nodes of a type, that corresponds to the input type.
5766
@@ -81,9 +90,18 @@ def values(
8190
return self.objects(type_, nullable)
8291
raise TypeError(f"Type {type_.__class__.__name__} is not supported.")
8392

84-
@instance_cache(lambda type_, nullable=True, default=None: (make_type_name(type_), nullable, default))
93+
@instance_cache(
94+
lambda type_, nullable=True, default=None: (
95+
make_type_name(type_),
96+
nullable,
97+
default,
98+
)
99+
)
85100
def lists(
86-
self, type_: graphql.GraphQLList, nullable: bool = True, default: Optional[graphql.ValueNode] = None
101+
self,
102+
type_: graphql.GraphQLList,
103+
nullable: bool = True,
104+
default: Optional[graphql.ValueNode] = None,
87105
) -> st.SearchStrategy[graphql.ListValueNode]:
88106
"""Generate a `graphql.ListValueNode`."""
89107
strategy = st.lists(self.values(type_.of_type))
@@ -121,16 +139,24 @@ def lists_of_object_fields(
121139
) -> st.SearchStrategy[List[graphql.ObjectFieldNode]]:
122140
return st.tuples(
123141
*(
124-
self.values(field.type, field.ast_node.default_value if field.ast_node is not None else None).map(
125-
factories.object_field(name)
126-
)
142+
self.values(
143+
field.type,
144+
field.ast_node.default_value if field.ast_node is not None else None,
145+
).map(factories.object_field(name))
127146
for name, field in items
128147
)
129148
).map(list)
130149

131-
@instance_cache(lambda interface, implementations: (interface.name, tuple(impl.name for impl in implementations)))
150+
@instance_cache(
151+
lambda interface, implementations: (
152+
interface.name,
153+
tuple(impl.name for impl in implementations),
154+
)
155+
)
132156
def interfaces(
133-
self, interface: graphql.GraphQLInterfaceType, implementations: List[InterfaceOrObject]
157+
self,
158+
interface: graphql.GraphQLInterfaceType,
159+
implementations: List[InterfaceOrObject],
134160
) -> st.SearchStrategy[SelectionNodes]:
135161
"""Build query for GraphQL interface type."""
136162
# If there are implementations that have fields with the same name but different types
@@ -376,7 +402,12 @@ def queries(
376402
if parsed_schema.query_type is None:
377403
raise InvalidArgument("Query type is not defined in the schema")
378404
return (
379-
_make_strategy(parsed_schema, type_=parsed_schema.query_type, fields=fields, custom_scalars=custom_scalars)
405+
_make_strategy(
406+
parsed_schema,
407+
type_=parsed_schema.query_type,
408+
fields=fields,
409+
custom_scalars=custom_scalars,
410+
)
380411
.map(make_query)
381412
.map(print_ast)
382413
)
@@ -403,7 +434,12 @@ def mutations(
403434
if parsed_schema.mutation_type is None:
404435
raise InvalidArgument("Mutation type is not defined in the schema")
405436
return (
406-
_make_strategy(parsed_schema, type_=parsed_schema.mutation_type, fields=fields, custom_scalars=custom_scalars)
437+
_make_strategy(
438+
parsed_schema,
439+
type_=parsed_schema.mutation_type,
440+
fields=fields,
441+
custom_scalars=custom_scalars,
442+
)
407443
.map(make_mutation)
408444
.map(print_ast)
409445
)

src/hypothesis_graphql/nodes.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@
88

99

1010
def String(
11-
value: typing.Any, StringValueNode: typing.Type[graphql.StringValueNode] = graphql.StringValueNode
11+
value: typing.Any,
12+
StringValueNode: typing.Type[graphql.StringValueNode] = graphql.StringValueNode,
1213
) -> graphql.StringValueNode:
1314
return StringValueNode(value=str(value))
1415

1516

1617
def Float(
17-
value: float, FloatValueNode: typing.Type[graphql.FloatValueNode] = graphql.FloatValueNode
18+
value: float,
19+
FloatValueNode: typing.Type[graphql.FloatValueNode] = graphql.FloatValueNode,
1820
) -> graphql.FloatValueNode:
1921
return FloatValueNode(value=str(value))
2022

@@ -31,7 +33,8 @@ def Object(
3133

3234

3335
def List(
34-
values: typing.List[graphql.ValueNode], ListValueNode: typing.Type[graphql.ListValueNode] = graphql.ListValueNode
36+
values: typing.List[graphql.ValueNode],
37+
ListValueNode: typing.Type[graphql.ListValueNode] = graphql.ListValueNode,
3538
) -> graphql.ListValueNode:
3639
return ListValueNode(values=values)
3740

src/hypothesis_graphql/types.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,18 @@
44
from hypothesis import strategies as st
55

66
# Leaf nodes, that don't have children
7-
ScalarValueNode = Union[graphql.IntValueNode, graphql.FloatValueNode, graphql.StringValueNode, graphql.BooleanValueNode]
8-
InputTypeNode = Union[ScalarValueNode, graphql.EnumValueNode, graphql.ListValueNode, graphql.ObjectValueNode]
7+
ScalarValueNode = Union[
8+
graphql.IntValueNode,
9+
graphql.FloatValueNode,
10+
graphql.StringValueNode,
11+
graphql.BooleanValueNode,
12+
]
13+
InputTypeNode = Union[
14+
ScalarValueNode,
15+
graphql.EnumValueNode,
16+
graphql.ListValueNode,
17+
graphql.ObjectValueNode,
18+
]
919
Field = Union[graphql.GraphQLField, graphql.GraphQLInputField]
1020
InterfaceOrObject = Union[graphql.GraphQLObjectType, graphql.GraphQLInterfaceType]
1121
SelectionNodes = List[graphql.SelectionNode]

0 commit comments

Comments
 (0)