diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a1aaaf..68b04b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ 1.0.0 ----- -* Repackage to pyproject.toml +* Repackage to hatch/pyproject.toml * Require i2cdevice>=1.0.0 (smbus2) 0.1.1 diff --git a/examples/all-values.py b/examples/all-values.py index d61daff..472917c 100755 --- a/examples/all-values.py +++ b/examples/all-values.py @@ -2,10 +2,7 @@ import time -try: - from smbus2 import SMBus -except ImportError: - from smbus import SMBus +from smbus2 import SMBus from bme280 import BME280 @@ -25,5 +22,5 @@ temperature = bme280.get_temperature() pressure = bme280.get_pressure() humidity = bme280.get_humidity() - print("{:05.2f}*C {:05.2f}hPa {:05.2f}%".format(temperature, pressure, humidity)) + print(f"{temperature:05.2f}°C {pressure:05.2f}hPa {humidity:05.2f}%") time.sleep(1) diff --git a/examples/compensated-temperature.py b/examples/compensated-temperature.py index fbfb9ef..329fd17 100755 --- a/examples/compensated-temperature.py +++ b/examples/compensated-temperature.py @@ -3,12 +3,9 @@ import time from subprocess import PIPE, Popen -from bme280 import BME280 +from smbus2 import SMBus -try: - from smbus2 import SMBus -except ImportError: - from smbus import SMBus +from bme280 import BME280 print( """compensated-temperature.py - Use the CPU temperature to compensate temperature @@ -49,6 +46,6 @@ def get_cpu_temperature(): raw_temp = bme280.get_temperature() comp_temp = raw_temp - ((smoothed_cpu_temp - raw_temp) / factor) - print("Compensated temperature: {:05.2f} *C".format(comp_temp)) + print(f"Raw: {raw_temp:05.2f}°C, Compensated: {comp_temp:05.2f}°C") time.sleep(1.0) diff --git a/examples/dump-calibration.py b/examples/dump-calibration.py index ba322a0..3a6667c 100755 --- a/examples/dump-calibration.py +++ b/examples/dump-calibration.py @@ -1,9 +1,8 @@ #!/usr/bin/env python -try: - from smbus2 import SMBus -except ImportError: - from smbus import SMBus + +from smbus2 import SMBus + from bme280 import BME280 print( @@ -21,4 +20,4 @@ for key in dir(bme280.calibration): if key.startswith("dig_"): value = getattr(bme280.calibration, key) - print("{} = {}".format(key, value)) + print(f"{key} = {value}") diff --git a/examples/local_altitude.py b/examples/local_altitude.py index 51addc3..e890bd7 100644 --- a/examples/local_altitude.py +++ b/examples/local_altitude.py @@ -2,10 +2,8 @@ import time -try: - from smbus2 import SMBus -except ImportError: - from smbus import SMBus +from smbus2 import SMBus + from bme280 import BME280 print( @@ -22,10 +20,20 @@ # asks the user for their local QNH value and confirms it local_qnh = input( - """Please enter your local QNH value. -You can find this by searching for a local METAR on the internet. + """Please enter your local QNH value (air pressure at the mean sea level). + +You can find this by searching for a local METAR report, + eg: "Cambridge METAR" + +And looking for the number prefixed with a "Q", + eg: Q1015 >""" ) + +# remove a Q prefix if there is one +if local_qnh.startswith("Q") or local_qnh.startswith("q"): + local_qnh = local_qnh[1:] + print("You have told us the QNH is", local_qnh) # converts the input into a floating point number @@ -39,5 +47,5 @@ while True: altitude = bme280.get_altitude(qnh=local_qnh) - print(round(altitude), "metres above sea level") + print(f"{altitude:0.0f} metres above sea level") time.sleep(2) diff --git a/examples/relative-altitude.py b/examples/relative-altitude.py index 0e498ae..7406c1e 100755 --- a/examples/relative-altitude.py +++ b/examples/relative-altitude.py @@ -2,10 +2,8 @@ import time -try: - from smbus2 import SMBus -except ImportError: - from smbus import SMBus +from smbus2 import SMBus + from bme280 import BME280 print( @@ -23,7 +21,7 @@ baseline_values = [] baseline_size = 100 -print("Collecting baseline values for {:d} seconds. Do not move the sensor!\n".format(baseline_size)) +print(f"Collecting baseline values for {baseline_size:d} seconds. Do not move the sensor!\n") # Collect some values to calculate a baseline pressure for i in range(baseline_size): @@ -36,5 +34,5 @@ while True: altitude = bme280.get_altitude(qnh=baseline) - print("Relative altitude: {:05.2f} metres".format(altitude)) + print(f"Relative altitude: {altitude:05.2f} metres") time.sleep(1) diff --git a/examples/temperature-compare.py b/examples/temperature-compare.py index e58ddfc..4e3f881 100755 --- a/examples/temperature-compare.py +++ b/examples/temperature-compare.py @@ -2,10 +2,7 @@ import time -try: - from smbus2 import SMBus -except ImportError: - from smbus import SMBus +from smbus2 import SMBus from bme280 import BME280 @@ -33,5 +30,5 @@ while True: temperatureA = bme280A.get_temperature() temperatureB = bme280B.get_temperature() - print("Forced: {:05.2f}*C Normal: {:05.2f}*C D: {:05.2f}".format(temperatureA, temperatureB, abs(temperatureA - temperatureB))) + print(f"Forced: {temperatureA:05.2f}°C Normal: {temperatureB:05.2f}°C D: {abs(temperatureA - temperatureB):05.2f}°C") time.sleep(1) diff --git a/examples/temperature-forced-mode.py b/examples/temperature-forced-mode.py index 08b1362..708dc5b 100755 --- a/examples/temperature-forced-mode.py +++ b/examples/temperature-forced-mode.py @@ -2,10 +2,7 @@ import time -try: - from smbus2 import SMBus -except ImportError: - from smbus import SMBus +from smbus2 import SMBus from bme280 import BME280 @@ -21,5 +18,5 @@ while True: temperature = bme280.get_temperature() - print("{:05.2f}*C".format(temperature)) + print(f"{temperature:05.2f}°C") time.sleep(1) diff --git a/pyproject.toml b/pyproject.toml index 438adfb..d8d254e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -115,4 +115,7 @@ ignore = [ [tool.pimoroni] apt_packages = [] configtxt = [] -commands = [] +commands = [ + "printf \"Setting up i2c...\n\"", + "sudo raspi-config nonint do_i2c 0" +] diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index ff6f91f..0000000 --- a/setup.cfg +++ /dev/null @@ -1,55 +0,0 @@ -# -*- coding: utf-8 -*- -[metadata] -name = pimoroni-bme280 -version = 0.1.1 -author = Philip Howard -author_email = phil@pimoroni.com -description = Python library for the bme280 temperature, pressure and humidity sensor -long_description = file: README.md -long_description_content_type = text/markdown -url = https://www.pimoroni.com -project_urls = - GitHub=https://www.github.com/pimoroni/bme280-python -license = MIT -# This includes the license file(s) in the wheel. -# https://wheel.readthedocs.io/en/stable/user_guide.html#including-license-files-in-the-generated-wheel-file -license_files = LICENSE.txt -classifiers = - Development Status :: 4 - Beta - Operating System :: POSIX :: Linux - License :: OSI Approved :: MIT License - Intended Audience :: Developers - Programming Language :: Python :: 2.6 - Programming Language :: Python :: 2.7 - Programming Language :: Python :: 3 - Topic :: Software Development - Topic :: Software Development :: Libraries - Topic :: System :: Hardware - -[options] -packages = bme280 -install_requires = - i2cdevice>=0.0.6 - -[flake8] -exclude = - .tox, - .eggs, - .git, - __pycache__, - build, - dist -ignore = - E501 - -[pimoroni] -py2deps = - python-pip - python-smbus -py3deps = - python3-pip - python3-smbus -configtxt = -commands = - printf "Setting up i2c...\n" - raspi-config nonint do_i2c 0