From 64e6cdcf1edecec1c2c50d33bee55564fc67206e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karol=20Jagodzi=C5=84ski?= Date: Mon, 3 Feb 2025 20:47:50 +0100 Subject: [PATCH] chore: fix `hatch run check` to only check. Fix styles --- .github/workflows/tests.yml | 30 ++++++++++++++---------------- ariadne/resolvers.py | 6 ++---- ariadne/scalars.py | 16 +++++----------- ariadne/schema_visitor.py | 10 +++------- ariadne/subscriptions.py | 3 +-- ariadne/types.py | 23 ++++++----------------- ariadne/utils.py | 6 ++---- pyproject.toml | 29 +++++++++++++++++++++++------ 8 files changed, 56 insertions(+), 67 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index d5a9757e..9026ff8c 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -10,7 +10,6 @@ on: jobs: build: - runs-on: ubuntu-latest strategy: fail-fast: false @@ -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 diff --git a/ariadne/resolvers.py b/ariadne/resolvers.py index d6be4fe6..be1769ac 100644 --- a/ariadne/resolvers.py +++ b/ariadne/resolvers.py @@ -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 diff --git a/ariadne/scalars.py b/ariadne/scalars.py index 9ccf0012..a159dbde 100644 --- a/ariadne/scalars.py +++ b/ariadne/scalars.py @@ -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 @@ -264,9 +262,7 @@ 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() @@ -274,11 +270,9 @@ def parse_date_literal( # 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 diff --git a/ariadne/schema_visitor.py b/ariadne/schema_visitor.py index 0f01ecea..608ffebd 100644 --- a/ariadne/schema_visitor.py +++ b/ariadne/schema_visitor.py @@ -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: @@ -389,9 +387,7 @@ 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( @@ -399,7 +395,7 @@ def visit_input_field_definition( ) -> GraphQLInputField: pass ``` - """ + """ # noqa: E501 def __init__(self, name, args, visited_type, schema, context) -> None: """Instantiates the directive for schema object. diff --git a/ariadne/subscriptions.py b/ariadne/subscriptions.py index 5e02411d..d48abe18 100644 --- a/ariadne/subscriptions.py +++ b/ariadne/subscriptions.py @@ -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 = {} diff --git a/ariadne/types.py b/ariadne/types.py index 0c282f93..d644400f 100644 --- a/ariadne/types.py +++ b/ariadne/types.py @@ -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 @@ -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: @@ -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 ``` @@ -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.""" diff --git a/ariadne/utils.py b/ariadne/utils.py index c67e469c..9e0d7992 100644 --- a/ariadne/utils.py +++ b/ariadne/utils.py @@ -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 @@ -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) diff --git a/pyproject.toml b/pyproject.toml index 93836c94..bfb3e559 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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] @@ -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", @@ -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 = [ @@ -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"] @@ -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