Skip to content

Commit 908762b

Browse files
authored
Merge pull request #10 from pimoroni/repackage
Repackage to hatch/pyproject.toml
2 parents 30a718d + e7dcdba commit 908762b

28 files changed

+777
-671
lines changed

.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@v4
23+
24+
- name: Set up Python ${{ matrix.python }}
25+
uses: actions/setup-python@v5
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 build
36+
37+
- name: Upload Packages
38+
uses: actions/upload-artifact@v4
39+
with:
40+
name: ${{ env.RELEASE_FILE }}
41+
path: dist/

.github/workflows/qa.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
env:
14+
TERM: xterm-256color
15+
16+
steps:
17+
- name: Checkout Code
18+
uses: actions/checkout@v4
19+
20+
- name: Set up Python '3,11'
21+
uses: actions/setup-python@v5
22+
with:
23+
python-version: '3.11'
24+
25+
- name: Install Dependencies
26+
run: |
27+
make dev-deps
28+
29+
- name: Run Quality Assurance
30+
run: |
31+
make qa
32+
33+
- name: Run Code Checks
34+
run: |
35+
make check
36+
37+
- name: Run Bash Code Checks
38+
run: |
39+
make shellcheck

.github/workflows/test.yml

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,41 @@
1-
name: Python Tests
1+
name: Tests
22

33
on:
44
pull_request:
55
push:
66
branches:
7-
- master
7+
- main
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@v5
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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ _build/
55
*.a
66
*.py[cod]
77
*.egg-info
8-
*.swp
98
dist/
109
__pycache__
1110
.DS_Store
@@ -19,4 +18,3 @@ library/debian/
1918
.coverage
2019
.pytest_cache
2120
.tox
22-
.vscode

library/CHANGELOG.txt renamed to CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
1.0.0
2+
-----
3+
4+
* Repackage to hatch/pyproject.toml
5+
* Migrate to smbus2
6+
17
0.1.0
28
-----
39

Makefile

Lines changed: 45 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,66 @@
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"
24+
25+
version:
26+
@hatch version
1927

2028
install:
21-
./install.sh
29+
./install.sh --unstable
2230

2331
uninstall:
2432
./uninstall.sh
2533

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

37-
python-readme: library/README.md
38+
check:
39+
@bash check.sh
3840

39-
python-license: library/LICENSE.txt
41+
shellcheck:
42+
shellcheck *.sh
4043

41-
library/README.md: README.md library/CHANGELOG.txt
42-
cp README.md library/README.md
43-
printf "\n# Changelog\n" >> library/README.md
44-
cat library/CHANGELOG.txt >> library/README.md
44+
qa:
45+
tox -e qa
4546

46-
library/LICENSE.txt: LICENSE
47-
cp LICENSE library/LICENSE.txt
47+
pytest:
48+
tox -e py
4849

49-
python-wheels: python-readme python-license
50-
cd library; python3 setup.py bdist_wheel
51-
cd library; python setup.py bdist_wheel
50+
nopost:
51+
@bash check.sh --nopost
5252

53-
python-sdist: python-readme python-license
54-
cd library; python setup.py sdist
53+
tag: version
54+
git tag -a "v${LIBRARY_VERSION}" -m "Version ${LIBRARY_VERSION}"
5555

56-
python-clean:
57-
-rm -r library/dist
58-
-rm -r library/build
59-
-rm -r library/*.egg-info
56+
build: check
57+
@hatch build
6058

61-
python-dist: python-clean python-wheels python-sdist
62-
ls library/dist
63-
twine check library/dist/*
59+
clean:
60+
-rm -r dist
6461

65-
python-testdeploy: check python-dist
66-
twine upload --repository-url https://test.pypi.org/legacy/ library/dist/*
62+
testdeploy: build
63+
twine upload --repository testpypi dist/*
6764

68-
python-deploy: check python-dist
69-
twine upload library/dist/*
65+
deploy: nopost build
66+
twine upload dist/*

README.md

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,51 @@
11
# AS7262 Spectral Sensor
22

3-
[![Build Status](https://shields.io/github/workflow/status/pimoroni/as7262-python/Python%20Tests.svg)](https://github.com/pimoroni/as7262-python/actions/workflows/test.yml)
4-
[![Coverage Status](https://coveralls.io/repos/github/pimoroni/as7262-python/badge.svg?branch=master)](https://coveralls.io/github/pimoroni/as7262-python?branch=master)
3+
[![Build Status](https://img.shields.io/github/actions/workflow/status/pimoroni/as7262-python/test.yml?branch=main)](https://github.com/pimoroni/as7262-python/actions/workflows/test.yml)
4+
[![Coverage Status](https://coveralls.io/repos/github/pimoroni/as7262-python/badge.svg?branch=main)](https://coveralls.io/github/pimoroni/as7262-python?branch=main)
55
[![PyPi Package](https://img.shields.io/pypi/v/as7262.svg)](https://pypi.python.org/pypi/as7262)
66
[![Python Versions](https://img.shields.io/pypi/pyversions/as7262.svg)](https://pypi.python.org/pypi/as7262)
77

8+
89
Suitable for detecting the properties of ambient light, light passing through a liquid or light reflected from an object the AS7262 spectral sensor has 6 spectral channels at 450 (violet), 500 (blue), 550 (green), 570 (yellow), 600 (orange) and 650nm (red).
910

10-
# Installing
11+
## Installing
12+
13+
### Full install (recommended):
14+
15+
We've created an easy installation script that will install all pre-requisites and get your AS7262
16+
up and running with minimal efforts. To run it, fire up Terminal which you'll find in Menu -> Accessories -> Terminal
17+
on your Raspberry Pi desktop, as illustrated below:
18+
19+
![Finding the terminal](http://get.pimoroni.com/resources/github-repo-terminal.png)
20+
21+
In the new terminal window type the command exactly as it appears below (check for typos) and follow the on-screen instructions:
22+
23+
```bash
24+
git clone https://github.com/pimoroni/as7262-python
25+
cd as7262-python
26+
./install.sh
27+
```
28+
29+
**Note** Libraries will be installed in the "pimoroni" virtual environment, you will need to activate it to run examples:
30+
31+
```
32+
source ~/.virtualenvs/pimoroni/bin/activate
33+
```
34+
35+
### Development:
1136

12-
Stable library from PyPi:
37+
If you want to contribute, or like living on the edge of your seat by having the latest code, you can install the development version like so:
1338

14-
* Just run `python3 -m pip install as7262`
39+
```bash
40+
git clone https://github.com/pimoroni/as7262-python
41+
cd as7262-python
42+
./install.sh --unstable
43+
```
1544

16-
Latest/development library from GitHub:
45+
The install script should do it for you, but in some cases you might have to enable the i2c bus.
1746

18-
* `git clone https://github.com/pimoroni/as7262-python`
19-
* `cd as7262-python`
20-
* `sudo ./install.sh --unstable`
47+
On a Raspberry Pi you can do that like so:
2148

49+
```
50+
sudo raspi-config nonint do_i2c 0
51+
```

library/as7262/__init__.py renamed to as7262/__init__.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
"""Library for the AS7262 Visble Light Spectral Sensor."""
2-
import time
1+
"""Library for the AS7262 Visible Light Spectral Sensor."""
32
import struct
3+
import time
44

5-
from i2cdevice import Device, Register, BitField, _int_to_bytes
5+
from i2cdevice import BitField, Device, Register, _int_to_bytes
66
from i2cdevice.adapter import Adapter, LookupAdapter
77

8-
__version__ = '0.1.0'
8+
__version__ = '1.0.0'
99

1010

1111
class as7262VirtualRegisterBus():
1212
"""AS7262 Virtual Register.
1313
1414
This class implements the wacky virtual register setup
15-
of the AS7262 annd allows i2cdevice.Device to "just work"
15+
of the AS7262 and allows i2cdevice.Device to "just work"
1616
without having to worry about how registers are actually
1717
read or written under the hood.
1818
@@ -25,8 +25,8 @@ def __init__(self, i2c_dev=None):
2525
2626
"""
2727
if i2c_dev is None:
28-
import smbus
29-
self._i2c_bus = smbus.SMBus(1)
28+
import smbus2
29+
self._i2c_bus = smbus2.SMBus(1)
3030
else:
3131
self._i2c_bus = i2c_dev
3232

library/as7262/__main__.py renamed to as7262/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Library for the AS7262 Visble Light Spectral Sensor."""
1+
"""Library for the AS7262 Viisble Light Spectral Sensor."""
22
import as7262
33

44
if __name__ == '__main__':

0 commit comments

Comments
 (0)