Skip to content

Commit

Permalink
feat: make project ready packaged via PEP-517 compatible build tools (#…
Browse files Browse the repository at this point in the history
…11)

Signed-off-by: Christopher Arndt <[email protected]>
  • Loading branch information
SpotlightKid authored Nov 15, 2023
1 parent 1b7a24e commit efe979c
Show file tree
Hide file tree
Showing 12 changed files with 145 additions and 41 deletions.
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# MIT License

Copyright (c) 2015 - 2023 Christopher Arndt <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
44 changes: 25 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,30 +1,26 @@
Micropython-OSC
===============
# Micropython-OSC

Micropython-osc (aka `uosc`) is a minimal [Open Sound Control] \(OSC) client
and server library for [MicroPython] and CPython 2 or 3.
and server library for [MicroPython] and CPython.


Status / Supported Boards
-------------------------
## Status / Supported Boards

It should work on the Unix, stm32 (Pyboard) and esp8266 port of MicroPython
and under CPython 2.7 and 3.3+. Since OSC is a protocol commonly using an IP
network and UDP or TCP packets as a transport, the main requirement is a
working and compatible `socket` module. Currently this module only supports UDP
as the transport.
and under CPython 3.8+. Since OSC is a protocol commonly using an IP network
and UDP or TCP packets as a transport, the main requirement is a working and
compatible `socket` module. Currently this module only supports UDP as the
transport.

The server code so far has only been tested under the Unix port and CPython 2
and 3, but the client portion has been confirmed to work on a ESP-8266 board
running MicroPython 1.8.x.
The server code so far has only been tested under the Unix port and CPython,
but the client portion has been confirmed to work on a ESP-8266 board running
MicroPython 1.8.x.


Usage
-----
## Usage

Here's a minmal usage example for the client. Further documentation is
currently only available by looking at the docstrings and the source code (the
whole package has a total LLOC of < 400).
currently only available by looking at the docstrings and the source code.

from uosc.client import Bundle, Client, create_message

Expand All @@ -36,13 +32,12 @@ whole package has a total LLOC of < 400).
osc.send(b)


Examples
--------
## Examples

The [examples](./examples) directory contains some simple example scripts using
this library to implement special OSC clients or simple OSC UDP servers.

To use the server examples with the unix port of MicroPython, the following
To use the server examples with the unix port of MicroPython, the following
required modules from the [micropython-lib] are included in this directory:

* argparse
Expand All @@ -52,6 +47,17 @@ Either use the provided shell wrappers to run the server examples or install
these two modules to `~/.micropython/lib`.


## License

`micropython-osc` is Free and Open Source software and released under the MIT
license. For details see the file [LICENSE.md](./LICENSE.md).


## Author

`micropython-osc` is written by *Christopher Arndt* and was started in 2015.


[Open Sound Control]: http://opensoundcontrol.org
[MicroPython]: http://micropython.org
[micropython-lib]: https://github.com/micropython/micropython-lib
71 changes: 71 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"


[tool.hatch.version]
path = "uosc/version.py"
pattern = "version = \"(?P<version>.*?)\""


[tool.hatch.build.targets.wheel]
packages = ["uosc"]


[tool.isort]
line_length = 99
profile = "black"


[tool.black]
line-length = 99


[project]
dynamic = ["version"]
name = "micropython-osc"
authors = [
{ name="Christopher Arndt", email="[email protected]" },
]
description = "A minimal OSC client and server library for MicroPython and CPython"
readme = "README.md"
keywords = [
"osc",
"opensoundcontrol",
"network",
"multimedia",
"protocol",
]
classifiers = [
"Development Status :: 4 - Beta",
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"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",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: MicroPython",
"Topic :: Communications",
"Topic :: Home Automation",
"Topic :: Internet",
"Topic :: Multimedia :: Sound/Audio",
"Topic :: Software Development :: Libraries :: Python Modules",
"Topic :: System :: Networking",
]
requires-python = ">=3.8"

[project.license]
file = "LICENSE.md"

[project.urls]
"Homepage" = "https://github.com/SpotlightKid/micropython-osc"
"Bug Tracker" = "https://github.com/SpotlightKid/micropython-osc/issues"


#[project.scripts]
#uosc-udp-server = "uosc.tools.async_server:main"
4 changes: 2 additions & 2 deletions run_async_server.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash

export MICROPYPATH="$(pwd):${MICROPYPATH:-.frozen:$HOME/.micropython/lib:/usr/lib/micropython}"
exec micropython examples/async_server.py "$@"
export MICROPYPATH="$(pwd):$(pwd)/examples:${MICROPYPATH:-.frozen:$HOME/.micropython/lib:/usr/lib/micropython}"
exec micropython uosc/tools/async_server.py "$@"
4 changes: 4 additions & 0 deletions run_minimal_server.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash

export MICROPYPATH="$(pwd):$(pwd)/examples:${MICROPYPATH:-.frozen:$HOME/.micropython/lib:/usr/lib/micropython}"
exec micropython uosc/tools/minimal_server.py "$@"
4 changes: 0 additions & 4 deletions run_server.sh

This file was deleted.

File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion uosc/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
try:
import logging
except ImportError:
import uosc.fakelogging as logging
import uosc.compat.fakelogging as logging

from uosc.common import Impulse, TimetagNow, to_time

Expand Down
27 changes: 16 additions & 11 deletions examples/async_server.py → uosc/tools/async_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
With micropython (unix port)
MICROPYPATH=".frozen:$(pwd)" micropython examples/async_server.py -v
MICROPYPATH=".frozen:$(pwd).$(pwd)/examples" micropython uosc/tools/async_server.py -v
With CPython (or PyPy etc.)
PYTHONPATH="$(pwd)" python examples/async_server.py -v
PYTHONPATH="$(pwd)" python -m uosc.tools.async_server.py -v
Then send OSC messages to localhost port 9001, for example with oscsend::
oscsend localhost 9001 /foo ifs $i 3.141 "hello world!"
Expand All @@ -36,12 +36,12 @@
from uosc.server import handle_osc

if __debug__:
from socketutil import get_hostport
from uosc.compat.socketutil import get_hostport

try:
import logging
except ImportError:
import uosc.fakelogging as logging
import uosc.compat.fakelogging as logging


log = logging.getLogger("uosc.async_server")
Expand All @@ -55,7 +55,7 @@ def __init__(self, poll_timeout=1, max_packet_size=MAX_DGRAM_SIZE, poll_interval
self.poll_timeout = poll_timeout
self.max_packet_size = max_packet_size
self.poll_interval = poll_interval

def close(self):
self.sock.close()

Expand Down Expand Up @@ -87,7 +87,7 @@ async def serve(self, host, port, cb, **params):
buf, addr = s.recvfrom(maxsize)
if __debug__: log.debug("RECV %i bytes from %s:%s", len(buf), *get_hostport(addr))
asyncio.create_task(cb(res[0], buf, addr, **params))

await asyncio.sleep(interval)
except asyncio.CancelledError:
if __debug__: log.debug("UDPServer.serve task cancelled.")
Expand Down Expand Up @@ -121,18 +121,18 @@ def __call__(self, t, msg):
print()


if __name__ == '__main__':
def main():
import sys
import time

debug = '-v' in sys.argv[1:]

logging.basicConfig(
level=logging.DEBUG if debug else logging.INFO)

server = UDPServer(poll_timeout=50)
counter = Counter(debug=debug)

if __debug__: log.debug("Starting asyncio event loop")
start = time.time()

Expand All @@ -144,3 +144,8 @@ def __call__(self, t, msg):
reqs = counter.count / (time.time() - start)
print("Requests/second: %.2f" % reqs)
print("Requests total: %i" % counter.count)


if __name__ == '__main__':
import sys
sys.exit(main() or 0)
8 changes: 4 additions & 4 deletions examples/minimal_server.py → uosc/tools/minimal_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
try:
import logging
except ImportError:
import uosc.fakelogging as logging
import uosc.compat.fakelogging as logging

if __debug__:
from socketutil import get_hostport
from uosc.compat.socketutil import get_hostport

from uosc.server import handle_osc


log = logging.getLogger("uosc.minimal_server")
DEFAULT_ADDRESS = '0.0.0.0'
DEFAULT_PORT = 9001
Expand Down
1 change: 1 addition & 0 deletions uosc/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version = "0.2.0"

0 comments on commit efe979c

Please sign in to comment.