diff --git a/src/functions/Makefile b/src/functions/Makefile index 5556dba4..c466e637 100644 --- a/src/functions/Makefile +++ b/src/functions/Makefile @@ -1,19 +1,40 @@ -tests: pytest +help:: + @echo "Available commands" + @echo " help -- (default) print this message" + +tests: mypy pytest +help:: + @echo " tests -- run all tests for supabase_functions package" pytest: uv run --package supabase_functions pytest --cov=./ --cov-report=xml --cov-report=html -vv +help:: + @echo " pytest -- run pytest on supabase_functions package" + +mypy: + uv run --package supabase_functions mypy src/supabase_functions tests +help:: + @echo " mypy -- run mypy on supabase_functions package" unasync: uv run --package supabase_functions run-unasync.py +help:: + @echo " unasync -- invoke run-unasync.py helper" build-sync: unasync sed -i '0,/SyncMock, /{s/SyncMock, //}' tests/_sync/test_function_client.py sed -i 's/SyncMock/Mock/g' tests/_sync/test_function_client.py sed -i 's/SyncClient/Client/g' src/supabase_functions/_sync/functions_client.py tests/_sync/test_function_client.py +help:: + @echo " build-sync -- generate _sync from _async implementation" clean: rm -rf htmlcov .pytest_cache .mypy_cache .ruff_cache rm -f .coverage coverage.xml +help:: + @echo " clean -- clean intermediary files" build: uv build --package supabase_functions +help:: + @echo " build -- invoke uv build on supabase_functions package" diff --git a/src/functions/pyproject.toml b/src/functions/pyproject.toml index 131e900f..4e8c219b 100644 --- a/src/functions/pyproject.toml +++ b/src/functions/pyproject.toml @@ -32,7 +32,10 @@ tests = [ lints = [ "unasync>=0.6.0", "ruff >=0.12.1", - "pre-commit >=3.4,<5.0" + "pre-commit >=3.4,<5.0", + "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)", ] dev = [{ include-group = "lints" }, {include-group = "tests" }] diff --git a/src/functions/run-unasync.py b/src/functions/run-unasync.py index 0d7c3fa1..3ea41c91 100644 --- a/src/functions/run-unasync.py +++ b/src/functions/run-unasync.py @@ -1,7 +1,7 @@ import unasync from pathlib import Path -paths = Path("src/functions").glob("**/*.py") +paths = Path("src/supabase_functions").glob("**/*.py") tests = Path("tests").glob("**/*.py") rules = (unasync._DEFAULT_RULE,) diff --git a/src/functions/src/supabase_functions/_async/functions_client.py b/src/functions/src/supabase_functions/_async/functions_client.py index 0ca6d23a..38ed3c61 100644 --- a/src/functions/src/supabase_functions/_async/functions_client.py +++ b/src/functions/src/supabase_functions/_async/functions_client.py @@ -74,9 +74,11 @@ async def _request( headers: Optional[Dict[str, str]] = None, json: Optional[Dict[Any, Any]] = None, ) -> Response: - user_data = {"data": json} if isinstance(json, str) else {"json": json} - response = await self._client.request(method, url, **user_data, headers=headers) - + response = ( + await self._client.request(method, url, data=json, headers=headers) + if isinstance(json, str) + else await self._client.request(method, url, json=json, headers=headers) + ) try: response.raise_for_status() except HTTPError as exc: diff --git a/src/functions/src/supabase_functions/_sync/functions_client.py b/src/functions/src/supabase_functions/_sync/functions_client.py index 2c50dd9a..95d30e42 100644 --- a/src/functions/src/supabase_functions/_sync/functions_client.py +++ b/src/functions/src/supabase_functions/_sync/functions_client.py @@ -74,9 +74,11 @@ def _request( headers: Optional[Dict[str, str]] = None, json: Optional[Dict[Any, Any]] = None, ) -> Response: - user_data = {"data": json} if isinstance(json, str) else {"json": json} - response = self._client.request(method, url, **user_data, headers=headers) - + response = ( + self._client.request(method, url, data=json, headers=headers) + if isinstance(json, str) + else self._client.request(method, url, json=json, headers=headers) + ) try: response.raise_for_status() except HTTPError as exc: diff --git a/src/functions/src/supabase_functions/py.typed b/src/functions/src/supabase_functions/py.typed new file mode 100644 index 00000000..e69de29b diff --git a/src/functions/tests/test_errors.py b/src/functions/tests/test_errors.py index bf296c5c..8401a0c3 100644 --- a/src/functions/tests/test_errors.py +++ b/src/functions/tests/test_errors.py @@ -22,11 +22,10 @@ def test_error_initialization( error_class: Type[FunctionsError], expected_name: str, expected_status: int ): test_message = "Test error message" - - if error_class is FunctionsError: + if issubclass(error_class, (FunctionsHttpError, FunctionsRelayError)): + error: FunctionsError = error_class(test_message) + elif error_class is FunctionsError: error = error_class(test_message, expected_name, expected_status) - else: - error = error_class(test_message) assert str(error) == test_message assert error.message == test_message @@ -48,10 +47,10 @@ def test_error_to_dict( ): test_message = "Test error message" - if error_class is FunctionsError: + if issubclass(error_class, (FunctionsHttpError, FunctionsRelayError)): + error: FunctionsError = error_class(test_message) + elif error_class is FunctionsError: error = error_class(test_message, expected_name, expected_status) - else: - error = error_class(test_message) error_dict = error.to_dict()