Skip to content
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
20 changes: 12 additions & 8 deletions src/py/client/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# pyright: strict, reportUnknownMemberType=false, reportUnknownVariableType=false
from __future__ import annotations

from typing import TYPE_CHECKING, Any, Optional
from typing import TYPE_CHECKING, Any, Optional, Self

import requests

Expand Down Expand Up @@ -123,7 +123,7 @@ def __init__(
else:
raise

def __enter__(self, *_: Any) -> Client:
def __enter__(self, *_: Any) -> Self:
return self

def __exit__(self, *_: Any) -> None:
Expand Down Expand Up @@ -244,11 +244,14 @@ def test_src(
seed: Optional[int] = None,
timeout: Optional[float] = None,
) -> simple_api_pb2.TestRes:
seed = seed or 0
req = simple_api_pb2.TestSrcReq(src=src, session=self._sesh)
if seed is not None:
req.seed = seed

timeout = timeout or self._timeout
return self._client.test_src(
ctx=self.mk_context(),
request=simple_api_pb2.TestSrcReq(src=src, session=self._sesh, seed=seed),
request=req,
timeout=timeout,
)

Expand All @@ -266,13 +269,14 @@ def test_name(
seed: Optional[int] = None,
timeout: Optional[float] = None,
) -> simple_api_pb2.TestRes:
seed = seed or 0
req = simple_api_pb2.TestNameReq(name=name, session=self._sesh)
if seed is not None:
req.seed = seed

timeout = timeout or self._timeout
return self._client.test_name(
ctx=self.mk_context(),
request=simple_api_pb2.TestNameReq(
name=name, session=self._sesh, seed=seed
),
request=req,
timeout=timeout,
)

Expand Down
44 changes: 32 additions & 12 deletions src/py/client/_async.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# pyright: strict, reportUnknownMemberType=false, reportUnknownVariableType=false
from __future__ import annotations

from typing import Any, Optional
from typing import Any, Optional, Self

import aiohttp # type: ignore[import-not-found]

Expand Down Expand Up @@ -75,7 +75,7 @@ def __init__(
)
self._timeout = timeout

async def __aenter__(self, *_: Any) -> AsyncClient:
async def __aenter__(self, *_: Any) -> Self:
await self._session.__aenter__()
if self._session_id is None:
try:
Expand Down Expand Up @@ -217,36 +217,56 @@ async def instance_src(
timeout=timeout,
)

async def qcheck_src(
async def test_src(
self,
src: str,
seed: Optional[int] = None,
timeout: Optional[float] = None,
) -> simple_api_pb2.TestRes:
seed = seed or 0
req = simple_api_pb2.TestSrcReq(src=src, session=self._sesh)
if seed is not None:
req.seed = seed

timeout = timeout or self._timeout
return await self._client.qcheck_src(
return await self._client.test_src(
ctx=self.mk_context(),
request=simple_api_pb2.QCheckSrcReq(src=src, session=self._sesh, seed=seed),
request=req,
timeout=timeout,
)

async def qcheck_name(
async def qcheck_src(
self,
src: str,
seed: Optional[int] = None,
timeout: Optional[float] = None,
) -> simple_api_pb2.TestRes:
return await self.test_src(src=src, seed=seed, timeout=timeout)

async def test_name(
self,
name: str,
seed: Optional[int] = None,
timeout: Optional[float] = None,
) -> simple_api_pb2.TestRes:
seed = seed or 0
req = simple_api_pb2.TestNameReq(name=name, session=self._sesh)
if seed is not None:
req.seed = seed

timeout = timeout or self._timeout
return await self._client.qcheck_name(
return await self._client.test_name(
ctx=self.mk_context(),
request=simple_api_pb2.QCheckNameReq(
name=name, session=self._sesh, seed=seed
),
request=req,
timeout=timeout,
)

async def qcheck_name(
self,
name: str,
seed: Optional[int] = None,
timeout: Optional[float] = None,
) -> simple_api_pb2.TestRes:
return await self.test_name(name=name, seed=seed, timeout=timeout)

async def list_artifacts(
self, task: task_pb2.Task, timeout: Optional[float] = None
) -> api_pb2.ArtifactListResult:
Expand Down
6 changes: 5 additions & 1 deletion src/py/client/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,8 @@ def is_session_not_found(ex: TwirpServerException) -> bool:
# Replace with a typed code check once the server is updated.
body = (getattr(ex, "meta", None) or {}).get("body") or {} # type: ignore
msg = body.get("msg") or "" # type: ignore
return "Session not found" in msg or "Unknown session" in msg
return (
"Session not found" in msg
or "Unknown session" in msg
or "InvalidSession" in msg
)
2 changes: 1 addition & 1 deletion src/py/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "imandrax_api"
version = "0.20.1"
version = "0.20.2"
description = "Imandrax API client library"
requires-python = ">=3.12"
dependencies = [
Expand Down
2 changes: 1 addition & 1 deletion src/py/setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from setuptools import setup

VERSION = "0.20.1"
VERSION = "0.20.2"
setup(
name="imandrax_api",
version=VERSION,
Expand Down
2 changes: 1 addition & 1 deletion src/py/uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading