Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Gadgetoid committed Feb 17, 2020
0 parents commit c25a989
Show file tree
Hide file tree
Showing 21 changed files with 627 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
build/
_build/
*.o
*.so
*.a
*.py[cod]
*.egg-info
dist/
__pycache__
.DS_Store
*.deb
*.dsc
*.build
*.changes
*.orig.*
packaging/*tar.xz
library/debian/
.coverage
.pytest_cache
.tox
5 changes: 5 additions & 0 deletions .stickler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
linters:
flake8:
python: 3
max-line-length: 160
25 changes: 25 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
language: python
sudo: false
cache: pip

git:
submodules: true

matrix:
include:
- python: "2.7"
env: TOXENV=py27
- python: "3.5"
env: TOXENV=py35

install:
- pip install --ignore-installed --upgrade setuptools pip tox coveralls

script:
- cd library
- tox -vv

after_success: if [ "$TOXENV" == "py35" ]; then coveralls; fi

notifications:
email: false
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2018 Pimoroni Ltd.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
70 changes: 70 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
LIBRARY_VERSION=$(shell grep version library/setup.cfg | awk -F" = " '{print $$2}')
LIBRARY_NAME=$(shell grep name library/setup.cfg | awk -F" = " '{print $$2}')

.PHONY: usage install uninstall
usage:
@echo "Library: ${LIBRARY_NAME}"
@echo "Version: ${LIBRARY_VERSION}\n"
@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 "check: peform basic integrity checks on the codebase"
@echo "python-readme: generate library/README.md from README.md + library/CHANGELOG.txt"
@echo "python-wheels: build python .whl files for distribution"
@echo "python-sdist: build python source distribution"
@echo "python-clean: clean python build and dist directories"
@echo "python-dist: build all python distribution files"
@echo "python-testdeploy: build all and deploy to test PyPi"
@echo "tag: tag the repository with the current version"

install:
./install.sh

uninstall:
./uninstall.sh

check:
@echo "Checking for trailing whitespace"
@! grep -IUrn --color "[[:blank:]]$$" --exclude-dir=sphinx --exclude-dir=.tox --exclude-dir=.git --exclude=PKG-INFO
@echo "Checking for DOS line-endings"
@! grep -IUrn --color "" --exclude-dir=sphinx --exclude-dir=.tox --exclude-dir=.git --exclude=Makefile
@echo "Checking library/CHANGELOG.txt"
@cat library/CHANGELOG.txt | grep ^${LIBRARY_VERSION}
@echo "Checking library/${LIBRARY_NAME}/__init__.py"
@cat library/${LIBRARY_NAME}/__init__.py | grep "^__version__ = '${LIBRARY_VERSION}'"

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

python-readme: library/README.md

python-license: library/LICENSE.txt

library/README.md: README.md library/CHANGELOG.txt
cp README.md library/README.md
printf "\n# Changelog\n" >> library/README.md
cat library/CHANGELOG.txt >> library/README.md

library/LICENSE.txt: LICENSE
cp LICENSE library/LICENSE.txt

python-wheels: python-readme python-license
cd library; python3 setup.py bdist_wheel
cd library; python setup.py bdist_wheel

python-sdist: python-readme python-license
cd library; python setup.py sdist

python-clean:
-rm -r library/dist
-rm -r library/build
-rm -r library/*.egg-info

python-dist: python-clean python-wheels python-sdist
ls library/dist

python-testdeploy: python-dist
twine upload --repository-url https://test.pypi.org/legacy/ library/dist/*

python-deploy: check python-dist
twine upload library/dist/*
Expand Down
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# {{TITLE}}

[![Build Status](https://travis-ci.com/pimoroni/{{LIBNAME}}-python.svg?branch=master)](https://travis-ci.com/pimoroni/{{LIBNAME}}-python)
[![Coverage Status](https://coveralls.io/repos/github/pimoroni/{{LIBNAME}}-python/badge.svg?branch=master)](https://coveralls.io/github/pimoroni/{{LIBNAME}}-python?branch=master)
[![PyPi Package](https://img.shields.io/pypi/v/{{LIBNAME}}.svg)](https://pypi.python.org/pypi/{{LIBNAME}})
[![Python Versions](https://img.shields.io/pypi/pyversions/{{LIBNAME}}.svg)](https://pypi.python.org/pypi/{{LIBNAME}})

# Pre-requisites

You must enable (delete where appropriate):

* i2c: `sudo raspi-config nonint do_i2c 0`
* spi: `sudo raspi-config nonint do_spi 0`

You can optionally run `sudo raspi-config` or the graphical Raspberry Pi Configuration UI to enable interfaces.

# Installing

Stable library from PyPi:

* Just run `sudo pip install {{LIBNAME}}`

Latest/development library from GitHub:

* `git clone https://github.com/pimoroni/{{LIBNAME}}-python`
* `cd {{LIBNAME}}-python`
* `sudo ./install.sh`

75 changes: 75 additions & 0 deletions _bootstrap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
* Python Library - library/name/__init__.py
* At least *one* test - library/tests/test_setup.py
* Examples

# In Detail

To get started, copy the contents of this repository (excluding the .git directory) and run `_bootstrap.sh` to highlight substitutions you need to make.

Be careful to copy *all* files, including those starting with a . such as `.travis.yml`.

A Makefile is provided to automate some tests, checks and package building. You should use it!

## Library

### Structure

Libraries should be singleton if they pertain to a HAT or pHAT and class-based if they are for breakouts with selectable addresses.

A singleton library would work like this:

```
import library
library.do_something()
```

Whereas a class-based library requires an instance of its class:

```
import library
device = library.Library()
device.do_something()
```

### Linting

You should ensure you either run `flake8` while writing the library, or use an IDE/Editor with linting.

All libraries (and example code) should stick to PEP8 style guides, although you can ignore long line warnings (E501) if you feel they're unwarranted.

### Testing

At least one test script should be used to prevent obvious errors and omissions from creeping into the library.

You should use `tox` to run the test scripts:

```
sudo pip install tox
cd library/
tox
```

## Examples

Examples should use hyphens and short, descriptive names, ie: `rainbow-larson.py`

Examples should include a `print()` front-matter introducing them, ie:

```
print("""rainbow-larson.py - Display a larson scanning rainbow
Press Ctrl+C to exit.
""")
```

# Deployment

Before deploying you should `make python-testdeploy` and verify that the package looks good and is installable from test PyPi.

You should also `make check` to catch common errors, including mismatched version numbers, trailing whitespace and DOS line-endings.

Subsequent to deployment you should `git tag -a "vX.X.X" -m "Version X.X.X"` and `git push origin master --follow-tags` to tag a release on GitHub that matches the deployed code.
5 changes: 5 additions & 0 deletions _bootstrap.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
printf "\nOutstanding substitutions:\n"
grep -Irn --color "{{[A-Z:]*}}"

printf "\nOutstanding directory renames:\n"
find . -regex ".*{{[A-Z]*}}"
3 changes: 3 additions & 0 deletions _bootstrap_remotes.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
git remote rename origin boilerplate
git remote set-url --push boilerplate no_push
git remote add origin $1
Loading

0 comments on commit c25a989

Please sign in to comment.