Skip to content

Commit 94b9baf

Browse files
committed
moved library to subfolder and add setup config
1 parent 4898040 commit 94b9baf

File tree

16 files changed

+269
-1
lines changed

16 files changed

+269
-1
lines changed

.gitignore

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
share/python-wheels/
24+
*.egg-info/
25+
.installed.cfg
26+
*.egg
27+
MANIFEST
28+
29+
# PyInstaller
30+
# Usually these files are written by a python script from a template
31+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
32+
*.manifest
33+
*.spec
34+
35+
# Installer logs
36+
pip-log.txt
37+
pip-delete-this-directory.txt
38+
39+
# Unit test / coverage reports
40+
htmlcov/
41+
.tox/
42+
.nox/
43+
.coverage
44+
.coverage.*
45+
.cache
46+
nosetests.xml
47+
coverage.xml
48+
*.cover
49+
*.py,cover
50+
.hypothesis/
51+
.pytest_cache/
52+
cover/
53+
54+
# Translations
55+
*.mo
56+
*.pot
57+
58+
# Django stuff:
59+
*.log
60+
local_settings.py
61+
db.sqlite3
62+
db.sqlite3-journal
63+
64+
# Flask stuff:
65+
instance/
66+
.webassets-cache
67+
68+
# Scrapy stuff:
69+
.scrapy
70+
71+
# Sphinx documentation
72+
docs/_build/
73+
74+
# PyBuilder
75+
.pybuilder/
76+
target/
77+
78+
# Jupyter Notebook
79+
.ipynb_checkpoints
80+
81+
# IPython
82+
profile_default/
83+
ipython_config.py
84+
85+
# pyenv
86+
# For a library or package, you might want to ignore these files since the code is
87+
# intended to run in multiple environments; otherwise, check them in:
88+
# .python-version
89+
90+
# pipenv
91+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
93+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
94+
# install all needed dependencies.
95+
#Pipfile.lock
96+
97+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
98+
__pypackages__/
99+
100+
# Celery stuff
101+
celerybeat-schedule
102+
celerybeat.pid
103+
104+
# SageMath parsed files
105+
*.sage.py
106+
107+
# Environments
108+
.env
109+
.venv
110+
env/
111+
venv/
112+
ENV/
113+
env.bak/
114+
venv.bak/
115+
116+
# Spyder project settings
117+
.spyderproject
118+
.spyproject
119+
120+
# Rope project settings
121+
.ropeproject
122+
123+
# mkdocs documentation
124+
/site
125+
126+
# mypy
127+
.mypy_cache/
128+
.dmypy.json
129+
dmypy.json
130+
131+
# Pyre type checker
132+
.pyre/
133+
134+
# pytype static type analyzer
135+
.pytype/
136+
137+
# Cython debug symbols
138+
cython_debug/

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,16 @@ It supports distributed properties, asynchronous method invokation as also serve
66

77
It is designed to wort together with ApiGear Object Model to generate complete client and server side APIs.
88

9+
# Install for testing
10+
11+
This will install the package as editable python package, which can be used for local development.
12+
13+
```
14+
pip install -e .
15+
```
16+
17+
# Publish package
18+
19+
TBD
920

1021

examples/server.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
from starlette.websockets import WebSocket
88

99
from olink.core.types import Name
10-
from olink.net.server import RemoteEndpoint
1110
from olink.remotenode import IObjectSource, RemoteNode
1211

1312

pyproject.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[build-system]
2+
requires = [
3+
"setuptools>=42",
4+
"wheel"
5+
]
6+
build-backend = "setuptools.build_meta"

server.py

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import asyncio
2+
from typing import Any
3+
from asyncio.queues import Queue
4+
from starlette.applications import Starlette
5+
from starlette.endpoints import WebSocketEndpoint
6+
from starlette.routing import WebSocketRoute
7+
from starlette.websockets import WebSocket
8+
9+
from olink.core.types import Name
10+
from olink.remotenode import IObjectSource, RemoteNode
11+
12+
13+
class Counter:
14+
count = 0
15+
_node: RemoteNode
16+
def increment(self):
17+
self.count += 1
18+
self._node.notify_property_change('demo.Counter/count', self.count)
19+
20+
class CounterAdapter(IObjectSource):
21+
node: RemoteNode = None
22+
def __init__(self, impl):
23+
self.impl = impl
24+
RemoteNode.add_object_source(self)
25+
26+
def olink_object_name(self):
27+
return 'demo.Counter'
28+
29+
def olink_invoke(self, name: str, args: list[Any]) -> Any:
30+
path = Name.path_from_name(name)
31+
func = getattr(self.impl, path)
32+
func()
33+
34+
def olink_set_property(self, name: str, value: Any):
35+
path = Name.path_from_name(name)
36+
setattr(self, self.impl, value)
37+
38+
def olink_linked(self, name: str, node: "RemoteNode"):
39+
self.impl._node = node
40+
41+
def olink_collect_properties(self) -> object:
42+
return {k: getattr(self.impl, k) for k in ['count']}
43+
44+
counter = Counter()
45+
adapter = CounterAdapter(counter)
46+
47+
48+
49+
50+
class RemoteEndpoint(WebSocketEndpoint):
51+
encoding = "text"
52+
node = RemoteNode()
53+
queue = Queue()
54+
55+
async def sender(self, ws):
56+
print('start sender')
57+
while True:
58+
print('001')
59+
msg = await self.queue.get()
60+
print('send', msg)
61+
await ws.send_text(msg)
62+
self.queue.task_done()
63+
64+
async def on_connect(self, ws: WebSocket):
65+
print('on_connect')
66+
asyncio.create_task(self.sender(ws))
67+
68+
def writer(msg: str):
69+
print('writer', msg)
70+
self.queue.put_nowait(msg)
71+
self.node.on_write(writer)
72+
await super().on_connect(ws)
73+
74+
75+
async def on_receive(self, ws: WebSocket, data: Any) -> None:
76+
print('on_receive', data)
77+
self.node.handle_message(data)
78+
79+
async def on_disconnect(self, websocket: WebSocket, close_code: int) -> None:
80+
await super().on_disconnect(websocket, close_code)
81+
self.node.on_write(None)
82+
await self.queue.join()
83+
84+
85+
86+
routes = [
87+
WebSocketRoute("/ws", RemoteEndpoint)
88+
]
89+
90+
app = Starlette(routes=routes)

setup.cfg

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[metadata]
2+
name = olink-core
3+
version = 0.0.1
4+
author = AppiGear
5+
author_email = [email protected]
6+
description = ObjectLink Core Protocol
7+
long_description = file: README.md
8+
long_description_content_type = text/markdown
9+
url = https://github.com/apigear-io/objectlink-core-python
10+
project_urls =
11+
Bug Tracker = https://github.com/apigear-io/objectlink-core-python/issues
12+
classifiers =
13+
Programming Language :: Python :: 3
14+
License :: OSI Approved :: MIT License
15+
Operating System :: OS Independent
16+
17+
[options]
18+
package_dir =
19+
= src
20+
packages = find:
21+
python_requires = >=3.6
22+
23+
[options.packages.find]
24+
where = src
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)