If python had a package management, I would hate it.

This commit is contained in:
saces 2026-03-03 20:33:03 +01:00
parent 8a5bebb254
commit 2eec7b4f5e
8 changed files with 67 additions and 92 deletions

View file

@ -25,6 +25,15 @@ FROM docker.io/library/python:${PYTHON_VERSION}-${DEBIAN_VERSION} AS pybuilder
ENV PYTHONUNBUFFERED=1 ENV PYTHONUNBUFFERED=1
ENV PIP_ROOT_USER_ACTION=ignore ENV PIP_ROOT_USER_ACTION=ignore
RUN <<EOF
# install packages
set -e
apt update
apt -y upgrade
apt -y install libolm-dev
rm -rf /var/lib/apt/lists/*
EOF
COPY --from=gobuilder /pygomx-build/libmxclient.so /usr/local/lib/libmxclient.so COPY --from=gobuilder /pygomx-build/libmxclient.so /usr/local/lib/libmxclient.so
COPY --from=gobuilder /pygomx-build/libmxclient.h /usr/local/include/libmxclient.h COPY --from=gobuilder /pygomx-build/libmxclient.h /usr/local/include/libmxclient.h
@ -36,7 +45,7 @@ RUN <<EOF
# build py module # build py module
set -e set -e
cd /pygomx cd /pygomx
python3 build_ffi.py PYGOMX_LINK_OLM=1 python3 build_ffi.py
ls -la *.so ls -la *.so
EOF EOF

View file

@ -16,15 +16,14 @@ the bot follows each invite (autojoin) and have two commands:
!echo [text] - in a DM the bot responds with 'text', !echo [text] - in a DM the bot responds with 'text',
in regular rooms it is a reply. in regular rooms it is a reply.
install (venv): install from source (venv):
you need go >=1.22 and libolm-dev installed
(create and activate a venv) (create and activate a venv)
cd pygomx-module cd pygomx-module
pip install -r requirements.txt pip install .
make install
(run 'make clean' to remove any generated)
cd ../smal cd ../smal
pip install [-e] . pip install [-e] .

View file

@ -1 +1 @@
include *.so exclude build_ffi.py

View file

@ -1,78 +0,0 @@
# set some defaults
# one of static, shared
BUILD_MODE ?= static
# one of none, colm, goolm, vodozemac
OLM_FLAVOR ?= colm
ifndef GO_TAGS
GO_TAGS =
else
GO_TAGS := $(GO_TAGS),
endif
ifeq ($(OLM_FLAVOR),none)
GO_TAGS := $(GO_TAGS)nocrypto
else ifeq ($(OLM_FLAVOR),colm)
GO_TAGS := $(GO_TAGS)colm
else ifeq ($(OLM_FLAVOR),goolm)
GO_TAGS := $(GO_TAGS)goolm
else ifeq ($(OLM_FLAVOR),vodozemac)
GO_TAGS := $(GO_TAGS)vodozemac
else
$(error unknown OLM_FLAVOR $(OLM_FLAVOR))
endif
# calculate configuration matrix
ifeq ($(BUILD_MODE),static)
build_mode_name=c-archive
build_mode_ext=a
else ifeq ($(BUILD_MODE),shared)
build_mode_name=c-shared
build_mode_ext=so
else
$(error unknown BUILD_MODE $(BUILD_MODE))
endif
link_list =
ifeq ($(BUILD_MODE),static)
ifeq ($(OLM_FLAVOR),colm)
link_list += olm
endif
endif
SOURCE_GO=$(shell find ../libmxclient/ -iname "*.go")
ifndef GO_OUTDIR
GO_OUTDIR = ../pygomx-module
endif
.PHONY:
all: _pygomx.o libmxclient.h
mkdir -p build/lib
cp *.so build/lib
_pygomx.o: libmxclient.h build_ffi.py
python3 build_ffi.py $(link_list)
libmxclient.h: ../libmxclient/go.mod ../libmxclient/go.sum $(SOURCE_GO)
cd ../libmxclient/ && \
CGO_ENABLED=1 go build -buildmode=$(build_mode_name) -tags $(GO_TAGS) -o $(GO_OUTDIR)/libmxclient.$(build_mode_ext) .
.PHONY:
clean:
@rm -f _pygomx.*
@rm -f libmxclient.*
@rm -rf dist/
@rm -rf build/
@rm -rf pygomx_module.egg-info
.PHONY:
install: all
python setup.py bdist_wheel
python setup.py install

View file

@ -1,4 +1,5 @@
#!/usr/bin/python #!/usr/bin/python
import os
import sys import sys
from cffi import FFI from cffi import FFI
@ -6,8 +7,8 @@ lib_list = [
"mxclient", "mxclient",
] ]
if len(sys.argv) > 1: if os.getenv("PYGOMX_LINK_OLM"):
lib_list += sys.argv[1:] lib_list += ["olm"]
print(f"liblist: {lib_list}") print(f"liblist: {lib_list}")

View file

@ -0,0 +1,17 @@
[build-system]
requires = ["setuptools>=80", "cffi>=2.0.0"]
build-backend = "setuptools.build_meta"
[project]
name = "pygomx-module"
version = "0.0.1"
requires-python = ">=3.9"
description = "python pindings for a golang matrix library"
license = "AGPL-3.0-only"
readme = "README.txt"
dependencies = ["cffi>=2.0.0"]
[project.urls]
homepage = "https://codeberg.org/saces/pygomx"
heimseite = "https://code.c-base.org/saces/pygomx"

View file

@ -1,3 +0,0 @@
cffi
setuptools>=80
wheel

View file

@ -1,3 +1,33 @@
from setuptools import setup import subprocess
from contextlib import suppress
from setuptools import Command, setup
from setuptools.command.build import build
setup(name="pygomx-module", version="0.0.1", py_modules=["_pygomx"])
class CustomCommand(Command):
def initialize_options(self) -> None:
pass
def finalize_options(self) -> None:
pass
def run(self) -> None:
go_call = [
"go",
"build",
"-buildmode=c-archive",
"-o",
"../pygomx-module/libmxclient.a",
".",
]
subprocess.call(go_call, cwd="../libmxclient")
class CustomBuild(build):
sub_commands = [("build_custom", None)] + build.sub_commands
setup(
cffi_modules=["build_ffi.py:ffibuilder"],
cmdclass={"build": CustomBuild, "build_custom": CustomCommand},
)