1
0
mirror of https://github.com/aziascreations/BakaShrot.git synced 2026-11-23 20:58:46 +01:00

Added python wheel stuff, Added libsodium's license for packaging

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-11 21:55:32 +01:00
parent 42bd1f76d9
commit 5887e70e70
8 changed files with 327 additions and 3 deletions
+77
View File
@@ -0,0 +1,77 @@
# BakaShrot - Python client
Python client for BakaShrot servers, over `BakaShrot_Client.dll`, without dependencies.
The wheel includes the DLLs it needs, nothing else to install or compile. \
Windows 10 or later, 64-bit Python 3.8+.
> [!NOTE]
> The client and the server must come from the same release, any other protocol version refuses the connection.
## Linux
There is no Linux wheel yet.
The Windows wheel bundles `libsodium.dll` next to the client DLL. \
On Linux, libsodium shouldn't be bundled like that, but come from a package instead:
* The distribution's, like the Docker image does (`apt install libsodium23`), the wheel only holding the client's `.so`.
* Or a Python package that provides it, as a dependency of the wheel.
Until then, build the client yourself (see [CLAUDE.md](../../CLAUDE.md)) and point `BAKASHROT_DLL` at it.
## Installing
From Gitea:
```shell
pip install --index-url https://git.nibblepoker.lu/api/packages/aziascreations/pypi/simple/ bakashrot
```
From a GitHub release, or a release folder:
```shell
pip install https://github.com/aziascreations/BakaShrot/releases/download/v0.0.1/bakashrot-0.0.1-py3-none-win_amd64.whl
pip install python\bakashrot-0.0.1-py3-none-win_amd64.whl
```
Usage is in [bakashrot.py](bakashrot.py)'s docstring, and in [example.py](example.py).
## Building
`Release.ps1` builds the wheel into `Release\<version>\python\`, and checks it once installed by pip.
By hand, from the DLLs of a release folder or of `Build\`:
```shell
python Interactors/Python/make_wheel.py Release/<version> dist
```
The version comes from `__version__` in [bakashrot.py](bakashrot.py).
## Licenses
The wheel's license is `CC0-1.0 AND ISC`:
* BakaShrot is in the public domain ([CC0](../../LICENSE)).
* The included `libsodium.dll` is under the [ISC license](../../Libs/libsodium/LICENSE),
whose notice must ship with it: it's in the wheel's `dist-info/licenses/`.
`vcruntime140.dll`, which libsodium needs, isn't included: Python already loads its own.
## Uploading
### Gitea
Requires [twine](https://pypi.org/project/twine/) 6.1+ (for the license metadata), and your Gitea login or an access token with the `write:package` scope.
```shell
pip install twine
twine upload --repository-url https://git.nibblepoker.lu/api/packages/aziascreations/pypi -u aziascreations dist/bakashrot-0.0.1-py3-none-win_amd64.whl
```
### GitHub
GitHub has no Python registry, the wheel is attached to the release instead.
Requires the [GitHub CLI](https://cli.github.com/), logged in with `gh auth login`.
```shell
gh release create v0.0.1 --repo aziascreations/BakaShrot --title "0.0.1" dist/bakashrot-0.0.1-py3-none-win_amd64.whl
```
Or, if the release already exists:
```shell
gh release upload v0.0.1 --repo aziascreations/BakaShrot dist/bakashrot-0.0.1-py3-none-win_amd64.whl
```
+5
View File
@@ -46,6 +46,8 @@ shared between threads, one request at a time.
The DLL is 64-bit, so is the Python running this. It's looked for, in order:
the dll_path given, the BAKASHROT_DLL environment variable, next to this
file, then in the current directory. libsodium.dll must be next to it.
The wheel (make_wheel.py, `pip install bakashrot`) has them all next to
this file: nothing else to install or build.
"""
from __future__ import annotations
@@ -61,6 +63,9 @@ from dataclasses import dataclass, field
from datetime import datetime, timezone
from typing import Any, Iterator, Optional, Union
# The release's, and the wheel's (make_wheel.py reads it from here).
__version__ = "0.0.1"
__all__ = [
"Client", "Message", "MessagesPage", "NameEntry", "NamesList",
"BakaShrotError", "RefusedError", "ConnectionLostError", "AuthError", "ErrorCode",
+152
View File
@@ -0,0 +1,152 @@
"""Builds the bakashrot wheel: bakashrot.py with the DLLs it needs, so that
`pip install` is all a Python app needs, nothing to compile.
python make_wheel.py <BinDir> [OutDir]
BinDir holds BakaShrot_Client.dll and libsodium.dll (a release folder, or
Build\\). OutDir defaults to the current directory. Release.ps1 runs it.
Prints the wheel's path.
Licenses: BakaShrot is CC0-1.0, libsodium ISC, which asks for its notice
in every copy: both are in the wheel's dist-info/licenses/ (LICENSE, and
Libs/libsodium/LICENSE), the metadata says "CC0-1.0 AND ISC".
vcruntime140.dll, which libsodium.dll needs, isn't in it: every CPython on
Windows has loaded its own already, and that's the one used.
The wheel is bakashrot-<version>-py3-none-win_amd64.whl, the version being
bakashrot.py's __version__. Inside it, bakashrot.py is bakashrot/__init__.py,
the DLLs next to it, where bakashrot.py looks first. Only the standard
library: no setuptools, no build step, and the same inputs give the same
wheel (fixed timestamps).
"""
import base64
import hashlib
import os
import re
import sys
import zipfile
HERE = os.path.dirname(os.path.abspath(__file__))
ROOT = os.path.normpath(os.path.join(HERE, "..", ".."))
NAME = "bakashrot"
TAG = "py3-none-win_amd64"
DLLS = ["BakaShrot_Client.dll", "libsodium.dll"]
# In the wheel's dist-info/licenses/, from the repository's root.
LICENSES = {"LICENSE": "LICENSE", "libsodium/LICENSE": "Libs/libsodium/LICENSE"}
LICENSE_EXPRESSION = "CC0-1.0 AND ISC"
# Zip entries' timestamp, so the wheel only changes when its content does.
FIXED_TIME = (2026, 1, 1, 0, 0, 0)
SUMMARY = "Python client for BakaShrot servers, with the client DLL included"
DESCRIPTION = """\
# bakashrot
Python client for [BakaShrot](https://github.com/aziascreations/BakaShrot)
servers: push messages and attachments, read them back, resolve names, query.
Includes `BakaShrot_Client.dll` and `libsodium.dll`: nothing else to install
or build. Windows 10 or later, 64-bit Python 3.8+. The server must speak the
same protocol: use the release this package comes from.
BakaShrot is CC0-1.0 (public domain). The included libsodium is Frank
Denis's, under the ISC license: its notice is in this package's
`licenses/libsodium/LICENSE`.
```python
from bakashrot import Client
with Client.from_ini("client.ini") as client:
message_id = client.push({"temperature": 21.5})
for message in client.get_messages("logs", "kitchen", after=0).messages:
print(message.id, message.data)
```
See the module's docstring (`help(bakashrot)`) for the rest.
"""
def read_version(module_path):
with open(module_path, encoding="utf-8") as file:
match = re.search(r'^__version__ = "([^"]+)"', file.read(), re.MULTILINE)
if not match:
sys.exit(f"No __version__ in {module_path}")
return match.group(1)
def record_line(path, data):
digest = base64.urlsafe_b64encode(hashlib.sha256(data).digest()).rstrip(b"=").decode("ascii")
return f"{path},sha256={digest},{len(data)}"
def main():
if len(sys.argv) not in (2, 3):
sys.exit(__doc__)
bin_dir = sys.argv[1]
out_dir = sys.argv[2] if len(sys.argv) == 3 else os.getcwd()
module_path = os.path.join(HERE, "bakashrot.py")
version = read_version(module_path)
dist_info = f"{NAME}-{version}.dist-info"
files = [] # (path in the wheel, bytes)
with open(module_path, "rb") as file:
files.append((f"{NAME}/__init__.py", file.read()))
for dll in DLLS:
path = os.path.join(bin_dir, dll)
if not os.path.isfile(path):
sys.exit(f"Missing {path}")
with open(path, "rb") as file:
files.append((f"{NAME}/{dll}", file.read()))
# Metadata 2.4 (PEP 639): an SPDX expression and the license files,
# without license classifiers (not allowed with an expression).
metadata = "\n".join([
"Metadata-Version: 2.4",
f"Name: {NAME}",
f"Version: {version}",
f"Summary: {SUMMARY}",
"Author: Herwin Bozet (NibblePoker)",
f"License-Expression: {LICENSE_EXPRESSION}",
] + [f"License-File: {name}" for name in LICENSES] + [
"Project-URL: GitHub, https://github.com/aziascreations/BakaShrot",
"Project-URL: Gitea, https://git.nibblepoker.lu/aziascreations/BakaShrot",
"Classifier: Operating System :: Microsoft :: Windows :: Windows 10",
"Classifier: Programming Language :: Python :: 3",
"Requires-Python: >=3.8",
"Description-Content-Type: text/markdown",
"",
DESCRIPTION,
]).encode("utf-8")
files.append((f"{dist_info}/METADATA", metadata))
files.append((f"{dist_info}/WHEEL", "\n".join([
"Wheel-Version: 1.0",
"Generator: BakaShrot make_wheel.py",
"Root-Is-Purelib: false",
f"Tag: {TAG}",
"",
]).encode("utf-8")))
for name, source in LICENSES.items():
path = os.path.join(ROOT, source)
if not os.path.isfile(path):
sys.exit(f"Missing {path}")
with open(path, "rb") as file:
files.append((f"{dist_info}/licenses/{name}", file.read()))
record = "\n".join([record_line(path, data) for path, data in files] + [f"{dist_info}/RECORD,,", ""])
files.append((f"{dist_info}/RECORD", record.encode("utf-8")))
os.makedirs(out_dir, exist_ok=True)
wheel_path = os.path.join(out_dir, f"{NAME}-{version}-{TAG}.whl")
with zipfile.ZipFile(wheel_path, "w", zipfile.ZIP_DEFLATED) as wheel:
for path, data in files:
info = zipfile.ZipInfo(path, FIXED_TIME)
info.compress_type = zipfile.ZIP_DEFLATED
info.external_attr = 0o644 << 16
wheel.writestr(info, data)
print(wheel_path)
if __name__ == "__main__":
main()