Skip to content
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
14 changes: 14 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
root = true

[*]
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
charset = utf-8

[Makefile]
indent_style = tab

[*.{py,cfg,ini,toml,yaml,yml,md,sh}]
indent_style = space
indent_size = 4
14 changes: 14 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
- package-ecosystem: "pip"
directory: "/"
schedule:
interval: "weekly"
- package-ecosystem: "pre-commit"
directory: "/"
schedule:
interval: "weekly"
18 changes: 10 additions & 8 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ on:
branches:
- main

permissions:
contents: read

jobs:
test:
name: Build (Python ${{ matrix.python }})
runs-on: ubuntu-latest
strategy:
matrix:
python: ['3.9', '3.10', '3.11']
python: ['3.9', '3.10', '3.11', '3.12', '3.13']

env:
TERM: xterm-256color
Expand All @@ -21,19 +24,18 @@ jobs:
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Python ${{ matrix.python }}
uses: actions/setup-python@v5
- name: Set up uv
uses: astral-sh/setup-uv@v6
with:
enable-cache: true
python-version: ${{ matrix.python }}

- name: Install Dependencies
run: |
make dev-deps

- name: Build Packages
run: |
make build
uv run make build

- name: Upload Packages
uses: actions/upload-artifact@v4
Expand Down
7 changes: 6 additions & 1 deletion .github/workflows/install.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ on:
branches:
- main

permissions:
contents: read

jobs:
test:
name: Install (Python ${{ matrix.python }})
Expand All @@ -14,11 +17,13 @@ jobs:
TERM: xterm-256color
strategy:
matrix:
python: ['3.9', '3.10', '3.11']
python: ['3.9', '3.10', '3.11', '3.12', '3.13']

steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Python ${{ matrix.python }}
uses: actions/setup-python@v5
Expand Down
42 changes: 42 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Publish

on:
release:
types: [published]
workflow_dispatch:

permissions:
contents: read

jobs:
publish:
name: Build and publish to PyPI
runs-on: ubuntu-latest
environment: pypi
permissions:
id-token: write

steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up uv
uses: astral-sh/setup-uv@v6

- name: Build Packages
run: uv build

- name: Check version matches tag
run: |
TAG="${GITHUB_REF_NAME#v}"
BUILT="$(ls dist/*.whl | head -1 | cut -d- -f2)"
echo "tag=$TAG built=$BUILT"
if [ "$GITHUB_REF_NAME" != "$TAG" ] && [ "$TAG" != "$BUILT" ]; then
echo "::error::built $BUILT from tag $TAG"
exit 1
fi

- name: Publish
run: uv publish --trusted-publishing always
22 changes: 12 additions & 10 deletions .github/workflows/qa.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ on:
branches:
- main

permissions:
contents: read

jobs:
test:
name: Linting & Spelling
Expand All @@ -16,24 +19,23 @@ jobs:
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Python '3,11'
uses: actions/setup-python@v5
- name: Set up uv
uses: astral-sh/setup-uv@v6
with:
enable-cache: true
python-version: '3.11'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe make this 3.13? 3.11 would be the edge case with much older Pi's?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's just say I am not optimistic about people keeping Raspberry Pi OS up to date 😆 (though perhaps that's partly my fault...)

Though I am very tempted to drop older versions for new shinies.

Thanks for looking over this, by the way, I'm super rusty on the Python front so I'm mostly fixing the things that specifically annoy me or catch me out any time I come back to this stuff.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have an interest in this working. The Inventor HAT Mini serves as the main breakout for my Third Edition Learn Robotics Programming book, so I'm hoping that it works well for new Pi owners for a good few years. The target being that pip install inventor-hat-mini works for most cases.
This arrived by the route from the inventor-hat-mini to the io-expander to this repo.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your input would be helpful if you want to make sure it stays working for your cases. Certainly a much more focussed and testable use case than all-of-the-possible-permutations-of-installs.

The inventor hat mini repackage PR is here: pimoroni/inventorhatmini-python#17 and basically ready to go, testing notwithstanding.


- name: Install Dependencies
run: |
make dev-deps

- name: Run Quality Assurance
run: |
make qa
uv run make qa

- name: Run Code Checks
run: |
make check
uv run make check

- name: Run Bash Code Checks
- name: Run Pre-Commit
run: |
make shellcheck
uv run pre-commit run --all-files
20 changes: 9 additions & 11 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ on:
branches:
- main

permissions:
contents: read

jobs:
test:
name: Test (Python ${{ matrix.python }})
Expand All @@ -14,30 +17,25 @@ jobs:
TERM: xterm-256color
strategy:
matrix:
python: ['3.9', '3.10', '3.11']
python: ['3.9', '3.10', '3.11', '3.12', '3.13']

steps:
- name: Checkout Code
uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python }}
uses: actions/setup-python@v5
- name: Set up uv
uses: astral-sh/setup-uv@v6
with:
enable-cache: true
python-version: ${{ matrix.python }}

- name: Install Dependencies
run: |
make dev-deps

- name: Run Tests
run: |
make pytest
uv run make pytest

- name: Coverage
if: ${{ matrix.python == '3.9' }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
python -m pip install coveralls
coveralls --service=github

uvx coveralls --service=github
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ library/debian/
.coverage
.pytest_cache
.tox
.venv
uv.lock
22 changes: 22 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: mixed-line-ending
args: ['--fix=lf']
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.15.20
hooks:
- id: ruff-check
args: ['--fix']
- repo: https://github.com/codespell-project/codespell
rev: v2.3.0
hooks:
- id: codespell
additional_dependencies: ['tomli']
- repo: https://github.com/shellcheck-py/shellcheck-py
rev: v0.10.0.1
hooks:
- id: shellcheck
5 changes: 0 additions & 5 deletions .stickler.yml

This file was deleted.

48 changes: 32 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
LIBRARY_NAME := $(shell hatch project metadata name 2> /dev/null)
LIBRARY_VERSION := $(shell hatch version 2> /dev/null)
LIBRARY_VERSION := $(shell grep -m 1 '^[0-9]' CHANGELOG.md)
BUILD_VERSION := $(shell hatch version 2> /dev/null)

.PHONY: usage install uninstall check pytest qa build-deps check tag wheel sdist clean dist testdeploy deploy
.PHONY: usage version install uninstall dev-deps check pre-commit qa pytest nopost tag build clean testdeploy deploy
usage:
ifdef LIBRARY_NAME
@echo "Library: ${LIBRARY_NAME}"
@echo "Version: ${LIBRARY_VERSION}\n"
@echo "Next version: ${LIBRARY_VERSION} (from CHANGELOG.md)"
@echo "Build version: ${BUILD_VERSION} (from the git tag)\n"
else
@echo "WARNING: You should 'make dev-deps'\n"
endif
@echo "Usage: make <target>, where target is one of:\n"
@echo "install: install the library locally from source"
@echo "uninstall: uninstall the local library"
@echo "dev-deps: install Python dev dependencies"
@echo "check: perform basic integrity checks on the codebase"
@echo "qa: run linting and package QA"
@echo "check: verify CHANGELOG.md has an entry for an untagged version"
@echo "qa: run package QA (check-manifest, build, twine)"
@echo "pre-commit: run pre-commit hooks (lint, whitespace) on all files"
@echo "pytest: run Python test fixtures"
@echo "clean: clean Python build and dist directories"
@echo "build: build Python distribution files"
@echo "testdeploy: build and upload to test PyPi"
@echo "deploy: build and upload to PyPi"
@echo "tag: tag the repository with the current version\n"
@echo "tag: tag the repository with the version from CHANGELOG.md\n"

version:
@hatch version
@echo "${LIBRARY_VERSION} (next, from CHANGELOG.md)"
@echo "${BUILD_VERSION} (build, from the git tag)"

install:
./install.sh --unstable
Expand All @@ -32,14 +36,22 @@ uninstall:
./uninstall.sh

dev-deps:
python3 -m pip install -r requirements-dev.txt
sudo apt install dos2unix shellcheck
python3 -m pip install --group dev
pre-commit install

check:
@bash check.sh
@if [ -z "${LIBRARY_VERSION}" ]; then \
echo "No version heading at the top of CHANGELOG.md."; \
exit 1; \
fi
@if git rev-parse -q --verify "refs/tags/v${LIBRARY_VERSION}" > /dev/null; then \
echo "v${LIBRARY_VERSION} is already tagged. Add a CHANGELOG.md entry for the new version."; \
exit 1; \
fi
@echo "CHANGELOG.md is ready for v${LIBRARY_VERSION}."

shellcheck:
shellcheck *.sh
pre-commit:
pre-commit run --all-files

qa:
tox -e qa
Expand All @@ -48,13 +60,17 @@ pytest:
tox -e py

nopost:
@bash check.sh --nopost
@POST_VERSION=`echo "${BUILD_VERSION}" | awk -F '.' '{print $$4}'`; \
if [ -n "$$POST_VERSION" ]; then \
echo "Found .$$POST_VERSION on the build version; tag a release first."; \
exit 1; \
fi

tag: version
tag: check
git tag -a "v${LIBRARY_VERSION}" -m "Version ${LIBRARY_VERSION}"

build: check
@hatch build
build:
uv build

clean:
-rm -r dist
Expand Down
7 changes: 6 additions & 1 deletion PROJECT_NAME/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
__version__ = '0.0.1'
from importlib.metadata import PackageNotFoundError, version

try:
__version__ = version("PROJECT_NAME")
except PackageNotFoundError:
__version__ = "0.0.0"


def test():
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ product description goes here

# Installing

We'd recommend using this library with Raspberry Pi OS Bookworm or later. It requires Python ≥3.7.
We'd recommend using this library with Raspberry Pi OS Bookworm or later. It requires Python ≥3.9.

## Full install (recommended):

Expand Down
Loading
Loading