Skip to content

Commit

Permalink
Merge branch 'main' into callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
DobromirM committed Jun 10, 2024
2 parents 61deab5 + d08a8df commit 49158d8
Show file tree
Hide file tree
Showing 46 changed files with 201 additions and 172 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/python_publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Swim Python Client Publish

on:
push:
tags:
- '*'

jobs:
pypi-publish:
name: Upload release to PyPI
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/p/<your-pypi-project-name>
permissions:
id-token: write
steps:
- name: Build
uses: actions/checkout@v4
- run: python3 -m pip install --upgrade build && python3 -m build

- name: Publish package distributions to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Swim System Python Implementation
[![PyPI version](https://badge.fury.io/py/swimai.svg)](https://badge.fury.io/py/swimai)
[![PyPI version](https://badge.fury.io/py/swimos.svg)](https://badge.fury.io/py/swimos)
[![Build Status](https://dev.azure.com/swimai-build/swim-rust/_apis/build/status/swimos.swim-system-python?branchName=main)](https://dev.azure.com/swimai-build/swim-rust/_build/latest?definitionId=6&branchName=main)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](LICENSE)
[![Code of Conduct](https://img.shields.io/badge/code-of%20conduct-green.svg)](CODE_OF_CONDUCT.md)
Expand All @@ -17,13 +17,13 @@ enabling every state of a Web API to be streamed, without
interference from billions of queues.
<br>
## Installation
`pip install swimai`
`pip install swimos`
## Usage
```python
# Setting the value of a value lane on a remote agent.
import time

from swimai import SwimClient
from swimos import SwimClient

with SwimClient() as swim_client:
host_uri = 'ws://localhost:9001'
Expand Down Expand Up @@ -57,7 +57,7 @@ with SwimClient() as swim_client:
##### With coverage:
1) Install async test package: `pip install aiounittest`
2) Install coverage package: `pip install coverage`
3) Generate report: `coverage run --source=swimai -m unittest`
3) Generate report: `coverage run --source=swimos -m unittest`
4) View report: `coverage report -m`

### Run Lint
Expand All @@ -68,9 +68,9 @@ with SwimClient() as swim_client:
1) Install commit hook package: `pip install pre-commit`
2) Run hook installation: `pre-commit install`
### Build package
##### Building source distribution
1) Run: `python setup.py sdist`
##### Building wheel
1) Install wheel package: `pip install wheel`
2) Run: `python setup.py sdist`

##### Building package distribution
1) Install build package: `pip install build`
2) Run: `python -m build`
##### Releasing a new version
1) Add version tag: `git tag VERSION (e.g. 0.1.0)`
2) Push to remote: `git push origin VERSION`
2 changes: 1 addition & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ steps:
displayName: 'Run flake8'
- script: |
py.test --cov-report=xml --cov=swimai test/
py.test --cov-report=xml --cov=swimos test/
displayName: 'Run pytest'
- template: azure-code-coverage.yml
Expand Down
4 changes: 2 additions & 2 deletions examples/client_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
# Setting the value of a value lane on a remote agent.
import time

from swimai import SwimClient
from swimai.structures import Num
from swimos import SwimClient
from swimos.structures import Num


async def custom_on_event_callback(event):
Expand Down
4 changes: 2 additions & 2 deletions examples/cookbook/command_lanes.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

import time

from swimai import SwimClient
from swimai.structures import Num
from swimos import SwimClient
from swimos.structures import Num


async def custom_on_event(event):
Expand Down
2 changes: 1 addition & 1 deletion examples/cookbook/downlinks.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

import random
import time
from swimai import SwimClient
from swimos import SwimClient

if __name__ == '__main__':
with SwimClient() as swim_client:
Expand Down
2 changes: 1 addition & 1 deletion examples/cookbook/join_map_lane.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.

import time
from swimai import SwimClient
from swimos import SwimClient

THRESHOLD = 1000

Expand Down
4 changes: 2 additions & 2 deletions examples/cookbook/join_value_lanes.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
# limitations under the License.

import time
from swimai import SwimClient
from swimai.structures import Value
from swimos import SwimClient
from swimos.structures import Value


async def custom_did_update(key, new_value, old_value):
Expand Down
2 changes: 1 addition & 1 deletion examples/cookbook/map_lanes.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.

import time
from swimai import SwimClient
from swimos import SwimClient


async def custom_did_update(key, new_value, old_value):
Expand Down
4 changes: 2 additions & 2 deletions examples/cookbook/timers.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

import time

from swimai import SwimClient
from swimai.structures import Value
from swimos import SwimClient
from swimos.structures import Value

if __name__ == '__main__':
with SwimClient() as swim_client:
Expand Down
2 changes: 1 addition & 1 deletion examples/cookbook/value_lanes.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.

import time
from swimai import SwimClient
from swimos import SwimClient


async def custom_did_set(new_value, old_value):
Expand Down
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[build-system]
requires = ["setuptools>=45", "setuptools_scm[toml]>=6.2"]
build-backend = "setuptools.build_meta"

[tool.setuptools_scm]
3 changes: 2 additions & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ coverage
flake8
wheel
setuptools
pre-commit
pre-commit
build
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
requirements = f.read().splitlines()

setuptools.setup(
name='swimai',
version='1.2.0-alpha',
name='swimos',
version='1.3.0-alpha',
author='Dobromir Marinov',
author_email='dobromir@swim.it',
description='Standalone Python framework for building massively real-time streaming WARP clients.',
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import websockets

from enum import Enum
from swimai.warp._warp import _Envelope
from swimos.warp._warp import _Envelope
from typing import TYPE_CHECKING, Any

if TYPE_CHECKING:
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
from collections.abc import Callable
from abc import abstractmethod, ABC
from typing import TYPE_CHECKING, Any
from swimai.recon import Recon
from swimai.structures import Value, RecordConverter
from swimai.warp._warp import _SyncRequest, _CommandMessage, _Envelope, _LinkRequest
from swimos.recon import Recon
from swimos.structures import Value, RecordConverter
from swimos.warp._warp import _SyncRequest, _CommandMessage, _Envelope, _LinkRequest
from .._utils import _URI
from ._utils import before_open, UpdateRequest, RemoveRequest, after_open, validate_callback

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
import sys
from abc import ABC, abstractmethod
from typing import Any, Callable
from swimai.structures import RecordMap, Slot, Text, RecordConverter, Attr
from swimai.structures._structs import _Item, _Record
from swimos.structures import RecordMap, Slot, Text, RecordConverter, Attr
from swimos.structures._structs import _Item, _Record


def before_open(function: 'Callable') -> 'Callable':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
from ._connections import _ConnectionPool, _WSConnection
from ._downlinks._downlinks import _ValueDownlinkView, _EventDownlinkView, _DownlinkView, _MapDownlinkView
from ._utils import _URI, after_started
from swimai.structures import RecordConverter
from swimai.warp._warp import _CommandMessage
from swimos.structures import RecordConverter
from swimos.warp._warp import _CommandMessage


class SwimClient:
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions swimai/recon/_parsers.py → swimos/recon/_parsers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
from typing import Union, Any

from ._utils import _ReconUtils, _InputMessage, _OutputMessage
from swimai.structures import Text, Bool, Attr, Value, Slot, Num, RecordMap
from swimai.structures._structs import _Item, _Record, _ValueBuilder
from swimos.structures import Text, Bool, Attr, Value, Slot, Num, RecordMap
from swimos.structures._structs import _Item, _Record, _ValueBuilder


class _ReconParser:
Expand Down
2 changes: 1 addition & 1 deletion swimai/recon/_recon.py → swimos/recon/_recon.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

from swimai.structures._structs import Value
from swimos.structures._structs import Value
from ._parsers import _ReconParser
from ._writers import _ReconWriter

Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions swimai/recon/_writers.py → swimos/recon/_writers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
from typing import Union, List, Optional

from ._utils import _ReconUtils, _OutputMessage
from swimai.structures import Attr, Slot, Value, Text, Num, Bool
from swimai.structures._structs import _Absent, _Item, _Extant, _Record
from swimos.structures import Attr, Slot, Value, Text, Num, Bool
from swimos.structures._structs import _Absent, _Item, _Extant, _Record


class _ReconWriter:
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions swimai/warp/_warp.py → swimos/warp/_warp.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
import math
from abc import ABC, abstractmethod
from typing import Optional
from swimai.recon import Recon
from swimai.structures import Attr, Value, Num, RecordMap
from swimai.structures._structs import _Record, _Item
from swimos.recon import Recon
from swimos.structures import Attr, Value, Num, RecordMap
from swimos.structures._structs import _Record, _Item


class _Envelope(ABC):
Expand Down
8 changes: 4 additions & 4 deletions test/client/downlinks/test_downlink_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@

from aiounittest import async_test

from swimai import SwimClient
from swimai.client._downlinks._downlinks import _EventDownlinkView, _ValueDownlinkView
from swimai.client._downlinks._utils import UpdateRequest, RemoveRequest, convert_to_async, validate_callback
from swimai.structures import RecordMap, Slot, Num, Attr, Value
from swimos import SwimClient
from swimos.client._downlinks._downlinks import _EventDownlinkView, _ValueDownlinkView
from swimos.client._downlinks._utils import UpdateRequest, RemoveRequest, convert_to_async, validate_callback
from swimos.structures import RecordMap, Slot, Num, Attr, Value
from test.utils import MockPerson, mock_func, mock_coro


Expand Down
26 changes: 13 additions & 13 deletions test/client/downlinks/test_downlinks.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@
from concurrent.futures import Future
from unittest.mock import patch

from swimai import SwimClient
from swimai.client._connections import _DownlinkManager, _DownlinkManagerStatus
from swimai.client._downlinks._downlinks import _EventDownlinkModel, _DownlinkModel, _ValueDownlinkModel, \
from swimos import SwimClient
from swimos.client._connections import _DownlinkManager, _DownlinkManagerStatus
from swimos.client._downlinks._downlinks import _EventDownlinkModel, _DownlinkModel, _ValueDownlinkModel, \
_EventDownlinkView, \
_DownlinkView, _ValueDownlinkView, _MapDownlinkModel, _MapDownlinkView
from swimai.client._downlinks._utils import UpdateRequest, RemoveRequest
from swimai.structures import Text, Attr, RecordMap, Num, Bool, Slot, Value
from swimai.structures._structs import _Absent, _Record
from swimai.warp._warp import _LinkedResponse, _SyncedResponse, _EventMessage, _UnlinkedResponse
from swimos.client._downlinks._utils import UpdateRequest, RemoveRequest
from swimos.structures import Text, Attr, RecordMap, Num, Bool, Slot, Value
from swimos.structures._structs import _Absent, _Record
from swimos.warp._warp import _LinkedResponse, _SyncedResponse, _EventMessage, _UnlinkedResponse
from test.utils import MockConnection, MockExecuteOnException, MockWebsocketConnect, MockWebsocket, \
mock_did_set_confirmation, ReceiveLoop, MockPerson, MockPet, NewScope, MockNoDefaultConstructor, MockCar, \
MockModel, MockDownlinkManager, mock_on_event_callback, MockEventCallback, \
Expand Down Expand Up @@ -65,7 +65,7 @@ async def test_open_downlink_model(self):
self.assertEqual(downlink, actual)
self.assertIsInstance(actual.task, Future)

@patch('swimai.client._connections._DownlinkManager._close_views')
@patch('swimos.client._connections._DownlinkManager._close_views')
async def test_close_downlink_model_with_manager(self, mock_close_views):
# Given
with SwimClient() as client:
Expand All @@ -87,7 +87,7 @@ async def test_close_downlink_model_with_manager(self, mock_close_views):
self.assertTrue(actual.task.cancelled())
self.assertTrue(mock_close_views.called)

@patch('swimai.client._connections._DownlinkManager._close_views')
@patch('swimos.client._connections._DownlinkManager._close_views')
async def test_close_downlink_model_without_manager(self, mock_close_views):
# Given
with SwimClient() as client:
Expand Down Expand Up @@ -1062,7 +1062,7 @@ async def test_event_downlink_view_execute_on_event_missing_callback(self):
downlink_view = _EventDownlinkView(client)
event = 20
# When
with patch('swimai.SwimClient._schedule_task') as mock_schedule_task:
with patch('swimos.SwimClient._schedule_task') as mock_schedule_task:
await downlink_view._execute_on_event(event)

# Then
Expand Down Expand Up @@ -1503,7 +1503,7 @@ async def test_value_downlink_view_execute_did_set_no_callback(self):
new_value = 'Test_new_value'
old_value = 'Test_old_value'
# When
with patch('swimai.SwimClient._schedule_task') as mock_schedule_task:
with patch('swimos.SwimClient._schedule_task') as mock_schedule_task:
await downlink_view._execute_did_set(new_value, old_value)

# Then
Expand Down Expand Up @@ -2256,7 +2256,7 @@ async def test_map_downlink_view_execute_did_update_no_callback(self):
new_value = 'Test_update_new_value'
old_value = 'Test_update_old_value'
# When
with patch('swimai.SwimClient._schedule_task') as mock_schedule_task:
with patch('swimos.SwimClient._schedule_task') as mock_schedule_task:
await downlink_view._execute_did_update(key, new_value, old_value)

# Then
Expand Down Expand Up @@ -2285,7 +2285,7 @@ async def test_map_downlink_view_execute_did_remove_no_callback(self):
key = 'Test_remove_key'
value = 'Test_remove_value'
# When
with patch('swimai.SwimClient._schedule_task') as mock_schedule_task:
with patch('swimos.SwimClient._schedule_task') as mock_schedule_task:
await downlink_view._execute_did_remove(key, value)

# Then
Expand Down
Loading

0 comments on commit 49158d8

Please sign in to comment.