Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python Packaging #1753

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
==================================================

Expand Down
43 changes: 43 additions & 0 deletions build-rpi-rgb-led-matrix.py
Original file line number Diff line number Diff line change
@@ -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.")
28 changes: 28 additions & 0 deletions hatch.toml
Original file line number Diff line number Diff line change
@@ -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"]
13 changes: 13 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -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="[email protected]"}]
maintainers = [{name="Chris Gill", email="[email protected]"}]
license = "GPL-2.0-or-later"
readme = "README.md"
requires-python = ">=3.11"