Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Updating dependencies. #123

Merged
merged 3 commits into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/build-and-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,3 @@ jobs:

- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ The libraries and tools that make Platformics work:
5. Run `make token` to generate an authorization token that you can use to interact with the API. The `make` target copies the necessary headers to the system clipboard. Paste the token into the `headers` section at the bottom of the GraphQL explorer API

## Versioning platformics
Platformics can be used in downstream applications by
Platformics can be used in downstream applications by
1) using the platformics image as the base Docker image. To select a version of platformics, add the appropriate version tags to the docker image
2) installing as a dependency, `pip install platformics`.

Expand Down
4 changes: 2 additions & 2 deletions platformics/cli/generate_token.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import click

from platformics.security.token_auth import create_token
from platformics.settings import Settings
from platformics.settings import APISettings


@click.group()
Expand Down Expand Up @@ -47,7 +47,7 @@ def auth() -> None:
)
@click.pass_context
def generate_token(ctx: click.Context, userid: int, project: list[str], expiration: int) -> None:
settings = Settings.model_validate({})
settings = APISettings.model_validate({})
private_key = settings.JWK_PRIVATE_KEY

project_roles: dict[str, list[int]] = {"member": [], "owner": [], "viewer": []}
Expand Down
4 changes: 2 additions & 2 deletions platformics/cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from platformics.codegen.generator import generate
from platformics.security.token_auth import create_token
from platformics.settings import Settings
from platformics.settings import APISettings


@click.group()
Expand Down Expand Up @@ -76,7 +76,7 @@ def auth() -> None:
)
@click.pass_context
def generate_token(ctx: click.Context, userid: int, project: list[str], expiration: int) -> None:
settings = Settings.model_validate({})
settings = APISettings.model_validate({})
private_key = settings.JWK_PRIVATE_KEY

project_roles: dict[str, list[int]] = {"member": [], "owner": [], "viewer": []}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ from sqlalchemy import inspect
from sqlalchemy.engine.row import RowMapping
from sqlalchemy.ext.asyncio import AsyncSession
from platformics.graphql_api import relay
from strawberry.field import StrawberryField
from strawberry.types import Info
from support.limit_offset import LimitOffsetClause
from typing_extensions import TypedDict
Expand Down
5 changes: 5 additions & 0 deletions platformics/graphql_api/core/error_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ class DefaultExceptionHandler(ExceptionHandler):
error_message: str = "Unexpected error."

def convert_exception(self, err: Any) -> list[GraphQLError]:
try:
if isinstance(err, GraphQLError) and not err.original_error:
return [err]
except AttributeError:
pass
return [
GraphQLError(
message=self.error_message,
Expand Down
37 changes: 16 additions & 21 deletions platformics/graphql_api/core/strawberry_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
from fastapi.dependencies.models import Dependant
from fastapi.params import Depends as DependsClass
from strawberry.extensions import FieldExtension
from strawberry.field import StrawberryField
from strawberry.types import Info
from strawberry.types.field import StrawberryField


def get_func_with_only_deps(func: typing.Callable[..., typing.Any]) -> typing.Callable[..., typing.Any]:
Expand Down Expand Up @@ -61,27 +61,22 @@ async def resolve_async(
except AttributeError:
request.context = {"dependency_cache": {}}

if not request.scope.get("sberrystack"):
async with AsyncExitStack() as async_exit_stack:
request.scope["sberrystack"] = AsyncExitStack()

solved_result = await deputils.solve_dependencies(
request=request,
dependant=self.dependant,
body={},
dependency_overrides_provider=request.app,
dependency_cache=request.context["dependency_cache"],
async_exit_stack=request.scope["sberrystack"],
)
(
solved_values,
_, # solver_errors. It shouldn't be possible for it to contain
# anything relevant to this extension.
_, # background tasks
_, # the subdependency returns the same response we have
new_cache, # sub_dependency_cache
) = solved_result
solved_result = await deputils.solve_dependencies(
request=request,
dependant=self.dependant,
body={},
dependency_overrides_provider=request.app,
dependency_cache=request.context["dependency_cache"],
async_exit_stack=async_exit_stack,
embed_body_fields=False,
)
solved_values = solved_result.values
new_cache = solved_result.dependency_cache
request.context["dependency_cache"].update(new_cache)

request.context["dependency_cache"].update(new_cache)
kwargs = solved_values | kwargs # solved_values has None values that need to be overridden by kwargs
res = await next_(source, info, **kwargs)
kwargs = solved_values | kwargs # solved_values has None values that need to be overridden by kwargs
res = await next_(source, info, **kwargs)
return res
8 changes: 4 additions & 4 deletions platformics/graphql_api/relay/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@

import strawberry
from strawberry.annotation import StrawberryAnnotation
from strawberry.arguments import StrawberryArgument, argument
from strawberry.extensions.field_extension import (
AsyncExtensionResolver,
FieldExtension,
SyncExtensionResolver,
)
from strawberry.field import _RESOLVER_TYPE, StrawberryField, field
from strawberry.lazy_type import LazyType
from strawberry.type import StrawberryList, StrawberryOptional
from strawberry.types.arguments import StrawberryArgument, argument
from strawberry.types.base import StrawberryList, StrawberryOptional
from strawberry.types.field import _RESOLVER_TYPE, StrawberryField, field
from strawberry.types.fields.resolver import StrawberryResolver
from strawberry.types.lazy_type import LazyType
from strawberry.utils.aio import asyncgen_to_list
from strawberry.utils.typing import eval_type
from typing_extensions import Annotated, get_origin
Expand Down
10 changes: 5 additions & 5 deletions platformics/graphql_api/relay/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@
)

import strawberry
from strawberry.field import field
from strawberry.object_type import interface, type
from strawberry.private import StrawberryPrivate

# from strawberry.relay import GlobalID
# from strawberry.relay import Node as StrawberryNode
from strawberry.type import StrawberryContainer, get_object_definition
from strawberry.types import get_object_definition
from strawberry.types.base import StrawberryContainer, StrawberryObjectDefinition
from strawberry.types.field import field
from strawberry.types.info import Info # noqa: TCH001
from strawberry.types.types import StrawberryObjectDefinition
from strawberry.types.object_type import interface, type
from strawberry.types.private import StrawberryPrivate
from strawberry.utils.aio import aenumerate, aislice, resolve_awaitable
from strawberry.utils.inspect import in_async_context
from strawberry.utils.typing import eval_type, is_classvar
Expand Down
7 changes: 6 additions & 1 deletion platformics/graphql_api/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,12 @@ def get_graphql_name(self, obj: HasGraphQLName) -> str:
return super().get_graphql_name(obj)


def get_app(settings: APISettings, schema: strawberry.Schema, db_module: typing.Any, dependencies: typing.Optional[typing.Sequence[Depends]] = []) -> FastAPI:
def get_app(
settings: APISettings,
schema: strawberry.Schema,
db_module: typing.Any,
dependencies: typing.Optional[typing.Sequence[Depends]] = [],
) -> FastAPI:
"""
Make sure tests can get their own instances of the app.
"""
Expand Down
1 change: 0 additions & 1 deletion platformics/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ class APISettings(Settings):
DEFAULT_UPLOAD_BUCKET: str
DEFAULT_UPLOAD_PROTOCOL: str


@cached_property
def JWK_PRIVATE_KEY(self) -> jwk.JWK: # noqa: N802
key = None
Expand Down
Loading
Loading