POC
This commit is contained in:
parent
16f964f41d
commit
3bb4ee9def
14 changed files with 219 additions and 7 deletions
|
|
@ -1,18 +1,23 @@
|
|||
# syntax=docker/dockerfile:1
|
||||
|
||||
ARG GOLANG_VERSION=1.25
|
||||
ARG GOLANG_VERSION=1.24
|
||||
ARG DEBIAN_VERSION=trixie
|
||||
ARG PYTHON_VERSION=3.14
|
||||
|
||||
FROM docker.io/library/golang:${GOLANG_VERSION}-${DEBIAN_VERSION} AS gobuilder
|
||||
|
||||
RUN --mount=type=bind,source=./libmxclient,target=/build <<EOF
|
||||
cd /build
|
||||
RUN --mount=type=bind,source=./libmxclient/go.mod,target=/libmxclient/build/go.mod --mount=type=bind,source=./libmxclient/go.sum,target=/libmxclient/build/go.sum <<EOF
|
||||
cd /libmxclient/build
|
||||
go mod download
|
||||
EOF
|
||||
|
||||
RUN --mount=type=bind,source=./libmxclient,target=/libmxclient/build <<EOF
|
||||
cd /libmxclient/build
|
||||
CGO_ENABLED=1 GOARCH=${GOARCH} go build -buildmode=c-shared -o /pygomx-build/libmxclient.so .
|
||||
EOF
|
||||
|
||||
FROM docker.io/library/python:${PYTHON_VERSION}-${DEBIAN_VERSION} AS pybuilder
|
||||
|
||||
ENV PYTHONUNBUFFERED=1
|
||||
COPY --from=gobuilder /pygomx-build/libmxclient.so /usr/local/lib/libmxclient.so
|
||||
COPY --from=gobuilder /pygomx-build/libmxclient.h /usr/local/include/libmxclient.h
|
||||
|
||||
|
|
@ -23,11 +28,11 @@ COPY pygomx /pygomx
|
|||
RUN <<EOF
|
||||
cd /pygomx
|
||||
python3 build_ffi.py
|
||||
ls -la
|
||||
ls -lha
|
||||
EOF
|
||||
|
||||
FROM docker.io/library/python:${PYTHON_VERSION}-${DEBIAN_VERSION}
|
||||
|
||||
ENV PYTHONUNBUFFERED=1
|
||||
RUN pip install cffi
|
||||
|
||||
COPY --from=gobuilder /pygomx-build/libmxclient.so /usr/local/lib/
|
||||
|
|
|
|||
40
README.txt
Normal file
40
README.txt
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
monorepos to have the right versions together
|
||||
|
||||
libmxclient - golang matrix client library
|
||||
pygomx - python binding
|
||||
smal - python matrix lib
|
||||
echobot - simple bot
|
||||
|
||||
|
||||
docker compose build
|
||||
docker compose run --rm dev /bin/bash
|
||||
|
||||
|
||||
pip install -e .
|
||||
discoverhs <mxid>
|
||||
|
||||
|
||||
---
|
||||
screenshot:
|
||||
~/p/m/pygomx (main|✚4) $ docker compose run --rm dev /bin/bash
|
||||
Container pygomx-dev-run-401f3ed5da9c Creating
|
||||
Container pygomx-dev-run-401f3ed5da9c Created
|
||||
root@7c2a56098d3c:/smal# pip install -e .
|
||||
Obtaining file:///smal
|
||||
Installing build dependencies ... done
|
||||
Checking if build backend supports build_editable ... done
|
||||
Getting requirements to build editable ... done
|
||||
Preparing editable metadata (pyproject.toml) ... done
|
||||
Building wheels for collected packages: smal
|
||||
Building editable for smal (pyproject.toml) ... done
|
||||
Created wheel for smal: filename=smal-0.0.1-0.editable-py3-none-any.whl size=3038 sha256=11291c3389b4044f1f12f47c2b3885f58139c5665279cab81f3a7488e5a84aeb
|
||||
Stored in directory: /tmp/pip-ephem-wheel-cache-v8951o8c/wheels/1f/23/eb/fa46f9ff6c1c46feaa27e5ffad7cb966e7aee46d5794e2d15f
|
||||
Successfully built smal
|
||||
Installing collected packages: smal
|
||||
Successfully installed smal-0.0.1
|
||||
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager, possibly rendering your system unusable. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv. Use the --root-user-action option if you know what you are doing and want to suppress this warning.
|
||||
root@7c2a56098d3c:/smal# discoverhs @saces:matrix.org
|
||||
try to discover mxid: b'@saces:matrix.org'
|
||||
Attempt to discover 'matrix.org'
|
||||
b'{"m.homeserver":{"base_url":"https://matrix-client.matrix.org"},"m.identity_server":{"base_url":"https://vector.im"}}'
|
||||
root@7c2a56098d3c:/smal#
|
||||
8
compose.yaml
Normal file
8
compose.yaml
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
services:
|
||||
dev:
|
||||
build:
|
||||
context: .
|
||||
dockerfile: Containerfile.debian
|
||||
working_dir: /smal
|
||||
volumes:
|
||||
- ./smal:/smal:ro
|
||||
|
|
@ -1,3 +1,22 @@
|
|||
module mxclientlib
|
||||
|
||||
go 1.23.5
|
||||
go 1.24.0
|
||||
|
||||
require maunium.net/go/mautrix v0.26.1
|
||||
|
||||
require (
|
||||
filippo.io/edwards25519 v1.1.0 // indirect
|
||||
github.com/mattn/go-colorable v0.1.14 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/rs/zerolog v1.34.0 // indirect
|
||||
github.com/tidwall/gjson v1.18.0 // indirect
|
||||
github.com/tidwall/match v1.1.1 // indirect
|
||||
github.com/tidwall/pretty v1.2.1 // indirect
|
||||
github.com/tidwall/sjson v1.2.5 // indirect
|
||||
go.mau.fi/util v0.9.4 // indirect
|
||||
golang.org/x/crypto v0.46.0 // indirect
|
||||
golang.org/x/exp v0.0.0-20251209150349-8475f28825e9 // indirect
|
||||
golang.org/x/net v0.48.0 // indirect
|
||||
golang.org/x/sys v0.39.0 // indirect
|
||||
golang.org/x/text v0.32.0 // indirect
|
||||
)
|
||||
|
|
|
|||
42
libmxclient/go.sum
Normal file
42
libmxclient/go.sum
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
|
||||
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
|
||||
github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
|
||||
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
|
||||
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
|
||||
github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE=
|
||||
github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8=
|
||||
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
||||
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/rs/xid v1.6.0/go.mod h1:7XoLgs4eV+QndskICGsho+ADou8ySMSjJKDIan90Nz0=
|
||||
github.com/rs/zerolog v1.34.0 h1:k43nTLIwcTVQAncfCw4KZ2VY6ukYoZaBPNOE8txlOeY=
|
||||
github.com/rs/zerolog v1.34.0/go.mod h1:bJsvje4Z08ROH4Nhs5iH600c3IkWhwp44iRc54W6wYQ=
|
||||
github.com/tidwall/gjson v1.14.2/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
|
||||
github.com/tidwall/gjson v1.18.0 h1:FIDeeyB800efLX89e5a8Y0BNH+LOngJyGrIWxG2FKQY=
|
||||
github.com/tidwall/gjson v1.18.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
|
||||
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
|
||||
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
|
||||
github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
|
||||
github.com/tidwall/pretty v1.2.1 h1:qjsOFOWWQl+N3RsoF5/ssm1pHmJJwhjlSbZ51I6wMl4=
|
||||
github.com/tidwall/pretty v1.2.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
|
||||
github.com/tidwall/sjson v1.2.5 h1:kLy8mja+1c9jlljvWTlSazM7cKDRfJuR/bOJhcY5NcY=
|
||||
github.com/tidwall/sjson v1.2.5/go.mod h1:Fvgq9kS/6ociJEDnK0Fk1cpYF4FIW6ZF7LAe+6jwd28=
|
||||
go.mau.fi/util v0.9.4 h1:gWdUff+K2rCynRPysXalqqQyr2ahkSWaestH6YhSpso=
|
||||
go.mau.fi/util v0.9.4/go.mod h1:647nVfwUvuhlZFOnro3aRNPmRd2y3iDha9USb8aKSmM=
|
||||
golang.org/x/crypto v0.46.0 h1:cKRW/pmt1pKAfetfu+RCEvjvZkA9RimPbh7bhFjGVBU=
|
||||
golang.org/x/crypto v0.46.0/go.mod h1:Evb/oLKmMraqjZ2iQTwDwvCtJkczlDuTmdJXoZVzqU0=
|
||||
golang.org/x/exp v0.0.0-20251209150349-8475f28825e9 h1:MDfG8Cvcqlt9XXrmEiD4epKn7VJHZO84hejP9Jmp0MM=
|
||||
golang.org/x/exp v0.0.0-20251209150349-8475f28825e9/go.mod h1:EPRbTFwzwjXj9NpYyyrvenVh9Y+GFeEvMNh7Xuz7xgU=
|
||||
golang.org/x/net v0.48.0 h1:zyQRTTrjc33Lhh0fBgT/H3oZq9WuvRR5gPC70xpDiQU=
|
||||
golang.org/x/net v0.48.0/go.mod h1:+ndRgGjkh8FGtu1w1FGbEC31if4VrNVMuKTgcAAnQRY=
|
||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.39.0 h1:CvCKL8MeisomCi6qNZ+wbb0DN9E5AATixKsvNtMoMFk=
|
||||
golang.org/x/sys v0.39.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
|
||||
golang.org/x/text v0.32.0 h1:ZD01bjUt1FQ9WJ0ClOL5vxgxOI/sVCNgX1YtKwcY0mU=
|
||||
golang.org/x/text v0.32.0/go.mod h1:o/rUWzghvpD5TXrTIBuJU77MTaN0ljMWE47kxGJQ7jY=
|
||||
maunium.net/go/mautrix v0.26.1 h1:FWCC1xY5vwJ5ou3duEBjB6w9IIlwfc9el3q3Mju3Dlg=
|
||||
maunium.net/go/mautrix v0.26.1/go.mod h1:UySSpb8OqXG1sMJ6dDqyzmfcqr2ayZK+KzwqOTAkAOM=
|
||||
36
libmxclient/mxclient/utils.go
Normal file
36
libmxclient/mxclient/utils.go
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
package mxclient
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"maunium.net/go/mautrix"
|
||||
"maunium.net/go/mautrix/id"
|
||||
)
|
||||
|
||||
func DiscoverHS(ids string) string {
|
||||
mxid := id.UserID(ids)
|
||||
|
||||
_, hs, err := mxid.Parse()
|
||||
|
||||
if err != nil {
|
||||
return fmt.Sprintf("ERR: %v", err)
|
||||
}
|
||||
|
||||
fmt.Printf("Attempt to discover '%s'\n", hs)
|
||||
|
||||
wk, err := mautrix.DiscoverClientAPI(context.Background(), hs)
|
||||
if err != nil {
|
||||
return fmt.Sprintf("ERR: %v", err)
|
||||
}
|
||||
if wk == nil {
|
||||
return fmt.Sprintf("No well-known. hs from input: %s", hs)
|
||||
}
|
||||
|
||||
j, err := json.Marshal(wk)
|
||||
if err != nil {
|
||||
return fmt.Sprintf("ERR: %v", err)
|
||||
}
|
||||
return string(j)
|
||||
}
|
||||
|
|
@ -1,7 +1,18 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"mxclientlib/mxclient"
|
||||
)
|
||||
|
||||
import "C"
|
||||
|
||||
//export discoverhs
|
||||
func discoverhs(id *C.char) *C.char {
|
||||
mxid := C.GoString(id)
|
||||
result := mxclient.DiscoverHS(mxid)
|
||||
return C.CString(result)
|
||||
}
|
||||
|
||||
//export hello
|
||||
func hello(name *C.char) *C.char {
|
||||
goName := C.GoString(name)
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ ffibuilder.set_source(
|
|||
|
||||
ffibuilder.cdef(
|
||||
csource="""
|
||||
extern char* discoverhs(char* p0);
|
||||
extern char* hello(char* p0);
|
||||
"""
|
||||
)
|
||||
|
|
|
|||
3
smal/README
Normal file
3
smal/README
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
|
||||
Simple Matrix Application Library
|
||||
=================================
|
||||
30
smal/pyproject.toml
Normal file
30
smal/pyproject.toml
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
[build-system]
|
||||
requires = ["setuptools"]
|
||||
build-backend = "setuptools.build_meta"
|
||||
|
||||
[project]
|
||||
name = "smal"
|
||||
version = "0.0.1"
|
||||
requires-python = ">=3.11"
|
||||
description = "smal - simple matrix application library"
|
||||
authors = [{ name = "saces" }]
|
||||
license = "AGPL-3.0-only"
|
||||
readme = "README"
|
||||
classifiers = [
|
||||
"Development Status :: 3 - Alpha",
|
||||
"Programming Language :: Python",
|
||||
]
|
||||
|
||||
[tool.setuptools.package-dir]
|
||||
"pygomx" = "src/pygomx"
|
||||
"smal" = "src/smal"
|
||||
"smbl" = "src/smbl"
|
||||
|
||||
[project.urls]
|
||||
repository = "https://code.c-base.org/saces/pygomx"
|
||||
|
||||
[tool.distutils.egg_info]
|
||||
egg_base = "/tmp"
|
||||
|
||||
[project.scripts]
|
||||
discoverhs = "pygomx.mxutils:discoverhs"
|
||||
1
smal/src/pygomx/mxutils/__init__.py
Normal file
1
smal/src/pygomx/mxutils/__init__.py
Normal file
|
|
@ -0,0 +1 @@
|
|||
from .discoverhs import discoverhs
|
||||
16
smal/src/pygomx/mxutils/discoverhs.py
Normal file
16
smal/src/pygomx/mxutils/discoverhs.py
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
import sys
|
||||
from _pygomx import lib, ffi
|
||||
|
||||
|
||||
def discoverhs():
|
||||
if len(sys.argv) != 2:
|
||||
print("usage: ", sys.argv[0], " matrixid")
|
||||
return 1
|
||||
|
||||
mxid = sys.argv[1].encode(encoding="utf-8")
|
||||
|
||||
print("try to discover from: ", mxid)
|
||||
|
||||
r = lib.discoverhs(mxid)
|
||||
result = ffi.string(r)
|
||||
print(result)
|
||||
0
smal/src/smal/__init__.py
Normal file
0
smal/src/smal/__init__.py
Normal file
0
smal/src/smbl/__init__.py
Normal file
0
smal/src/smbl/__init__.py
Normal file
Loading…
Add table
Add a link
Reference in a new issue