Skip to content

Commit

Permalink
chore: fix hatch run check to only check. Fix styles
Browse files Browse the repository at this point in the history
  • Loading branch information
KarolJagodzinski committed Feb 4, 2025
1 parent e772e8d commit 64e6cdc
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 67 deletions.
30 changes: 14 additions & 16 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ on:

jobs:
build:

runs-on: ubuntu-latest
strategy:
fail-fast: false
Expand Down Expand Up @@ -46,21 +45,20 @@ jobs:
strategy:
fail-fast: false
matrix:
library: ["fastapi", "starlette", "flask"]
env: ["test-integration-fastapi", "test-integration-starlette", "test-integration-flask"]
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install wheel
pip install -r tests_integrations/${{ matrix.library }}/requirements.txt
pip install -e .[asgi-file-uploads,tracing,telemetry,test,dev]
- name: Pytest
run: |
pytest tests_integrations/${{ matrix.library }}
- name: Checkout source code
uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install Hatch
uses: pypa/hatch@257e27e51a6a5616ed08a39a408a21c35c9931bc

- name: Run integration tests for ${{ matrix.env }}
run: hatch run ${{ matrix.env }}:test
6 changes: 2 additions & 4 deletions ariadne/resolvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,12 @@ def bind_to_schema(self, schema: GraphQLSchema) -> None:
self.add_resolvers_to_object_fields(type_object)

def add_resolvers_to_object_fields(self, type_object: GraphQLObjectType) -> None:
"""Sets explicit default resolver on a fields of an object that don't have any.
"""
"""Sets explicit default resolver on a fields of an object that don't have any.""" # noqa: E501
for field_name, field_object in type_object.fields.items():
self.add_resolver_to_field(field_name, field_object)

def add_resolver_to_field(self, _: str, field_object: GraphQLField) -> None:
"""Sets `default_field_resolver` as a resolver on a field that doesn't have any.
"""
"""Sets `default_field_resolver` as a resolver on a field that doesn't have any.""" # noqa: E501
if field_object.resolve is None:
field_object.resolve = default_field_resolver

Expand Down
16 changes: 5 additions & 11 deletions ariadne/scalars.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,9 @@ def parse_date_str(value: str) -> date:
# Parse "YYYY-MM-DD" string into date
return datetime.strptime(value, "%Y-%m-%d").date()
except (ValueError, TypeError):
raise ValueError(
f'"{value}" is not a date string in YYYY-MM-DD format.'
)
raise ValueError(f'"{value}" is not a date string in YYYY-MM-DD format.')
```
"""
""" # noqa: E501
self._parse_value = f
return f

Expand All @@ -264,21 +262,17 @@ def set_literal_parser(
@date_scalar.literal_parser
def parse_date_literal(
value: str, variable_values: Optional[dict[str, Any]] = None
) -> date:
def parse_date_literal(value: str, variable_values: Optional[dict[str, Any]] = None) -> date:
if not isinstance(ast, StringValueNode):
raise ValueError()
try:
# Parse "YYYY-MM-DD" string into date
return datetime.strptime(ast.value, "%Y-%m-%d").date()
except (ValueError, TypeError):
raise ValueError(
f'"{value}" is not a date string in YYYY-MM-DD format.'
)
raise ValueError(f'"{value}" is not a date string in YYYY-MM-DD format.')
```
"""
""" # noqa: E501
self._parse_literal = f
return f

Expand Down
10 changes: 3 additions & 7 deletions ariadne/schema_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,9 +373,7 @@ def visit_argument_definition(
) -> GraphQLArgument:
pass
def visit_interface(
self, interface: GraphQLInterfaceType
) -> GraphQLInterfaceType:
def visit_interface(self, interface: GraphQLInterfaceType) -> GraphQLInterfaceType:
pass
def visit_union(self, union: GraphQLUnionType) -> GraphQLUnionType:
Expand All @@ -389,17 +387,15 @@ def visit_enum_value(
) -> GraphQLEnumValue:
pass
def visit_input_object(
self, object_: GraphQLInputObjectType
) -> GraphQLInputObjectType:
def visit_input_object(self, object_: GraphQLInputObjectType) -> GraphQLInputObjectType:
pass
def visit_input_field_definition(
self, field: GraphQLInputField, object_type: GraphQLInputObjectType
) -> GraphQLInputField:
pass
```
"""
""" # noqa: E501

def __init__(self, name, args, visited_type, schema, context) -> None:
"""Instantiates the directive for schema object.
Expand Down
3 changes: 1 addition & 2 deletions ariadne/subscriptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ async def resolve_post(
_subscribers: dict[str, Subscriber]

def __init__(self) -> None:
"""Initializes the `SubscriptionType` with a GraphQL name set to `Subscription`.
"""
"""Initializes the `SubscriptionType` with a GraphQL name set to `Subscription`.""" # noqa: E501
super().__init__("Subscription")
self._subscribers = {}

Expand Down
23 changes: 6 additions & 17 deletions ariadne/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -570,17 +570,12 @@ def resolve(
from graphql import GraphQLResolveInfo
from graphql.pyutils import is_awaitable
class MyExtension(Extension):
def __init__(self):
self.paths = []
def resolve(
self,
next_: Resolver,
obj: Any,
info: GraphQLResolveInfo,
**kwargs
) -> Any:
def resolve(self, next_: Resolver, obj: Any, info: GraphQLResolveInfo, **kwargs) -> Any:
path = ".".join(map(str, info.path.as_list()))
# Fast implementation for synchronous resolvers
Expand All @@ -603,7 +598,7 @@ async def async_my_extension():
# GraphQL query executor will execute this closure for us
return async_my_extension()
```
"""
""" # noqa: E501
return next_(obj, info, **kwargs)

def has_errors(self, errors: list[GraphQLError], context: ContextValue) -> None:
Expand Down Expand Up @@ -649,19 +644,13 @@ def bind_to_schema(self, schema: GraphQLSchema) -> None:
raise ValueError(
"%s is defined in the schema, "
"but it is instance of %s (expected %s)"
% (
self.name,
type(graphql_type).__name__,
GraphQLInputType.__name__
)
% (self.name, type(graphql_type).__name__, GraphQLInputType.__name__)
)
for field, out_name in self._fields.items():
schema_field = graphql_type.fields.get(field)
if not schema_field:
raise ValueError(
"Type %s does not define the %s field" % (self.name, field)
)
raise ValueError("Type %s does not define the %s field" % (self.name, field))
schema_field.out_name = out_name
```
Expand Down Expand Up @@ -712,7 +701,7 @@ def resolve_count_users(*_, input):
input_type,
)
```
"""
""" # noqa: E501

def bind_to_schema(self, schema: GraphQLSchema) -> None:
"""Binds this `SchemaBindable` instance to the instance of GraphQL schema."""
6 changes: 2 additions & 4 deletions ariadne/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,7 @@ def unwrap_graphql_error(
assert (
unwrap_graphql_error(
GraphQLError(
"Error 1",
GraphQLError("Error 2", GraphQLError("Error 3", original_error=error)
)
"Error 1", GraphQLError("Error 2", GraphQLError("Error 3", original_error=error))
)
)
== error
Expand All @@ -156,7 +154,7 @@ def unwrap_graphql_error(
error = ValueError("I am a test!")
assert unwrap_graphql_error(error) == error
```
"""
""" # noqa: E501

if isinstance(error, GraphQLError):
return unwrap_graphql_error(error.original_error)
Expand Down
29 changes: 23 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ asgi-file-uploads = ["python-multipart>=0.0.5"]
tracing = ["opentracing"]
telemetry = ["opentelemetry-api"]
types = ["mypy[faster-cache]>=1.0.0"]
kaka = ["fastapi", "fastapi"]


[project.urls]
Expand Down Expand Up @@ -63,7 +64,7 @@ features = ["dev", "types"]

[tool.hatch.envs.default.scripts]
check = [
"hatch fmt",
"hatch fmt --check",
"hatch test -a -p",
"hatch test --cover",
"hatch run types:check",
Expand All @@ -74,7 +75,7 @@ check = [
[tool.hatch.envs.types.scripts]
check = "mypy --install-types --non-interactive"

## Test environment
## Test environments

[tool.hatch.envs.hatch-test]
extra-dependencies = [
Expand All @@ -95,6 +96,26 @@ extra-dependencies = [
]
extra-args = []

## Integration tests Flask environment
[tool.hatch.envs.test-integration-flask]
template = "hatch-test"
dependencies = ["flask"]
scripts.test = "hatch test tests_integrations/flask"


## Integration tests FastAPI environment
[tool.hatch.envs.test-integration-fastapi]
template = "hatch-test"
dependencies = ["fastapi"]
scripts.test = "hatch test tests_integrations/fastapi"

## Integration tests Starlette environment
[tool.hatch.envs.test-integration-starlette]
template = "hatch-test"
dependencies = ["starlette"]
scripts.test = "hatch test tests_integrations/starlette"


[[tool.hatch.envs.hatch-test.matrix]]
python = ["3.9", "3.10", "3.11", "3.12", "3.13"]

Expand Down Expand Up @@ -161,10 +182,6 @@ task-tags = ["NOTE", "TODO", "FIXME", "HACK", "XXX"]
[tool.ruff.lint.pycodestyle]
ignore-overlong-task-comments = true


# [tool.ruff.lint.flake8-tidy-imports]
# ban-relative-imports = "all"

[tool.ruff.lint.mccabe]
max-complexity = 15

Expand Down

0 comments on commit 64e6cdc

Please sign in to comment.