Skip to content

Commit 03249b9

Browse files
Merge pull request #3 from pimoroni/new-boilerplate-rebased
CI & Packaging: Upgrade to latest boilerplate.
2 parents cc11ee5 + 0e2bd6a commit 03249b9

42 files changed

Lines changed: 1279 additions & 1056 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/build.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Build
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
9+
jobs:
10+
test:
11+
name: Python ${{ matrix.python }}
12+
runs-on: ubuntu-latest
13+
strategy:
14+
matrix:
15+
python: ['3.9', '3.10', '3.11']
16+
17+
env:
18+
RELEASE_FILE: ${{ github.event.repository.name }}-${{ github.event.release.tag_name || github.sha }}-py${{ matrix.python }}
19+
20+
steps:
21+
- name: Checkout Code
22+
uses: actions/checkout@v3
23+
24+
- name: Set up Python ${{ matrix.python }}
25+
uses: actions/setup-python@v3
26+
with:
27+
python-version: ${{ matrix.python }}
28+
29+
- name: Install Dependencies
30+
run: |
31+
make dev-deps
32+
33+
- name: Build Packages
34+
run: |
35+
make dist
36+
37+
- name: Upload Packages
38+
uses: actions/upload-artifact@v3
39+
with:
40+
name: ${{ env.RELEASE_FILE }}
41+
path: dist/

.github/workflows/qa.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: QA
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
9+
jobs:
10+
test:
11+
name: linting & spelling
12+
runs-on: ubuntu-latest
13+
14+
env:
15+
TERM: xterm-256color
16+
17+
steps:
18+
- name: Checkout Code
19+
uses: actions/checkout@v2
20+
21+
- name: Set up Python '3,11'
22+
uses: actions/setup-python@v3
23+
with:
24+
python-version: '3.11'
25+
26+
- name: Install Dependencies
27+
run: |
28+
make dev-deps
29+
30+
- name: Run Quality Assurance
31+
run: |
32+
make qa
33+
34+
- name: Run Code Checks
35+
run: |
36+
make check

.github/workflows/test.yml

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Python Tests
1+
name: Tests
22

33
on:
44
pull_request:
@@ -8,30 +8,34 @@ on:
88

99
jobs:
1010
test:
11+
name: Python ${{ matrix.python }}
1112
runs-on: ubuntu-latest
1213
strategy:
1314
matrix:
14-
python: [2.7, 3.5, 3.7, 3.9]
15+
python: ['3.9', '3.10', '3.11']
1516

1617
steps:
17-
- uses: actions/checkout@v2
18+
- name: Checkout Code
19+
uses: actions/checkout@v3
20+
1821
- name: Set up Python ${{ matrix.python }}
19-
uses: actions/setup-python@v2
22+
uses: actions/setup-python@v3
2023
with:
2124
python-version: ${{ matrix.python }}
25+
2226
- name: Install Dependencies
2327
run: |
24-
python -m pip install --upgrade setuptools tox
28+
make dev-deps
29+
2530
- name: Run Tests
26-
working-directory: library
2731
run: |
28-
tox -e py
32+
make pytest
33+
2934
- name: Coverage
35+
if: ${{ matrix.python == '3.9' }}
3036
env:
3137
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
32-
working-directory: library
3338
run: |
3439
python -m pip install coveralls
3540
coveralls --service=github
36-
if: ${{ matrix.python == '3.9' }}
3741

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,4 @@ library/debian/
1818
.coverage
1919
.pytest_cache
2020
.tox
21-
2221
.idea
File renamed without changes.

Makefile

Lines changed: 40 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,60 @@
1-
LIBRARY_VERSION=$(shell grep version library/setup.cfg | awk -F" = " '{print $$2}')
2-
LIBRARY_NAME=$(shell grep name library/setup.cfg | awk -F" = " '{print $$2}')
1+
LIBRARY_NAME := $(shell hatch project metadata name 2> /dev/null)
2+
LIBRARY_VERSION := $(shell hatch version 2> /dev/null)
33

4-
.PHONY: usage install uninstall
4+
.PHONY: usage install uninstall check pytest qa build-deps check tag wheel sdist clean dist testdeploy deploy
55
usage:
6+
ifdef LIBRARY_NAME
67
@echo "Library: ${LIBRARY_NAME}"
78
@echo "Version: ${LIBRARY_VERSION}\n"
9+
else
10+
@echo "WARNING: You should 'make dev-deps'\n"
11+
endif
812
@echo "Usage: make <target>, where target is one of:\n"
9-
@echo "install: install the library locally from source"
10-
@echo "uninstall: uninstall the local library"
11-
@echo "check: peform basic integrity checks on the codebase"
12-
@echo "python-readme: generate library/README.md from README.md + library/CHANGELOG.txt"
13-
@echo "python-wheels: build python .whl files for distribution"
14-
@echo "python-sdist: build python source distribution"
15-
@echo "python-clean: clean python build and dist directories"
16-
@echo "python-dist: build all python distribution files"
17-
@echo "python-testdeploy: build all and deploy to test PyPi"
18-
@echo "tag: tag the repository with the current version"
13+
@echo "install: install the library locally from source"
14+
@echo "uninstall: uninstall the local library"
15+
@echo "dev-deps: install Python dev dependencies"
16+
@echo "check: perform basic integrity checks on the codebase"
17+
@echo "qa: run linting and package QA"
18+
@echo "pytest: run Python test fixtures"
19+
@echo "clean: clean Python build and dist directories"
20+
@echo "build: build Python distribution files"
21+
@echo "testdeploy: build and upload to test PyPi"
22+
@echo "deploy: build and upload to PyPi"
23+
@echo "tag: tag the repository with the current version\n"
1924

2025
install:
21-
./install.sh
26+
./install.sh --unstable
2227

2328
uninstall:
2429
./uninstall.sh
2530

26-
check:
27-
@echo "Checking for trailing whitespace"
28-
@! grep -IUrn --color "[[:blank:]]$$" --exclude-dir=sphinx --exclude-dir=.tox --exclude-dir=.git --exclude=PKG-INFO
29-
@echo "Checking for DOS line-endings"
30-
@! grep -lIUrn --color "
31-
" --exclude-dir=sphinx --exclude-dir=.tox --exclude-dir=.git --exclude=Makefile
32-
@echo "Checking library/CHANGELOG.txt"
33-
@cat library/CHANGELOG.txt | grep ^${LIBRARY_VERSION}
34-
@echo "Checking library/${LIBRARY_NAME}/__init__.py"
35-
@cat library/${LIBRARY_NAME}/__init__.py | grep "^__version__ = '${LIBRARY_VERSION}'"
36-
37-
tag:
38-
git tag -a "v${LIBRARY_VERSION}" -m "Version ${LIBRARY_VERSION}"
31+
dev-deps:
32+
python3 -m pip install -r requirements-dev.txt
33+
sudo apt install dos2unix
3934

40-
python-readme: library/README.md
41-
42-
python-license: library/LICENSE.txt
35+
check:
36+
@bash check.sh
4337

44-
library/README.md: README.md library/CHANGELOG.txt
45-
cp README.md library/README.md
46-
printf "\n# Changelog\n" >> library/README.md
47-
cat library/CHANGELOG.txt >> library/README.md
38+
qa:
39+
tox -e qa
4840

49-
library/LICENSE.txt: LICENSE
50-
cp LICENSE library/LICENSE.txt
41+
pytest:
42+
tox -e py
5143

52-
python-wheels: python-readme python-license
53-
cd library; python3 setup.py bdist_wheel
44+
nopost:
45+
@bash check.sh --nopost
5446

55-
python-sdist: python-readme python-license
56-
cd library; python3 setup.py sdist
47+
tag:
48+
git tag -a "v${LIBRARY_VERSION}" -m "Version ${LIBRARY_VERSION}"
5749

58-
python-clean:
59-
-rm -r library/dist
60-
-rm -r library/build
61-
-rm -r library/*.egg-info
50+
build: check
51+
@hatch build
6252

63-
python-dist: python-clean python-wheels python-sdist
64-
ls library/dist
53+
clean:
54+
-rm -r dist
6555

66-
python-testdeploy: python-dist
67-
twine upload --repository-url https://test.pypi.org/legacy/ library/dist/*
56+
testdeploy: build
57+
twine upload --repository-url https://test.pypi.org/legacy/ dist/*
6858

69-
python-deploy: check python-dist
70-
twine upload library/dist/*
59+
deploy: nopost build
60+
twine upload dist/*

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Inventor HAT Mini
22

3-
[![Build Status](https://shields.io/github/workflow/status/pimoroni/inventorhatmini-python/Python%20Tests.svg)](https://github.com/pimoroni/inventorhatmini-python/actions/workflows/test.yml)
3+
[![Build Status](https://img.shields.io/github/actions/workflow/status/pimoroni/inventorhatmini-python/test.yml?branch=main)](https://github.com/pimoroni/inventorhatmini-python/actions/workflows/test.yml)
44
[![Coverage Status](https://coveralls.io/repos/github/pimoroni/inventorhatmini-python/badge.svg?branch=master)](https://coveralls.io/github/pimoroni/inventorhatmini-python?branch=master)
55
[![PyPi Package](https://img.shields.io/pypi/v/inventorhatmini.svg)](https://pypi.python.org/pypi/inventorhatmini)
66
[![Python Versions](https://img.shields.io/pypi/pyversions/inventorhatmini.svg)](https://pypi.python.org/pypi/inventorhatmini)
@@ -17,18 +17,18 @@ You can optionally run `sudo raspi-config` or the graphical Raspberry Pi Configu
1717

1818
Stable library from PyPi:
1919

20-
* Just run `pip3 install inventorhatmini`
20+
* Just run `python3 -m pip install inventorhatmini`
2121

2222
In some cases you may need to use `sudo` or install pip with: `sudo apt install python3-pip`
2323

2424
Latest/development library from GitHub:
2525

2626
* `git clone https://github.com/pimoroni/inventorhatmini-python`
2727
* `cd inventorhatmini-python`
28-
* `sudo ./install.sh`
28+
* `./install.sh`
2929

3030
# Examples and Usage
3131

3232
There are many examples to get you started with your Inventor HAT Mini. With the library installed on your Raspberry Pi, these can be found in the `~/Pimoroni/inventorhatmini/examples` directory. Details about what each one does can be found in the [examples readme](/examples/README.md).
3333

34-
To take Inventor HAT Mini further, the full API is described in the [library readme](/library/inventorhatmini/README.md)
34+
To take Inventor HAT Mini further, the full API is described in the [library readme](/inventorhatmini/README.md)

check.sh

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
#!/bin/bash
2+
3+
# This script handles some basic QA checks on the source
4+
5+
NOPOST=$1
6+
LIBRARY_NAME=`hatch project metadata name`
7+
LIBRARY_VERSION=`hatch version | awk -F "." '{print $1"."$2"."$3}'`
8+
POST_VERSION=`hatch version | awk -F "." '{print substr($4,0,length($4))}'`
9+
10+
success() {
11+
echo -e "$(tput setaf 2)$1$(tput sgr0)"
12+
}
13+
14+
inform() {
15+
echo -e "$(tput setaf 6)$1$(tput sgr0)"
16+
}
17+
18+
warning() {
19+
echo -e "$(tput setaf 1)$1$(tput sgr0)"
20+
}
21+
22+
while [[ $# -gt 0 ]]; do
23+
K="$1"
24+
case $K in
25+
-p|--nopost)
26+
NOPOST=true
27+
shift
28+
;;
29+
*)
30+
if [[ $1 == -* ]]; then
31+
printf "Unrecognised option: $1\n";
32+
exit 1
33+
fi
34+
POSITIONAL_ARGS+=("$1")
35+
shift
36+
esac
37+
done
38+
39+
inform "Checking $LIBRARY_NAME $LIBRARY_VERSION\n"
40+
41+
inform "Checking for trailing whitespace..."
42+
grep -IUrn --color "[[:blank:]]$" --exclude-dir=dist --exclude-dir=.tox --exclude-dir=.git --exclude=PKG-INFO
43+
if [[ $? -eq 0 ]]; then
44+
warning "Trailing whitespace found!"
45+
exit 1
46+
else
47+
success "No trailing whitespace found."
48+
fi
49+
printf "\n"
50+
51+
inform "Checking for DOS line-endings..."
52+
grep -lIUrn --color $'\r' --exclude-dir=dist --exclude-dir=.tox --exclude-dir=.git --exclude=Makefile
53+
if [[ $? -eq 0 ]]; then
54+
warning "DOS line-endings found!"
55+
exit 1
56+
else
57+
success "No DOS line-endings found."
58+
fi
59+
printf "\n"
60+
61+
inform "Checking CHANGELOG.md..."
62+
cat CHANGELOG.md | grep ^${LIBRARY_VERSION} > /dev/null 2>&1
63+
if [[ $? -eq 1 ]]; then
64+
warning "Changes missing for version ${LIBRARY_VERSION}! Please update CHANGELOG.md."
65+
exit 1
66+
else
67+
success "Changes found for version ${LIBRARY_VERSION}."
68+
fi
69+
printf "\n"
70+
71+
inform "Checking for git tag ${LIBRARY_VERSION}..."
72+
git tag -l | grep -E "${LIBRARY_VERSION}$"
73+
if [[ $? -eq 1 ]]; then
74+
warning "Missing git tag for version ${LIBRARY_VERSION}"
75+
fi
76+
printf "\n"
77+
78+
if [[ $NOPOST ]]; then
79+
inform "Checking for .postN on library version..."
80+
if [[ "$POST_VERSION" != "" ]]; then
81+
warning "Found .$POST_VERSION on library version."
82+
inform "Please only use these for testpypi releases."
83+
exit 1
84+
else
85+
success "OK"
86+
fi
87+
fi

examples/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
- [Velocity Tuning](#velocity-tuning)
2525
- [Position on Velocity Tuning](#position-on-velocity-tuning)
2626
- [Servo Examples](#servo-examples)
27-
- [Single Servos](#single-servo)
27+
- [Single Servo](#single-servo)
2828
- [Multiple Servos](#multiple-servos)
2929
- [Simple Easing](#simple-easing)
3030
- [Servo Wave](#servo-wave)

0 commit comments

Comments
 (0)