Skip to content

chore(BA-440): Upgrade mypy to 1.14.1 and ruff to 0.8.5 #3354

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

Merged
merged 9 commits into from
Jan 2, 2025
Prev Previous commit
Next Next commit
style: Make GraphQL literals more readable and easier to write
  • Loading branch information
achimnol committed Jan 2, 2025
commit 7e95cdbba9340bdf46dc0f1ec743c9397dc0a5b8
15 changes: 6 additions & 9 deletions src/ai/backend/client/func/acl.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import textwrap
from typing import Sequence

from ai.backend.client.output.fields import permission_fields
from ai.backend.client.output.types import FieldSpec

from ..output.fields import permission_fields
from ..output.types import FieldSpec
from ..session import api_session
from ..utils import dedent as _d
from .base import BaseFunction, api_function

__all__ = ("Permission",)
Expand All @@ -24,13 +23,11 @@ async def list(

:param fields: Additional permission query fields to fetch.
"""
query = textwrap.dedent(
"""\
query = _d("""
query {
vfolder_host_permissions {$fields}
vfolder_host_permissions { $fields }
}
"""
)
""")
query = query.replace("$fields", " ".join(f.field_ref for f in fields))
data = await api_session.get().Admin._query(query)
return data["vfolder_host_permissions"]
19 changes: 8 additions & 11 deletions src/ai/backend/client/func/agent.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
from __future__ import annotations

import textwrap
from typing import Optional, Sequence

from ai.backend.client.output.fields import agent_fields
from ai.backend.client.output.types import FieldSpec, PaginatedResult
from ai.backend.client.pagination import fetch_paginated_result
from ai.backend.client.request import Request
from ai.backend.client.session import api_session

from ..output.fields import agent_fields
from ..output.types import FieldSpec, PaginatedResult
from ..pagination import fetch_paginated_result
from ..request import Request
from ..session import api_session
from ..utils import dedent as _d
from .base import BaseFunction, api_function

__all__ = (
Expand Down Expand Up @@ -88,13 +87,11 @@ async def detail(
agent_id: str,
fields: Sequence[FieldSpec] = _default_detail_fields,
) -> Sequence[dict]:
query = textwrap.dedent(
"""\
query = _d("""
query($agent_id: String!) {
agent(agent_id: $agent_id) {$fields}
}
"""
)
""")
query = query.replace("$fields", " ".join(f.field_ref for f in fields))
variables = {"agent_id": agent_id}
data = await api_session.get().Admin._query(query, variables)
Expand Down
61 changes: 29 additions & 32 deletions src/ai/backend/client/func/domain.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import textwrap
from typing import Any, Iterable, Sequence

from ...cli.types import Undefined, undefined
from ..output.fields import domain_fields
from ..output.types import FieldSpec
from ..session import api_session
from ..types import set_if_set
from ..utils import dedent as _d
from .base import BaseFunction, api_function, resolve_fields

__all__ = ("Domain",)
Expand Down Expand Up @@ -56,13 +56,11 @@ async def list(

:param fields: Additional per-domain query fields to fetch.
"""
query = textwrap.dedent(
"""\
query = _d("""
query {
domains {$fields}
domains { $fields }
}
"""
)
""")
query = query.replace("$fields", " ".join(f.field_ref for f in fields))
data = await api_session.get().Admin._query(query)
return data["domains"]
Expand All @@ -75,18 +73,16 @@ async def detail(
fields: Sequence[FieldSpec] = _default_detail_fields,
) -> dict:
"""
Fetch information of a domain with name.
Retrieves the detail of a domain with name.

:param name: Name of the domain to fetch.
:param fields: Additional per-domain query fields to fetch.
"""
query = textwrap.dedent(
"""\
query = _d("""
query($name: String) {
domain(name: $name) {$fields}
domain(name: $name) { $fields }
}
"""
)
""")
query = query.replace("$fields", " ".join(f.field_ref for f in fields))
variables = {"name": name}
data = await api_session.get().Admin._query(query, variables)
Expand All @@ -108,17 +104,16 @@ async def create(
) -> dict:
"""
Creates a new domain with the given options.

You need an admin privilege for this operation.
"""
query = textwrap.dedent(
"""\
query = _d("""
mutation($name: String!, $input: DomainInput!) {
create_domain(name: $name, props: $input) {
ok msg domain {$fields}
ok msg domain { $fields }
}
}
"""
)
""")
resolved_fields = resolve_fields(fields, domain_fields, (domain_fields["name"],))
query = query.replace("$fields", " ".join(resolved_fields))
inputs = {
Expand Down Expand Up @@ -152,18 +147,17 @@ async def update(
fields: Iterable[FieldSpec | str] | None = None,
) -> dict:
"""
Update existing domain.
Updates an existing domain.

You need an admin privilege for this operation.
"""
query = textwrap.dedent(
"""\
query = _d("""
mutation($name: String!, $input: ModifyDomainInput!) {
modify_domain(name: $name, props: $input) {
ok msg
}
}
"""
)
""")
inputs: dict[str, Any] = {}
set_if_set(inputs, "name", new_name)
set_if_set(inputs, "description", description)
Expand All @@ -183,17 +177,19 @@ async def update(
@classmethod
async def delete(cls, name: str):
"""
Deletes an existing domain. This action only deletes the primary record and might leave behind some associated data or metadata that can be manually cleaned up or ignored. Ideal for removing items that may be re-created or restored.
Deletes an existing domain.

This action only deletes the primary record and might leave behind some associated data or
metadata that can be manually cleaned up or ignored. Ideal for removing items that may be
re-created or restored.
"""
query = textwrap.dedent(
"""\
query = _d("""
mutation($name: String!) {
delete_domain(name: $name) {
ok msg
}
}
"""
)
""")
variables = {"name": name}
data = await api_session.get().Admin._query(query, variables)
return data["delete_domain"]
Expand All @@ -202,17 +198,18 @@ async def delete(cls, name: str):
@classmethod
async def purge(cls, name: str):
"""
Purges an existing domain. This action is irreversible and should be used when you need to ensure that no trace of the resource remains.
Purges an existing domain.

This action is irreversible and should be used when you need to ensure that no trace of the
resource remains.
"""
query = textwrap.dedent(
"""\
query = _d("""
mutation($name: String!) {
purge_domain(name: $name) {
ok msg
}
}
"""
)
""")
variables = {"name": name}
data = await api_session.get().Admin._query(query, variables)
return data["purge_domain"]
56 changes: 19 additions & 37 deletions src/ai/backend/client/func/group.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import textwrap
from typing import Any, Iterable, Optional, Sequence

from ai.backend.client.output.fields import group_fields
Expand All @@ -7,6 +6,7 @@
from ...cli.types import Undefined, undefined
from ..session import api_session
from ..types import set_if_set
from ..utils import dedent as _d
from .base import BaseFunction, api_function, resolve_fields

__all__ = ("Group",)
Expand Down Expand Up @@ -60,13 +60,11 @@ async def from_name(
:param domain_name: Name of domain to get groups from.
:param fields: Per-group query fields to fetch.
"""
query = textwrap.dedent(
"""\
query = _d("""
query($name: String!, $domain_name: String) {
groups_by_name(name: $name, domain_name: $domain_name) {$fields}
}
"""
)
""")
resolved_fields = resolve_fields(fields, group_fields, _default_detail_fields)
query = query.replace("$fields", " ".join(resolved_fields))
variables = {
Expand All @@ -91,13 +89,11 @@ async def list(
"""
if fields is None:
fields = _default_list_fields
query = textwrap.dedent(
"""\
query = _d("""
query($domain_name: String) {
groups(domain_name: $domain_name) {$fields}
}
"""
)
""")
query = query.replace("$fields", " ".join(f.field_ref for f in fields))
variables = {"domain_name": domain_name}
data = await api_session.get().Admin._query(query, variables)
Expand All @@ -118,13 +114,11 @@ async def detail(
"""
if fields is None:
fields = _default_detail_fields
query = textwrap.dedent(
"""\
query = _d("""
query($gid: UUID!) {
group(id: $gid) {$fields}
}
"""
)
""")
query = query.replace("$fields", " ".join(f.field_ref for f in fields))
variables = {"gid": gid}
data = await api_session.get().Admin._query(query, variables)
Expand All @@ -148,15 +142,13 @@ async def create(
Creates a new group with the given options.
You need an admin privilege for this operation.
"""
query = textwrap.dedent(
"""\
query = _d("""
mutation($name: String!, $input: GroupInput!) {
create_group(name: $name, props: $input) {
ok msg group {$fields}
}
}
"""
)
""")
resolved_fields = resolve_fields(
fields,
group_fields,
Expand Down Expand Up @@ -195,15 +187,13 @@ async def update(
Update existing group.
You need an admin privilege for this operation.
"""
query = textwrap.dedent(
"""\
query = _d("""
mutation($gid: UUID!, $input: ModifyGroupInput!) {
modify_group(gid: $gid, props: $input) {
ok msg
}
}
"""
)
""")
inputs: dict[str, Any] = {}
set_if_set(inputs, "name", name)
set_if_set(inputs, "description", description)
Expand All @@ -224,15 +214,13 @@ async def delete(cls, gid: str):
"""
Inactivates the existing group. Does not actually delete it for safety.
"""
query = textwrap.dedent(
"""\
query = _d("""
mutation($gid: UUID!) {
delete_group(gid: $gid) {
ok msg
}
}
"""
)
""")
variables = {"gid": gid}
data = await api_session.get().Admin._query(query, variables)
return data["delete_group"]
Expand All @@ -243,15 +231,13 @@ async def purge(cls, gid: str):
"""
Delete the existing group. This action cannot be undone.
"""
query = textwrap.dedent(
"""\
query = _d("""
mutation($gid: UUID!) {
purge_group(gid: $gid) {
ok msg
}
}
"""
)
""")
variables = {"gid": gid}
data = await api_session.get().Admin._query(query, variables)
return data["purge_group"]
Expand All @@ -265,15 +251,13 @@ async def add_users(
Add users to a group.
You need an admin privilege for this operation.
"""
query = textwrap.dedent(
"""\
query = _d("""
mutation($gid: UUID!, $input: ModifyGroupInput!) {
modify_group(gid: $gid, props: $input) {
ok msg
}
}
"""
)
""")
variables = {
"gid": gid,
"input": {
Expand All @@ -293,15 +277,13 @@ async def remove_users(
Remove users from a group.
You need an admin privilege for this operation.
"""
query = textwrap.dedent(
"""\
query = _d("""
mutation($gid: UUID!, $input: ModifyGroupInput!) {
modify_group(gid: $gid, props: $input) {
ok msg
}
}
"""
)
""")
variables = {
"gid": gid,
"input": {
Expand Down
Loading
Loading