diff --git a/README.md b/README.md index f6dbd27d2..0680098a9 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,14 @@ +RGB LED Python Package +====================== +This fork was created to smooth installation of the Python rpi-rgb-led-matrix +bindings (rgbmatrix). Wheel is built on Python 3.11 on a Pi3 - which should work +for all intended use cases but has not been thoroughly tested. I'm purely an +amateur so welcome someone with more skill and experience picking this up and +improving it. + +As the originating library does not actually version, the package version is using +the package's version (0.0.1) plus the date of the last commit as the version. + Controlling RGB LED display with Raspberry Pi GPIO ================================================== diff --git a/build-rpi-rgb-led-matrix.py b/build-rpi-rgb-led-matrix.py new file mode 100644 index 000000000..95d48ba7a --- /dev/null +++ b/build-rpi-rgb-led-matrix.py @@ -0,0 +1,43 @@ +""" +Hatch Build Hook to compile the rpi-rgb-led-matrix library. +""" +from hatchling.plugin import hookimpl +from hatchling.builders.hooks.plugin.interface import BuildHookInterface + +import os, subprocess +import pathlib + +@hookimpl +def hatch_register_build_hook(): + """ + Register the build hook. + :return: + """ + return PyRGBMatrixBuildHook + +class PyRGBMatrixBuildHook(BuildHookInterface): + PLUGIN_NAME = "pyrgbmatrix" + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + + def clean(self, *args, **kwargs): + self.app.display_info("Running make clean...") + clean_process = subprocess.Popen('make clean', shell=True) + stdout, stderr = clean_process.communicate() + if stderr: + self.app.display_warning("Make clean encountered error.") + + def initialize(self, _: str, build_data: dict): + """ + Initialize the build, fetch the repo, determine version and compile. + :param _: + :param build_data: + :return: + """ + + self.app.display("Building rpi-rgb-led-matrix library...") + make_process = subprocess.Popen('make build-python HARDWARE_DESC="adafruit-hat-pwm"', shell=True) + stdout, stderr = make_process.communicate() + if stderr: + raise BaseException("Error occurred during build.") diff --git a/hatch.toml b/hatch.toml new file mode 100644 index 000000000..db3fe4571 --- /dev/null +++ b/hatch.toml @@ -0,0 +1,28 @@ +# Build environment. +[envs.hatch-build] +dependencies = ["cython"] + +# Wheel build configuration +[build.targets.wheel] +packages = ["bindings/python/rgbmatrix"] +exclude = [ + "*.cpp", + "*.pyd", + "*.pyx" + ] +artifacts = ["*.so"] + +# External hook script which invokes the makefile to build C library. +[build.targets.wheel.hooks.custom] +dependencies = ["cython"] +path = "build-rpi-rgb-led-matrix.py" + +[build.targets.wheel.hooks.cython] +dependencies = ["hatch-cython"] + +[build.targets.wheel.hooks.cython.options] +src = "src/bindings/python/rgbmatrix" +includes = ["../../include"] +libraries = "rgbmatrix" +library_dirs = ["../../lib"] +compile_args = ["-O3", "-Wall"] diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 000000000..6c3ed6e15 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,13 @@ +[build-system] +requires = ["hatchling"] +build-backend = "hatchling.build" + +[project] +name = "rgbmatrix" +version = "0.0.1+20240924" +description = "Packaged version of Christoph Friedrich's rpi-rgb-led-matrix library." +authors = [{name="Christoph Friedrich", email="christoph.friedrich@vonaffenfels.de"}] +maintainers = [{name="Chris Gill", email="chris@chrisgill.net"}] +license = "GPL-2.0-or-later" +readme = "README.md" +requires-python = ">=3.11"