Skip to content

Commit 4d015bd

Browse files
committed
linting/workflows
1 parent ab8e326 commit 4d015bd

File tree

8 files changed

+92
-25
lines changed

8 files changed

+92
-25
lines changed

.github/workflows/ci.yml

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: CI
2+
3+
on:
4+
pull_request:
5+
6+
jobs:
7+
ci:
8+
runs-on: ${{ matrix.os }}-latest
9+
strategy:
10+
matrix:
11+
python-version: [ '3.8', '3.9', '3.10' ]
12+
os: [ ubuntu, windows ]
13+
14+
name: ${{ matrix.python-version }} ${{ matrix.os }}
15+
steps:
16+
- uses: actions/checkout@v2
17+
- name: Set up Python
18+
uses: actions/setup-python@v2
19+
with:
20+
python-version: ${{ matrix.python-version }}
21+
- name: Install Nox
22+
run: pip install nox
23+
- name: Run Nox
24+
run: nox

.github/workflows/pypi.yml

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: pypi
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- uses: actions/checkout@v3
12+
- name: Set up Python
13+
uses: actions/setup-python@v3
14+
with:
15+
python-version: '3.8'
16+
- name: Install Dependencies
17+
run: pip install poetry
18+
- name: Build & Upload
19+
env:
20+
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
21+
run: |
22+
poetry config pypi-token.pypi $PYPI_TOKEN
23+
poetry version $(git describe --tags --abbrev=0)
24+
poetry build
25+
poetry publish

example/client.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
from socketapp import Client
55

66

7-
async def send(client: Client):
7+
async def send(client: Client) -> None:
88
while True:
99
await asyncio.sleep(5)
1010
await client.send(Message(data="hi"), client.clients)
1111

1212

13-
async def main(client: Client):
13+
async def main(client: Client) -> None:
1414
asyncio.create_task(send(client))
1515
await client.run()
1616

noxfile.py

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import nox
2+
3+
4+
@nox.session
5+
def mypy(session: nox.Session) -> None:
6+
session.install("poetry")
7+
session.run("poetry", "install")
8+
9+
session.run("mypy", ".")
10+
11+
12+
@nox.session
13+
def black(session: nox.Session) -> None:
14+
session.install("black")
15+
session.run("black", ".", "--check")
16+
17+
18+
@nox.session
19+
def ruff(session: nox.Session) -> None:
20+
session.install("ruff")
21+
session.run("ruff", ".")

pyproject.toml

+14-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ python = "^3.8"
1111
websockets = "^10.4"
1212
pydantic = "^1.10.2"
1313

14-
1514
[tool.poetry.group.dev.dependencies]
1615
ruff = "^0.0.168"
1716
nox = "^2022.11.21"
@@ -21,3 +20,17 @@ mypy = "^0.991"
2120
[build-system]
2221
requires = ["poetry-core"]
2322
build-backend = "poetry.core.masonry.api"
23+
24+
[tool.mypy]
25+
warn_return_any=true
26+
warn_unused_configs=true
27+
strict=true
28+
29+
[tool.black]
30+
skip-magic-trailing-comma=true
31+
32+
[tool.ruff]
33+
extend-select = [
34+
# isort
35+
"I001"
36+
]

socketapp/client.py

+3-11
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@
1515

1616
class Client:
1717
def __init__(
18-
self,
19-
host: str = "localhost",
20-
port: int = 5000,
21-
password: str | None = None,
18+
self, host: str = "localhost", port: int = 5000, password: str | None = None
2219
) -> None:
2320
self.host = host
2421
self.port = port
@@ -61,17 +58,12 @@ async def send(self, event: Event, to: t.Collection[int]) -> None:
6158
if not await event.process_client(self, self.client_id):
6259
return
6360

64-
raw = json.dumps(
65-
{
66-
"to": list(to),
67-
"event": event.to_dict(),
68-
}
69-
)
61+
raw = json.dumps({"to": list(to), "event": event.to_dict()})
7062
await self.ws.send(raw)
7163

7264
async def _handshake(self, ws: WebSocketClientProtocol) -> int:
7365
await ws.send(json.dumps({"password": self.password}))
74-
return json.loads(await ws.recv())["client_id"]
66+
return int(json.loads(await ws.recv())["client_id"])
7567

7668
async def _process_messages(self, ws: WebSocketClientProtocol) -> None:
7769
try:

socketapp/event.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def to_dict(self) -> dict[str, t.Any]:
3333
dct["cls_id"] = self.event_id
3434
return dct
3535

36-
def to_json(self) -> str: # type: ignore
36+
def to_json(self) -> str:
3737
return json.dumps(self.to_dict())
3838

3939
@staticmethod

socketapp/server.py

+2-10
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,7 @@
1515

1616
class Server:
1717
def __init__(
18-
self,
19-
host: str = "localhost",
20-
port: int = 5000,
21-
password: str | None = None,
18+
self, host: str = "localhost", port: int = 5000, password: str | None = None
2219
) -> None:
2320
self.host = host
2421
self.port = port
@@ -106,12 +103,7 @@ async def _process_msg(self, msg: str | bytes, client_id: int) -> None:
106103
if not ret:
107104
return
108105

109-
to_send = json.dumps(
110-
{
111-
"author_id": client_id,
112-
"event": event.to_dict(),
113-
}
114-
)
106+
to_send = json.dumps({"author_id": client_id, "event": event.to_dict()})
115107

116108
await asyncio.gather(
117109
*(ws.send(to_send) for (cid, ws) in self.clients.items() if cid in to),

0 commit comments

Comments
 (0)