Skip to content

chore: rename package to supabase_functions #37

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 5 commits into from
Feb 29, 2024
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
12 changes: 11 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,18 @@ jobs:
fetch-depth: 0
token: ${{ secrets.SILENTWORKS_PAT }}

- name: Rename Project
id: rename_project
run: make rename_project

- name: Python Semantic Release
id: release
uses: python-semantic-release/[email protected]
with:
github_token: ${{ secrets.GITHUB_TOKEN }}

- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
# NOTE: DO NOT wrap the conditional in ${{ }} as it will always evaluate to true.
# See https://github.com/actions/runner/issues/1173
if: needs.publish.release.outputs.released == 'true'
if: steps.release.outputs.released == 'true'
10 changes: 9 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,12 @@ tests_only:
poetry run pytest --cov=./ --cov-report=xml --cov-report=html -vv

build_sync:
poetry run unasync supafunc tests
poetry run unasync supabase_functions tests

rename_project: rename_package_dir rename_package

rename_package_dir:
mv supabase_functions supafunc

rename_package:
sed -i 's/supabase_functions/supafunc/g' pyproject.toml tests/_async/clients.py tests/_sync/clients.py tests/_async/test_function_client.py tests/_sync/test_function_client.py
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

## Installation

`pip3 install supafunc`
`pip3 install supabase_functions`

## Usage

Expand All @@ -12,7 +12,7 @@ Deploy your function as per documentation.

```python3
import asyncio
from supafunc import AsyncFunctionsClient
from supabase_functions import AsyncFunctionsClient
async def run_func():
fc = AsyncFunctionsClient("https://<project_ref>.functions.supabase.co", {})
res = await fc.invoke("payment-sheet", {"responseType": "json"})
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ def set_auth(self, token: str) -> None:

self.headers["Authorization"] = f"Bearer {token}"

def invoke(self, function_name: str, invoke_options: Optional[Dict] = None) -> Dict:
def invoke(
self, function_name: str, invoke_options: Optional[Dict] = None
) -> Union[Dict, bytes]:
"""Invokes a function

Parameters
Expand All @@ -54,11 +56,6 @@ def invoke(self, function_name: str, invoke_options: Optional[Dict] = None) -> D
`headers`: object representing the headers to send with the request
`body`: the body of the request
`responseType`: how the response should be parsed. The default is `json`

Returns
-------
Dict
Dictionary with data
"""
headers = self.headers
if invoke_options is not None:
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion tests/_async/clients.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from jwt import encode

from supafunc import AsyncFunctionsClient
from supabase_functions import AsyncFunctionsClient

GOTRUE_JWT_SECRET = "37c304f8-51aa-419a-a1af-06154e63707a"
FUNCTIONS_URL = "http://localhost:54321/functions/v1"
Expand Down
2 changes: 1 addition & 1 deletion tests/_async/test_function_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from httpx import Response
from jwt import encode

from supafunc.errors import FunctionsHttpError, FunctionsRelayError
from supabase_functions.errors import FunctionsHttpError, FunctionsRelayError

from .clients import (
FUNCTIONS_URL,
Expand Down
2 changes: 1 addition & 1 deletion tests/_sync/clients.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from jwt import encode

from supafunc import SyncFunctionsClient
from supabase_functions import SyncFunctionsClient

GOTRUE_JWT_SECRET = "37c304f8-51aa-419a-a1af-06154e63707a"
FUNCTIONS_URL = "http://localhost:54321/functions/v1"
Expand Down
16 changes: 14 additions & 2 deletions tests/_sync/test_function_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from httpx import Response
from jwt import encode

from supafunc.errors import FunctionsHttpError, FunctionsRelayError
from supabase_functions.errors import FunctionsHttpError, FunctionsRelayError

from .clients import (
FUNCTIONS_URL,
Expand Down Expand Up @@ -68,5 +68,17 @@ def test_invoke_with_non_200_response():
return_value=Response(404),
side_effect=FunctionsHttpError("Http error!"),
)
with pytest.raises(FunctionsHttpError, match=r"Http error!"):
with pytest.raises(FunctionsHttpError, match=r"Http error!") as exc:
function_client().invoke(function_name="hello-world")
assert exc.value.message == "Http error!"


def test_relay_error_message():
with respx.mock:
respx.post(f"{FUNCTIONS_URL}/hello-world").mock(
return_value=Response(200, headers={"x-relay-header": "true"}),
side_effect=FunctionsRelayError("Relay error!"),
)
with pytest.raises(FunctionsRelayError, match=r"Relay error!") as exc:
function_client().invoke(function_name="hello-world")
assert exc.value.message == "Relay error!"