Skip to content

Commit 30fcb34

Browse files
authored
Merge pull request #50 from pimoroni/repackage
Bookworm/Pi5 Compatibility: Upgrade to latest boilerplate
2 parents 8fb321b + 2cbbfa4 commit 30fcb34

Some content is hidden

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

46 files changed

+727
-1162
lines changed
File renamed without changes.

.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: 15 additions & 11 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
35-
coveralls --service github
36-
if: ${{ matrix.python == '3.9' }}
40+
coveralls --service=github
3741

library/CHANGELOG.txt renamed to CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
2.0.0
2+
-----
3+
4+
* Repackage to hatch/pyproject.toml
5+
* Drop Python 2.7 support
6+
* Switch from smbu2 to smbus2
7+
18
1.1.1
29
-----
310

Makefile

Lines changed: 45 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +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 trailing whitespace"
28-
@! grep -IUrn --color "[[:blank:]]$$" --exclude-dir=packaging --exclude-dir=sphinx --exclude-dir=.tox --exclude-dir=.git --exclude=PKG-INFO
29-
@echo "Checking for DOS line-endings"
30-
@! grep -IlUrn --color "" --exclude-dir=sphinx --exclude-dir=.tox --exclude-dir=.git --exclude=Makefile
31-
@echo "Checking library/CHANGELOG.txt"
32-
@cat library/CHANGELOG.txt | grep ^${LIBRARY_VERSION}
33-
@echo "Checking library/${LIBRARY_NAME}/__init__.py"
34-
@cat library/${LIBRARY_NAME}/__init__.py | grep "^__version__ = '${LIBRARY_VERSION}'"
35-
36-
tag:
37-
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
3837

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

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

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

48-
library/LICENSE.txt: LICENSE
49-
cp LICENSE library/LICENSE.txt
47+
pytest:
48+
tox -e py
5049

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

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

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

63-
python-dist: python-clean python-wheels python-sdist
64-
ls library/dist
59+
clean:
60+
-rm -r dist
6561

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

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

README.md

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,19 @@
1-
# BME68x
1+
# BME680
22

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

8-
BME68x is a series of state-of-the-art environmental sensors that let you measure temperature, pressure, humidity and indoor air quality.
8+
https://shop.pimoroni.com/products/bme680
99

10-
This library is designed to work with the following products:
11-
12-
* BME680 Breakout - https://shop.pimoroni.com/products/bme680
13-
* BME688 4-in-1 Air Quality Breakout - https://shop.pimoroni.com/products/bme688-breakout
10+
The state-of-the-art BME680 breakout lets you measure temperature, pressure, humidity, and indoor air quality.
1411

1512
## Installing
1613

1714
### Full install (recommended):
1815

19-
We've created an easy installation script that will install all pre-requisites and get your BME68x
16+
We've created an easy installation script that will install all pre-requisites and get your BME680
2017
up and running with minimal efforts. To run it, fire up Terminal which you'll find in Menu -> Accessories -> Terminal
2118
on your Raspberry Pi desktop, as illustrated below:
2219

@@ -25,35 +22,35 @@ on your Raspberry Pi desktop, as illustrated below:
2522
In the new terminal window type the command exactly as it appears below (check for typos) and follow the on-screen instructions:
2623

2724
```bash
28-
curl https://get.pimoroni.com/bme680 | bash
25+
git clone https://github.com/pimoroni/bme680-python
26+
cd bme680-python
27+
./install.sh
2928
```
3029

31-
### Manual install:
32-
33-
#### Library install for Python 3:
30+
**Note** Libraries will be installed in the "pimoroni" virtual environment, you will need to activate it to run examples:
3431

35-
```bash
36-
sudo pip3 install bme680
3732
```
38-
39-
#### Library install for Python 2:
40-
41-
```bash
42-
sudo pip2 install bme680
33+
source ~/.virtualenvs/pimoroni/bin/activate
4334
```
4435

4536
### Development:
4637

47-
If you want to contribute, or like living on the edge of your seat by having the latest code, you should clone this repository, `cd` to the library directory, and run:
38+
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:
4839

4940
```bash
50-
sudo python3 setup.py install
41+
git clone https://github.com/pimoroni/bme680-python
42+
cd bme680-python
43+
./install.sh --unstable
5144
```
52-
(or `sudo python setup.py install` whichever your primary Python environment may be)
5345

54-
In all cases you will have to have I2C enabled (`sudo raspi-config`, under 'Interfacing Options').
46+
In all cases you will have to enable the i2c bus:
47+
48+
```
49+
sudo raspi-config nonint do_i2c 0
50+
```
5551

5652
## Documentation & Support
5753

5854
* Guides and tutorials - https://learn.pimoroni.com/bme680-breakout
5955
* Get help - http://forums.pimoroni.com/c/support
56+

library/bme680/__init__.py renamed to bme680/__init__.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
"""BME680 Temperature, Pressure, Humidity & Gas Sensor."""
2-
from .constants import lookupTable1, lookupTable2
3-
from .constants import BME680Data
4-
from . import constants
52
import math
63
import time
74

8-
__version__ = '1.1.1'
5+
from . import constants
6+
from .constants import BME680Data, lookupTable1, lookupTable2
7+
8+
__version__ = '2.0.0'
99

1010

1111
# Export constants to global namespace
@@ -39,8 +39,8 @@ def __init__(self, i2c_addr=constants.I2C_ADDR_PRIMARY, i2c_device=None):
3939
self.i2c_addr = i2c_addr
4040
self._i2c = i2c_device
4141
if self._i2c is None:
42-
import smbus
43-
self._i2c = smbus.SMBus(1)
42+
import smbus2
43+
self._i2c = smbus2.SMBus(1)
4444

4545
try:
4646
self.chip_id = self._get_regs(constants.CHIP_ID_ADDR, 1)

library/bme680/constants.py renamed to bme680/constants.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@
239239

240240
def bytes_to_word(msb, lsb, bits=16, signed=False):
241241
"""Convert a most and least significant byte into a word."""
242-
# TODO: Reimpliment with struct
242+
# TODO: Reimplement with struct
243243
word = (msb << 8) | lsb
244244
if signed:
245245
word = twos_comp(word, bits)
@@ -248,7 +248,7 @@ def bytes_to_word(msb, lsb, bits=16, signed=False):
248248

249249
def twos_comp(val, bits=16):
250250
"""Convert two bytes into a two's compliment signed word."""
251-
# TODO: Reimpliment with struct
251+
# TODO: Reimplement with struct
252252
if val & (1 << (bits - 1)) != 0:
253253
val = val - (1 << bits)
254254
return val
@@ -312,7 +312,7 @@ def __init__(self): # noqa D107
312312
self.range_sw_err = None
313313

314314
def set_from_array(self, calibration):
315-
"""Set paramaters from an array of bytes."""
315+
"""Set parameters from an array of bytes."""
316316
# Temperature related coefficients
317317
self.par_t1 = bytes_to_word(calibration[T1_MSB_REG], calibration[T1_LSB_REG])
318318
self.par_t2 = bytes_to_word(calibration[T2_MSB_REG], calibration[T2_LSB_REG], bits=16, signed=True)

0 commit comments

Comments
 (0)