From 2eec7b4f5e96ad44b5a290ee81da8bb1ba5a0b83 Mon Sep 17 00:00:00 2001 From: saces Date: Tue, 3 Mar 2026 20:33:03 +0100 Subject: [PATCH] If python had a package management, I would hate it. --- Containerfile.debian | 11 ++++- README.txt | 9 ++-- pygomx-module/MANIFEST.in | 2 +- pygomx-module/Makefile | 78 ---------------------------------- pygomx-module/build_ffi.py | 5 ++- pygomx-module/pyproject.toml | 17 ++++++++ pygomx-module/requirements.txt | 3 -- pygomx-module/setup.py | 34 ++++++++++++++- 8 files changed, 67 insertions(+), 92 deletions(-) delete mode 100644 pygomx-module/Makefile create mode 100644 pygomx-module/pyproject.toml delete mode 100644 pygomx-module/requirements.txt diff --git a/Containerfile.debian b/Containerfile.debian index 08d892f..c52e22b 100644 --- a/Containerfile.debian +++ b/Containerfile.debian @@ -25,6 +25,15 @@ FROM docker.io/library/python:${PYTHON_VERSION}-${DEBIAN_VERSION} AS pybuilder ENV PYTHONUNBUFFERED=1 ENV PIP_ROOT_USER_ACTION=ignore +RUN <=1.22 and libolm-dev installed (create and activate a venv) cd pygomx-module - pip install -r requirements.txt - make install - - (run 'make clean' to remove any generated) + pip install . cd ../smal pip install [-e] . diff --git a/pygomx-module/MANIFEST.in b/pygomx-module/MANIFEST.in index 7e1214c..d96a342 100644 --- a/pygomx-module/MANIFEST.in +++ b/pygomx-module/MANIFEST.in @@ -1 +1 @@ -include *.so +exclude build_ffi.py diff --git a/pygomx-module/Makefile b/pygomx-module/Makefile deleted file mode 100644 index 610b44f..0000000 --- a/pygomx-module/Makefile +++ /dev/null @@ -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 diff --git a/pygomx-module/build_ffi.py b/pygomx-module/build_ffi.py index b742d69..a7eed44 100644 --- a/pygomx-module/build_ffi.py +++ b/pygomx-module/build_ffi.py @@ -1,4 +1,5 @@ #!/usr/bin/python +import os import sys from cffi import FFI @@ -6,8 +7,8 @@ lib_list = [ "mxclient", ] -if len(sys.argv) > 1: - lib_list += sys.argv[1:] +if os.getenv("PYGOMX_LINK_OLM"): + lib_list += ["olm"] print(f"liblist: {lib_list}") diff --git a/pygomx-module/pyproject.toml b/pygomx-module/pyproject.toml new file mode 100644 index 0000000..499efef --- /dev/null +++ b/pygomx-module/pyproject.toml @@ -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" diff --git a/pygomx-module/requirements.txt b/pygomx-module/requirements.txt deleted file mode 100644 index eefbb88..0000000 --- a/pygomx-module/requirements.txt +++ /dev/null @@ -1,3 +0,0 @@ -cffi -setuptools>=80 -wheel diff --git a/pygomx-module/setup.py b/pygomx-module/setup.py index f5ef31d..33c7a48 100644 --- a/pygomx-module/setup.py +++ b/pygomx-module/setup.py @@ -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}, +)