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
+3 -1
View File
@@ -23,7 +23,9 @@ database:
`BakaShrotGetMessages.exe`, resolves a name, queries them through the `messages`
view with `is_json = 1`;
- if `python` is on the PATH, reads them and pushes one with
`python\bakashrot.py`;
`python\bakashrot.py`, then installs the wheel (`python\bakashrot-*.whl`,
built by `Interactors/Python/make_wheel.py`) with pip into a folder and
reads and pushes with it, from elsewhere and with no DLL path;
- pushes a 3 MB attachment with `BakaShrotPushMessage.exe -a` and reads it back
identical with `BakaShrotGetAttachment.exe`;
- then force-kills the server and deletes everything.
+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()
+18
View File
@@ -0,0 +1,18 @@
/*
* ISC License
*
* Copyright (c) 2013-2026
* Frank Denis <j at pureftpd dot org>
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+30
View File
@@ -687,6 +687,31 @@ still say the old names where they tell what was done then.
volume and a console for `docker attach`. Not run yet (no Docker on the
dev machine).
## Done: the Python wheel (2026-11-11)
- **`Interactors/Python/make_wheel.py`** packs `bakashrot.py` (as
`bakashrot/__init__.py`) with `BakaShrot_Client.dll` and `libsodium.dll`
into `bakashrot-<version>-py3-none-win_amd64.whl`: `pip install` and
done, nothing to compile. Standard library only (no setuptools), same
inputs give the same wheel. The version is `bakashrot.py`'s
`__version__` (0.0.1).
- **Licenses:** libsodium is ISC, its notice must ship with every copy:
`Libs/libsodium/LICENSE` (from its 1.0.22-RELEASE tag) goes in the
wheel's `dist-info/licenses/` with ours, the metadata (2.4) says
`License-Expression: CC0-1.0 AND ISC`. The release zip ships both too
(`LICENSE.txt`, `LICENSE-libsodium.txt`), it didn't before. No
`vcruntime140.dll` in the wheel: CPython on Windows has loaded its own,
libsodium uses that one (checked by the release's smoke test).
- Works without touching the loader: `bakashrot.py` looks next to itself
first, and Python 3.8+ loads a DLL's dependencies from its own folder.
- **`Release.ps1`** builds it into `python\` (if Python is on the PATH),
and its smoke test installs it with pip into a folder, then reads and
pushes from another folder with no DLL path: passes (6.40 C build).
- Uploading: Gitea's PyPI registry (twine), GitHub has none, so the wheel
goes on the GitHub release (`gh release`). Commands in
`Interactors/Python/README.md`.
- **Windows only.** Linux: open item 20, without bundling libsodium.
## Threat model (2026-11-08)
BakaShrot is an **internal tool, on trusted machines and a trusted
@@ -812,6 +837,11 @@ network**, not exposed to the internet. So:
18. ~~**Linux is untested**~~ Done (2026-11-10): every suite passes, see
`Done: Linux, Docker images`.
19. **Console commands can't be scripted** (see 1).
20. **No Linux wheel.** The Windows one bundles `libsodium.dll` next to the
client DLL; on Linux, find a way not to bundle libsodium like that,
maybe through a package: the distribution's (`libsodium23`, as the
Docker image does, the wheel then holding only the client `.so`), or
a Python package that provides it. See `Done: the Python wheel`.
### Done recently (details in the sections above and `Design/`)
+38 -1
View File
@@ -14,8 +14,12 @@
# libsodium.dll, sqlite3.dll what they need next to them
# vcruntime140.dll what libsodium.dll needs (Libs\redist)
# python\bakashrot.py, example.py the Python client, over the DLL
# python\bakashrot-*.whl the same with the DLLs in it, for pip
# (if Python is on the PATH)
# config.example.ini the server's config, documented
# VERSION.txt commit, date, compiler, libraries
# LICENSE.txt, LICENSE-libsodium.txt BakaShrot's (CC0), libsodium's (ISC,
# its notice must ship with it)
# and Release\BakaShrot-<version>.zip of it, unless -NoZip.
#
# No keys and no configs with keys in it: generate them with BakaShrotGenerateKeyPairs.exe.
@@ -71,6 +75,9 @@ if (-not (Test-Path $SqliteDll)) { throw "Missing $SqliteDll, run Build.ps1 once
$SqliteVersion = (Get-Item $SqliteDll).VersionInfo.ProductVersion
if ([version]$SqliteVersion -lt [version]"3.38") { throw "SQLite $SqliteVersion is too old, the JSON functions need 3.38+" }
$SodiumVersion = (Get-Item $Sodium).VersionInfo.ProductVersion
# Its ISC license asks for its notice in every copy, the wheel's too.
$SodiumLicense = Join-Path $Root "Libs\libsodium\LICENSE"
if (-not (Test-Path $SodiumLicense)) { throw "Missing Libs\libsodium\LICENSE, libsodium's notice must ship with it" }
# The runtime DLLs Windows may not have, see Libs\redist\README.md.
$Redist = @(Get-ChildItem (Join-Path $Root "Libs\redist\x64") -Filter "*.dll" -ErrorAction SilentlyContinue)
if (-not ($Redist | Where-Object { $_.Name -eq "vcruntime140.dll" })) {
@@ -142,6 +149,8 @@ finally {
Get-ChildItem $OutDir -Include "*.lib", "*.exp" -Recurse | Remove-Item -Force
Copy-Item $Sodium $OutDir
Copy-Item $SodiumLicense (Join-Path $OutDir "LICENSE-libsodium.txt")
Copy-Item (Join-Path $Root "LICENSE") (Join-Path $OutDir "LICENSE.txt")
foreach ($File in $Redist) { Copy-Item $File.FullName $OutDir }
Copy-Item $SqliteDll (Join-Path $OutDir "sqlite3.dll")
Copy-Item (Join-Path $Root "Client\BakaShrot_Client_Prototypes.pbi") $OutDir
@@ -150,6 +159,17 @@ New-Item -ItemType Directory -Force (Join-Path $OutDir "python") | Out-Null
foreach ($File in @("bakashrot.py", "example.py")) {
Copy-Item (Join-Path $Root "Interactors\Python\$File") (Join-Path $OutDir "python")
}
# The wheel: bakashrot.py with this release's DLLs, `pip install` and done.
$Wheel = $null
$PythonExe = Get-Command python -ErrorAction SilentlyContinue
if ($PythonExe) {
$Wheel = & $PythonExe.Source -B (Join-Path $Root "Interactors\Python\make_wheel.py") $OutDir (Join-Path $OutDir "python")
if ($LASTEXITCODE -ne 0) { throw "Failed to build the Python wheel: $Wheel" }
Write-Host "Wheel: $Wheel"
}
else {
Write-Warning "No python on the PATH, no wheel"
}
Copy-Item (Join-Path $Root "Server\Config\schema.ini") (Join-Path $OutDir "config.example.ini")
$VersionText = @"
@@ -162,6 +182,8 @@ libsodium: $SodiumVersion
VC++ runtime: $RedistVersion (vcruntime140.dll, for libsodium.dll)
Needs Windows 10 or later, 64-bit. Keep the DLLs next to the exes.
Licenses: BakaShrot is CC0 (LICENSE.txt), libsodium ISC (LICENSE-libsodium.txt),
SQLite public domain, vcruntime140.dll under Visual Studio's redistribution terms.
Run the server: BakaShrot_Server.exe config.ini
Its config: config.example.ini. Keys: BakaShrotGenerateKeyPairs.exe, the
@@ -190,6 +212,7 @@ Tools, next to BakaShrot_Client.dll, with a client.ini:
Python (3.8+, 64-bit): python\bakashrot.py, no dependencies, uses
BakaShrot_Client.dll (set BAKASHROT_DLL, or pass dll_path). See its
docstring, and python\example.py <ClientIni> <Topic> <Node>.
Or pip install python\bakashrot-*.whl: the same, with the DLLs in it.
Compatibility: protocol 6. Servers and clients (the DLL, the tools, the
Python client) must come from the same release: any other version
refuses the connection, there's no mixing. From an older release:
@@ -324,7 +347,6 @@ ServerPublicKey = $($ServerKeys.PublicKey)
Write-Host " Pushed, read back by name, resolved and queried messages: OK"
$PythonExe = Get-Command python -ErrorAction SilentlyContinue
if ($PythonExe) {
$Script = "import sys; sys.path.insert(0, sys.argv[1]); from bakashrot import Client; " +
"c = Client.from_ini(sys.argv[2], sys.argv[3]); c.connect(); " +
@@ -332,6 +354,21 @@ ServerPublicKey = $($ServerKeys.PublicKey)
$PyOut = & $PythonExe.Source -B -c $Script (Join-Path $OutDir "python") $ClientIni (Join-Path $OutDir "BakaShrot_Client.dll") 2>&1
if ($LASTEXITCODE -ne 0 -or "$PyOut" -ne "2 42 3") { throw "Unexpected Python client output: $PyOut" }
Write-Host " Read and pushed with the Python client: OK"
# The wheel, installed by pip, run from elsewhere with no DLL
# path: it must use the DLLs inside it.
$Installed = Join-Path $TestDir "wheel"
$PipOut = & $PythonExe.Source -m pip install --no-index --no-deps --disable-pip-version-check --quiet --target $Installed $Wheel 2>&1
if ($LASTEXITCODE -ne 0) { throw "pip couldn't install the wheel: $PipOut" }
$Script = "import os, sys; sys.path.insert(0, sys.argv[1]); import bakashrot; " +
"c = bakashrot.Client.from_ini(sys.argv[2]); c.connect(); " +
"inside = os.path.dirname(c._dll.path) == os.path.dirname(bakashrot.__file__); " +
"print(inside, c.latest('releasetest', 'tester').json()['py'], c.push({'wheel': 1})); c.close()"
Push-Location $TestDir
try { $PyOut = & $PythonExe.Source -B -c $Script $Installed $ClientIni 2>&1 }
finally { Pop-Location }
if ($LASTEXITCODE -ne 0 -or "$PyOut" -ne "True 1 4") { throw "Unexpected output from the wheel: $PyOut" }
Write-Host " Read and pushed with the wheel, installed by pip: OK"
}
else {
Write-Host " No python on the PATH, the Python client wasn't checked"
+4 -1
View File
@@ -17,7 +17,7 @@ store them in SQLite, and replicate them to their peers by name.
* Clients:
* A DLL, with PureBasic prototypes
* CLI tools to push, read, query and list
* A Python module over the DLL, without dependencies
* A Python module over the DLL, without dependencies, as a wheel with the DLLs in it
## Building
@@ -26,6 +26,7 @@ Requires PureBasic 5.73 or 6.40+ and the submodules.
* **Development:** `powershell -ExecutionPolicy Bypass -File Build.ps1` (into `Build\`)
* **Release:** `powershell -ExecutionPolicy Bypass -File Release.ps1` (into `Release\`)
* **Docker:** See [Docker/README.md](Docker/README.md)
* **Python:** See [Interactors/Python/README.md](Interactors/Python/README.md)
See [Examples/](Examples/README.md) for ready-to-run setups,
and [Server/Config/schema.ini](Server/Config/schema.ini) for every option of the server.
@@ -43,3 +44,5 @@ git clone --recurse-submodules https://git.nibblepoker.lu/aziascreations/BakaShr
All the code in this repo is released in the [Public Domain](LICENSE).
Please note that this doesn't apply to the required PureBasic archives.
The releases and the Python wheel include [libsodium](https://libsodium.org), under the [ISC license](Libs/libsodium/LICENSE).