Skip to content

Commit

Permalink
Change ypy-websocket to pycrdt-websocket
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbrochart committed Dec 8, 2023
1 parent 4caf8aa commit 39a882c
Show file tree
Hide file tree
Showing 32 changed files with 61 additions and 68 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ jobs:
uses: mamba-org/provision-with-micromamba@main
with:
environment-file: environment-dev.yml
environment-name: ypy-websocket
environment-name: pycrdt-websocket
extra-specs: python=${{ matrix.python-version }}
- name: Install dependencies
run: |
pip install .[test]
cd tests; npm install
- name: Check types
run: |
mypy ypy_websocket tests
mypy pycrdt_websocket tests
- name: Run tests
run: |
pytest -v
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,5 @@ dmypy.json
# test JS dependencies
tests/node_modules
tests/package-lock.json
# pixi environments
.pixi
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
# Ypy-websocket
# Pycrdt-websocket

Ypy-websocket is an async WebSocket connector for Ypy.
Pycrdt-websocket is an async WebSocket connector for pycrdt.

[![Build Status](https://github.com/y-crdt/ypy-websocket/workflows/CI/badge.svg)](https://github.com/y-crdt/ypy-websocket/actions)
[![Build Status](https://github.com/davidbrochart/pycrdt-websocket/workflows/CI/badge.svg)](https://github.com/davidbrochart/pycrdt-websocket/actions)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)

---

**Documentation**: <a href="https://davidbrochart.github.io/ypy-websocket" target="_blank">https://davidbrochart.github.io/ypy-websocket</a>
**Documentation**: <a href="https://davidbrochart.github.io/pycrdt-websocket" target="_blank">https://davidbrochart.github.io/pycrdt-websocket</a>

**Source Code**: <a href="https://github.com/y-crdt/ypy-websocket" target="_blank">https://github.com/y-crdt/ypy-websocket</a>
**Source Code**: <a href="https://github.com/davidbrochart/pycrdt-websocket" target="_blank">https://github.com/davidbrochart/pycrdt-websocket</a>

---

Ypy-websocket is a Python library for building WebSocket servers and clients that connect and synchronize shared documents.
Pycrdt-websocket is a Python library for building WebSocket servers and clients that connect and synchronize shared documents.
It can be used to create collaborative web applications.

The following diagram illustrates a typical architecture. The goal is to share a document among several clients.
Expand Down
2 changes: 1 addition & 1 deletion RELEASE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Making a ypy-websocket release
# Making a pycrdt-websocket release

## Using `jupyter_releaser`

Expand Down
6 changes: 3 additions & 3 deletions docs/install.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
Ypy-websocket can be installed from [PyPI](https://pypi.org) using `pip` or from [conda-forge](https://conda-forge.org) using `micromamba`.
Pycrdt-websocket can be installed from [PyPI](https://pypi.org) using `pip` or from [conda-forge](https://conda-forge.org) using `micromamba`.

## With `pip`

```console
pip install ypy-websocket
pip install pycrdt-websocket
```

## With `micromamba`

```console
micromamba install -c conda-forge ypy-websocket
micromamba install -c conda-forge pycrdt-websocket
```
2 changes: 1 addition & 1 deletion docs/reference/ASGI_server.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
::: ypy_websocket.asgi_server.ASGIServer
::: pycrdt_websocket.asgi_server.ASGIServer
2 changes: 1 addition & 1 deletion docs/reference/Django_Channels_consumer.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
::: ypy_websocket.django_channels_consumer.YjsConsumer
::: pycrdt_websocket.django_channels_consumer.YjsConsumer
2 changes: 1 addition & 1 deletion docs/reference/Room.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
::: ypy_websocket.yroom.YRoom
::: pycrdt_websocket.yroom.YRoom
8 changes: 4 additions & 4 deletions docs/reference/Store.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
## BaseYStore

::: ypy_websocket.ystore.BaseYStore
::: pycrdt_websocket.ystore.BaseYStore

## FileYStore

::: ypy_websocket.ystore.FileYStore
::: pycrdt_websocket.ystore.FileYStore

## TempFileYStore

::: ypy_websocket.ystore.TempFileYStore
::: pycrdt_websocket.ystore.TempFileYStore

## SQLiteYStore

::: ypy_websocket.ystore.SQLiteYStore
::: pycrdt_websocket.ystore.SQLiteYStore
2 changes: 1 addition & 1 deletion docs/reference/WebSocket.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
::: ypy_websocket.websocket.Websocket
::: pycrdt_websocket.websocket.Websocket
2 changes: 1 addition & 1 deletion docs/reference/WebSocket_provider.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
::: ypy_websocket.websocket_provider.WebsocketProvider
::: pycrdt_websocket.websocket_provider.WebsocketProvider
2 changes: 1 addition & 1 deletion docs/reference/WebSocket_server.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
::: ypy_websocket.websocket_server.WebsocketServer
::: pycrdt_websocket.websocket_server.WebsocketServer
2 changes: 1 addition & 1 deletion docs/usage/client.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Here is a code example using the [websockets](https://websockets.readthedocs.io)
import asyncio
import y_py as Y
from websockets import connect
from ypy_websocket import WebsocketProvider
from pycrdt_websocket import WebsocketProvider

async def client():
ydoc = Y.YDoc()
Expand Down
6 changes: 3 additions & 3 deletions docs/usage/server.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Here is a code example using the [websockets](https://websockets.readthedocs.io)
```py
import asyncio
from websockets import serve
from ypy_websocket import WebsocketServer
from pycrdt_websocket import WebsocketServer

async def server():
async with (
Expand All @@ -15,12 +15,12 @@ async def server():

asyncio.run(server())
```
Ypy-websocket can also be used with an [ASGI](https://asgi.readthedocs.io) server. Here is a code example using [Uvicorn](https://www.uvicorn.org):
Pycrdt-websocket can also be used with an [ASGI](https://asgi.readthedocs.io) server. Here is a code example using [Uvicorn](https://www.uvicorn.org):
```py
# main.py
import asyncio
import uvicorn
from ypy_websocket import ASGIServer, WebsocketServer
from pycrdt_websocket import ASGIServer, WebsocketServer

websocket_server = WebsocketServer()
app = ASGIServer(websocket_server)
Expand Down
2 changes: 1 addition & 1 deletion environment-dev.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: ypy-websocket
name: pycrdt-websocket
channels:
- conda-forge
dependencies:
Expand Down
6 changes: 3 additions & 3 deletions mkdocs.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
site_name: ypy-websocket
site_description: Async WebSocket connector for Ypy
repo_url: https://github.com/y-crdt/ypy-websocket
site_name: pycrdt-websocket
site_description: Async WebSocket connector for pycrdt
repo_url: https://github.com/davidbrochart/pycrdt-websocket

theme:
name: 'material'
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 @@ -82,8 +82,8 @@ class YjsConsumer(AsyncWebsocketConsumer):
from pycrdt import Doc
from asgiref.sync import async_to_sync
from channels.layers import get_channel_layer
from ypy_websocket.django_channels_consumer import YjsConsumer
from ypy_websocket.yutils import create_update_message
from pycrdt_websocket.django_channels_consumer import YjsConsumer
from pycrdt_websocket.yutils import create_update_message
class DocConsumer(YjsConsumer):
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 1 addition & 2 deletions ypy_websocket/yutils.py → pycrdt_websocket/yutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def read_var_string(self):

def put_updates(update_send_stream: MemoryObjectSendStream, event: TransactionEvent) -> None:
try:
update = event.get_update() # type: ignore
update = event.update # type: ignore
update_send_stream.send_nowait(update)
except Exception:
pass
Expand Down Expand Up @@ -128,7 +128,6 @@ async def process_sync_message(message: bytes, ydoc: Doc, websocket, log) -> Non
YSyncMessageType.SYNC_UPDATE,
):
update = read_message(msg)
# Ignore empty updates (see https://github.com/y-crdt/ypy/issues/98)
if update != b"\x00\x00":
ydoc.apply_update(update)

Expand Down
23 changes: 11 additions & 12 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "ypy-websocket"
name = "pycrdt-websocket"
dynamic = ["version"]
description = "WebSocket connector for Ypy"
description = "WebSocket connector for pycrdt"
license = { file = "LICENSE" }
readme = "README.md"
requires-python = ">=3.7"
requires-python = ">=3.8"
authors = [
{ name = "David Brochart", email = "[email protected]" },
]
Expand All @@ -21,17 +21,16 @@ classifiers = [
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
]
dependencies = [
"anyio >=3.6.2,<5",
"aiosqlite >=0.18.0,<1",
"pycrdt >=0.4.1,<0.5.0",
"typing_extensions; python_version < '3.8'",
"pycrdt >=0.7.0,<0.8.0",
]

[project.optional-dependencies]
Expand All @@ -53,17 +52,17 @@ django = [
]

[project.urls]
Homepage = "https://github.com/y-crdt/ypy-websocket"
Source = "https://github.com/y-crdt/ypy-websocket"
Issues = "https://github.com/y-crdt/ypy-websocket/issues"
Pypi = "https://pypi.org/project/ypy-websocket"
Homepage = "https://github.com/davidbrochart/pycrdt-websocket"
Source = "https://github.com/davidbrochart/pycrdt-websocket"
Issues = "https://github.com/davidbrochart/pycrdt-websocket/issues"
Pypi = "https://pypi.org/project/pycrdt-websocket"

[tool.hatch.version]
path = "ypy_websocket/__init__.py"
path = "pycrdt_websocket/__init__.py"

[tool.hatch.build.targets.sdist]
include = [
"/ypy_websocket",
"/pycrdt_websocket",
"/tests",
]

Expand Down
5 changes: 2 additions & 3 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
from pycrdt import Array, Doc
from websockets import serve # type: ignore

from ypy_websocket import WebsocketServer
from pycrdt_websocket import WebsocketServer


class TestYDoc:
def __init__(self):
self.ydoc = Doc()
self.array = Array()
self.ydoc["array"] = self.array
self.ydoc["array"] = self.array = Array()
self.state = None
self.value = 0

Expand Down
8 changes: 3 additions & 5 deletions tests/test_asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from pycrdt import Doc, Map
from websockets import connect # type: ignore

from ypy_websocket import ASGIServer, WebsocketProvider, WebsocketServer
from pycrdt_websocket import ASGIServer, WebsocketProvider, WebsocketServer

websocket_server = WebsocketServer(auto_clean_rooms=False)
app = ASGIServer(websocket_server)
Expand All @@ -23,8 +23,7 @@ async def test_asgi(unused_tcp_port):
# clients
# client 1
ydoc1 = Doc()
ymap1 = Map()
ydoc1["map"] = ymap1
ydoc1["map"] = ymap1 = Map()
ymap1["key"] = "value"
async with connect(
f"ws://localhost:{unused_tcp_port}/my-roomname" # noqa
Expand All @@ -38,8 +37,7 @@ async def test_asgi(unused_tcp_port):
) as websocket2, WebsocketProvider(ydoc2, websocket2):
await sleep(0.1)

ymap2 = Map()
ydoc2["map"] = ymap2
ydoc2["map"] = ymap2 = Map()
assert str(ymap2) == '{"key":"value"}'

tg.cancel_scope.cancel()
22 changes: 9 additions & 13 deletions tests/test_ypy_yjs.py → tests/test_pycrdt_yjs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@
from pycrdt import Array, Doc, Map
from websockets import connect # type: ignore

from ypy_websocket import WebsocketProvider
from pycrdt_websocket import WebsocketProvider


class YTest:
def __init__(self, ydoc: Doc, timeout: float = 1.0):
self.ydoc = ydoc
self.timeout = timeout
self.ytest = Map()
self.ydoc["_test"] = self.ytest
self.ydoc["_test"] = self.ytest = Map()
self.clock = -1.0

def run_clock(self):
Expand All @@ -40,14 +39,13 @@ def callback(event):

@pytest.mark.anyio
@pytest.mark.parametrize("yjs_client", "0", indirect=True)
async def test_ypy_yjs_0(yws_server, yjs_client):
async def test_pycrdt_yjs_0(yws_server, yjs_client):
ydoc = Doc()
ytest = YTest(ydoc)
async with connect("ws://127.0.0.1:1234/my-roomname") as websocket, WebsocketProvider(
ydoc, websocket
):
ymap = Map()
ydoc["map"] = ymap
ydoc["map"] = ymap = Map()
# set a value in "in"
for v_in in range(10):
ymap["in"] = float(v_in)
Expand All @@ -59,7 +57,7 @@ async def test_ypy_yjs_0(yws_server, yjs_client):

@pytest.mark.anyio
@pytest.mark.parametrize("yjs_client", "1", indirect=True)
async def test_ypy_yjs_1(yws_server, yjs_client):
async def test_pycrdt_yjs_1(yws_server, yjs_client):
# wait for the JS client to connect
tt, dt = 0, 0.1
while True:
Expand All @@ -73,9 +71,7 @@ async def test_ypy_yjs_1(yws_server, yjs_client):
ytest = YTest(ydoc)
ytest.run_clock()
await ytest.clock_run()
ycells = Array()
ystate = Map()
ydoc["cells"] = ycells
ydoc["state"] = ystate
assert json.loads(str(ycells)) == [{"metadata": {"foo": "bar"}, "source": "1 + 2"}]
assert json.loads(str(ystate)) == {"state": {"dirty": False}}
ydoc["cells"] = ycells = Array()
ydoc["state"] = ystate = Map()
assert list(ycells) == [{"metadata": {"foo": "bar"}, "source": "1 + 2"}]
assert dict(ystate) == {"state": {"dirty": False}}
2 changes: 1 addition & 1 deletion tests/test_ystore.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import aiosqlite
import pytest

from ypy_websocket.ystore import SQLiteYStore, TempFileYStore
from pycrdt_websocket.ystore import SQLiteYStore, TempFileYStore


class MetadataCallback:
Expand Down

0 comments on commit 39a882c

Please sign in to comment.