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
35 changes: 30 additions & 5 deletions src/postgrest/Makefile
Original file line number Diff line number Diff line change
@@ -1,26 +1,47 @@
tests: pytest
help::
@echo "Available commands"
@echo " help -- (default) print this message"

tests: mypy pytest
help::
@echo " tests -- run all tests for postgrest package"

pytest: start-infra
uv run --package postgrest pytest --cov=./ --cov-report=xml -vv
help::
@echo " pytest -- run pytest on postgrest package"

mypy:
uv run --package supabase_functions mypy src/postgrest tests
help::
@echo " mypy -- run mypy on postgrest package"

start-infra:
cd infra &&\
docker compose down &&\
docker compose up -d
sleep 2
help::
@echo " stop-infra -- start containers for tests"

stop-infra:
cd infra &&\
docker compose down --remove-orphans
help::
@echo " stop-infra -- stop containers for tests"

clean-infra:
cd infra &&\
docker compose down --remove-orphans &&\
docker system prune -a --volumes -f

stop-infra:
cd infra &&\
docker compose down --remove-orphans
help::
@echo " clean-infra -- delete all stored information about the containers"

clean:
rm -rf htmlcov .pytest_cache .mypy_cache .ruff_cache
rm -f .coverage coverage.xml
help::
@echo " clean -- clean intermediary files generated by tests"

unasync:
uv run --package postgrest run-unasync.py
Expand All @@ -33,6 +54,10 @@ build-sync: unasync
sed -i 's/SyncHTTPTransport/HTTPTransport/g' tests/_sync/**.py
sed -i 's/SyncClient/Client/g' src/postgrest/_sync/**.py tests/_sync/**.py
sed -i 's/self\.session\.aclose/self\.session\.close/g' src/postgrest/_sync/client.py
help::
@echo " build-sync -- generate _sync from _async implementation"

build:
uv build --package postgrest
help::
@echo " build -- invoke uv build on storage3 package"
15 changes: 15 additions & 0 deletions src/postgrest/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ test = [
lints = [
"pre-commit >=4.2.0",
"ruff >=0.12.1",
"python-lsp-server (>=1.12.2,<2.0.0)",
"pylsp-mypy (>=0.7.0,<0.8.0)",
"python-lsp-ruff (>=2.2.2,<3.0.0)",
]
docs = [
"sphinx >=7.1.2",
Expand Down Expand Up @@ -84,3 +87,15 @@ filterwarnings = [
[build-system]
requires = ["uv_build>=0.8.3,<0.9.0"]
build-backend = "uv_build"

[tool.mypy]
python_version = "3.9"
check_untyped_defs = true
allow_redefinition = true
follow_untyped_imports = true # for deprecation module that does not have stubs

no_warn_no_return = true
warn_return_any = true
warn_unused_configs = true
warn_redundant_casts = true
warn_unused_ignores = true
2 changes: 1 addition & 1 deletion src/postgrest/run-unasync.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import unasync

paths = Path("src/supabase").glob("**/*.py")
paths = Path("src/postgrest").glob("**/*.py")
tests = Path("tests").glob("**/*.py")

rules = (unasync._DEFAULT_RULE,)
Expand Down
16 changes: 7 additions & 9 deletions src/postgrest/src/postgrest/_async/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
from ..version import __version__
from .request_builder import AsyncRequestBuilder, AsyncRPCFilterRequestBuilder

_TableT = Dict[str, Any]


class AsyncPostgrestClient(BasePostgrestClient):
"""PostgREST client."""
Expand Down Expand Up @@ -72,7 +70,7 @@ def __init__(
proxy=proxy,
http_client=http_client,
)
self.session = cast(AsyncClient, self.session)
self.session: AsyncClient = self.session

def create_session(
self,
Expand Down Expand Up @@ -122,17 +120,17 @@ async def aclose(self) -> None:
"""Close the underlying HTTP connections."""
await self.session.aclose()

def from_(self, table: str) -> AsyncRequestBuilder[_TableT]:
def from_(self, table: str) -> AsyncRequestBuilder:
"""Perform a table operation.

Args:
table: The name of the table
Returns:
:class:`AsyncRequestBuilder`
"""
return AsyncRequestBuilder[_TableT](self.session, f"/{table}")
return AsyncRequestBuilder(self.session, f"/{table}")

def table(self, table: str) -> AsyncRequestBuilder[_TableT]:
def table(self, table: str) -> AsyncRequestBuilder:
"""Alias to :meth:`from_`."""
return self.from_(table)

Expand All @@ -148,7 +146,7 @@ def rpc(
count: Optional[CountMethod] = None,
head: bool = False,
get: bool = False,
) -> AsyncRPCFilterRequestBuilder[Any]:
) -> AsyncRPCFilterRequestBuilder:
"""Perform a stored procedure call.

Args:
Expand All @@ -175,7 +173,7 @@ def rpc(
headers = Headers({"Prefer": f"count={count}"}) if count else Headers()

if method in ("HEAD", "GET"):
return AsyncRPCFilterRequestBuilder[Any](
return AsyncRPCFilterRequestBuilder(
self.session,
f"/rpc/{func}",
method,
Expand All @@ -184,6 +182,6 @@ def rpc(
json={},
)
# the params here are params to be sent to the RPC and not the queryparams!
return AsyncRPCFilterRequestBuilder[Any](
return AsyncRPCFilterRequestBuilder(
self.session, f"/rpc/{func}", method, headers, QueryParams(), json=params
)
Loading