Skip to content

Commit

Permalink
Merge pull request #17 from icgood/source
Browse files Browse the repository at this point in the history
Typed dataclass source instead of tuple
  • Loading branch information
icgood committed Jan 22, 2022
2 parents 6f2cd3d + f6e9b9b commit 7da7756
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 19 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [3.9]
python-version: ['3.9', '3.10']

steps:
- uses: actions/checkout@v2
Expand Down Expand Up @@ -50,7 +50,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.9'
python-version: '3.10'
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools wheel
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/python-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.9'
python-version: '3.10'
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools wheel twine
Expand All @@ -35,7 +35,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.9'
python-version: '3.10'
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools wheel
Expand Down
3 changes: 1 addition & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,4 @@

napoleon_numpy_docstring = False

intersphinx_mapping = {'https://docs.python.org/3/': None,
'https://grpclib.readthedocs.io/en/latest/': None}
intersphinx_mapping = {'https://docs.python.org/3/': None}
2 changes: 2 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ pytest-asyncio
pytest-cov
rope

types-setuptools

-e '.'
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
files = swimprotocol, test
strict = true

[flake8]
exclude = swimprotocol/grpc/
[tool:pytest]
asyncio_mode = auto

[coverage:report]
omit = */main.py, */demo.py, */proto/*
Expand Down
9 changes: 5 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2021 Ian C. Good
# Copyright (c) 2022 Ian C. Good
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
Expand All @@ -19,7 +19,7 @@
# THE SOFTWARE.
#

from setuptools import setup, find_packages # type: ignore
from setuptools import setup, find_packages

with open('README.md') as f:
readme = f.read()
Expand All @@ -28,7 +28,7 @@
license = f.read()

setup(name='swim-protocol',
version='0.3.8',
version='0.3.9',
author='Ian Good',
author_email='ian@icgood.net',
description='SWIM protocol implementation for exchanging cluster '
Expand All @@ -43,7 +43,8 @@
'Intended Audience :: Information Technology',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python',
'Programming Language :: Python :: 3.9'],
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10'],
python_requires='~=3.9',
include_package_data=True,
packages=find_packages(),
Expand Down
5 changes: 3 additions & 2 deletions swimprotocol/members.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from .config import BaseConfig
from .listener import Listener
from .packet import Source
from .shuffle import Shuffle, WeakShuffle
from .status import Status

Expand Down Expand Up @@ -60,8 +61,8 @@ def __repr__(self) -> str:
return f'Member<{self.name} {self.status.name}>'

@property
def source(self) -> tuple[str, bytes]:
return self.name, self._validity
def source(self) -> Source:
return Source(self.name, self._validity)

@property
def clock(self) -> int:
Expand Down
19 changes: 16 additions & 3 deletions swimprotocol/packet.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,21 @@

from .status import Status

__all__ = ['Packet', 'Ping', 'PingReq', 'Ack', 'Gossip', 'GossipAck']
__all__ = ['Source', 'Packet', 'Ping', 'PingReq', 'Ack', 'Gossip', 'GossipAck']


@dataclass(frozen=True)
class Source:
"""Uniquely identifies the local cluster member that created the packet.
Args:
name: The name of the local cluster member.
validity: Random bytestring used to detect non-unique *name* values.
"""

name: str
validity: bytes


@dataclass(frozen=True)
Expand All @@ -23,7 +37,7 @@ class Packet:
"""

source: tuple[str, bytes]
source: Source


@dataclass(frozen=True)
Expand Down Expand Up @@ -54,7 +68,6 @@ class Ack(Packet):
that *source* is online.
"""

pass


Expand Down
2 changes: 1 addition & 1 deletion swimprotocol/transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class Transport(Generic[ConfigT_co], metaclass=ABCMeta):

#: The :class:`~swimprotocol.config.BaseConfig` sub-class used by this
#: transport.
config_type: ClassVar[type[ConfigT_co]]
config_type: ClassVar[type[BaseConfig]]

def __init__(self, config: ConfigT_co) -> None:
super().__init__()
Expand Down
3 changes: 2 additions & 1 deletion swimprotocol/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ async def _run_handler(self) -> NoReturn:
local = self.members.local
while True:
packet = await self.io.recv()
source = self.members.get(*packet.source)
source = self.members.get(packet.source.name,
packet.source.validity)
if isinstance(packet, Ping):
await self.io.send(source, Ack(source=local.source))
elif isinstance(packet, PingReq):
Expand Down

0 comments on commit 7da7756

Please sign in to comment.