Skip to content

Commit

Permalink
Push release in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
Mo Balaa committed Dec 12, 2023
1 parent 0462d28 commit deef6ac
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 13 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
jobs:
# build_and_test:
# runs-on: ubuntu-latest

# steps:
# - name: Checkout repository
# uses: actions/checkout@v2

# - name: Run tests
# run: make test-ci

pypi-publish:
if: github.ref == 'refs/heads/main'
name: upload release to PyPI
runs-on: ubuntu-latest
# Specifying a GitHub environment is optional, but strongly encouraged
environment: release
permissions:
# IMPORTANT: this permission is mandatory for trusted publishing
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Install Poetry & Build
run: pip install poetry; poetry build

- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Fractal Matrix Client

This project is a thin wrapper around `matrix-nio`. It provides convenience helpers for working with synapse admin and the Matrix API
for Matrix powered projects.

## Example Usage

Context manager example:
```python
from fractal_matrix_client import MatrixClient

# Fractal Matrix Client can automatically discover the Matrix server associated with the given matrix_id if the homesrver is configured properly
async with MatrixClient(matrix_id='@user:matrix.org') as client:
res = await client.login('password')
print(res.access_token)

syt_bW8... #access_token
```
36 changes: 24 additions & 12 deletions fractal/matrix/async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from typing import Any, Dict, List, Optional, Union

import aiohttp
from fractal.matrix.utils import parse_matrix_id
from nio import (
AsyncClient,
AsyncClientConfig,
Expand All @@ -18,6 +17,8 @@
)
from nio.responses import RegisterErrorResponse

from fractal.matrix.utils import parse_matrix_id

from .exceptions import GetLatestSyncTokenError

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -248,21 +249,22 @@ async def example(client: FractalAsyncClient):
def __init__(
self,
homeserver_url: Optional[str] = None,
access_token: str = os.environ.get("HS_ACCESS_TOKEN", ""),
access_token: Optional[str] = None,
matrix_id: Optional[str] = None,
room_id: Optional[str] = None,
max_timeouts: int = 0,
):
try:
self.homeserver_url = homeserver_url or os.environ["MATRIX_HOMESERVER_URL"]
self.client = FractalAsyncClient(
self.homeserver_url, access_token, room_id=room_id, max_timeouts=max_timeouts
self.homeserver_url = homeserver_url or os.environ.get("MATRIX_HOMESERVER_URL")
self.matrix_id = matrix_id or os.environ.get("MATRIX_ID")
self.access_token = access_token or os.environ.get("MATRIX_ACCESS_TOKEN")
self.room_id = room_id
self.max_timeouts = max_timeouts

if not self.homeserver_url and not self.matrix_id:
raise KeyError(
"Environment variable MATRIX_HOMESERVER_URL or MATRIX_ID must be set if\
not passed explicitly to the MatrixClient context manager decorator."
)
except KeyError as e:
if e.args[0] == "MATRIX_HOMESERVER_URL":
raise KeyError(
"Environment variable MATRIX_HOMESERVER_URL must be set if\
not passed explicitly to the MatrixClient context manager decorator."
) from e

def __call__(self, func):
async def wrapper(*args, **kwargs):
Expand All @@ -272,6 +274,16 @@ async def wrapper(*args, **kwargs):
return wrapper

async def __aenter__(self):
if not self.homeserver_url:
self.homeserver_url = await get_homeserver_for_matrix_id(self.matrix_id)
self.client = FractalAsyncClient(
self.homeserver_url,
self.access_token,
room_id=self.room_id,
max_timeouts=self.max_timeouts,
)
if not self.access_token and self.matrix_id:
self.client.user = self.matrix_id
return self.client

async def __aexit__(self, exc_type, exc_value, traceback):
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "fractal-matrix-client"
version = "0.1.0"
version = "0.0.1"
description = ""
authors = ["Mo Balaa <balaa@fractalnetworks.co>"]
readme = "README.md"
Expand Down

0 comments on commit deef6ac

Please sign in to comment.