-LIBRARY_VERSION=`cat library/setup.py | grep version | awk -F"'" '{print $$2}'`
-LIBRARY_NAME=`cat library/setup.py | grep name | awk -F"'" '{print $$2}'`
+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 "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
check:
@echo "Checking for trailing whitespace"
- @! grep -IUrn --color "[[:blank:]]$$" --exclude-dir=.tox --exclude-dir=.git --exclude=PKG-INFO
+ @! 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 "\r" --exclude-dir=fonts --exclude-dir=.tox --exclude-dir=.git --exclude=Makefile
+ @! grep -IUrn --color "\r" --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.rst
python-license: library/LICENSE.txt
-library/README.rst: README.md
+library/README.rst: README.md library/CHANGELOG.txt
pandoc --from=markdown --to=rst -o library/README.rst README.md
+ echo "" >> library/README.rst
+ cat library/CHANGELOG.txt >> library/README.rst
library/LICENSE.txt: LICENSE
cp LICENSE library/LICENSE.txt
-# Enviro+ pHAT
+# Enviro+
+
+Designed for environmental monitoring, Enviro+ lets you measure air quality (pollutant gases and particulates), temperature, pressure, humidity, light, and noise level. Learn more - https://shop.pimoroni.com/products/enviro-plus
[![Build Status](https://travis-ci.com/pimoroni/enviroplus-python.svg?branch=master)](https://travis-ci.com/pimoroni/enviroplus-python)
[![Coverage Status](https://coveralls.io/repos/github/pimoroni/enviroplus-python/badge.svg?branch=master)](https://coveralls.io/github/pimoroni/enviroplus-python?branch=master)
# Installing
-Stable library from PyPi:
+You're best using the "One-line" install method if you want all of the UART serial configuration for the PMS5003 particulate matter sensor to run automatically.
+
+## One-line (Installs from GitHub)
-* Just run `sudo pip install enviroplus`
+```
+curl -sSL https://get.pimoroni.com/enviroplus | bash
+```
-(**Note** that you're best using the git clone / install.sh method below if you want all of the UART serial configuration for the PMS5003 particulate matter sensor to run automatically)
+**Note** report issues with one-line installer here: https://github.com/pimoroni/get
-Latest/development library from GitHub:
+## Or... Install and configure dependencies from GitHub:
* `git clone https://github.com/pimoroni/enviroplus-python`
* `cd enviroplus-python`
* `sudo ./install.sh`
+**Note** Raspbian Lite users may first need to install git: `sudo apt install git`
+
+## Or... Install from PyPi and configure manually:
+
+* Run `sudo pip install enviroplus`
+
+**Note** this wont perform any of the required configuration changes on your Pi, you may additionally need to:
+
+* Enable i2c: `raspi-config nonint do_i2c 0`
+* Enable SPI: `raspi-config nonint do_spi 0`
+
+And if you're using a PMS5003 sensor you will need to:
+
+* Enable serial: `raspi-config nonint set_config_var enable_uart 1 /boot/config.txt`
+* Disable serial terminal: `sudo raspi-config nonint do_serial 1`
+* Add `dtoverlay=pi3-miniuart-bt` to your `/boot/config.txt`
+
+And install additional dependencies:
+
+```
+sudo apt install python-numpy python-smbus
+```
+
+## Help & Support
+
+* GPIO Pinout - https://pinout.xyz/pinout/enviro_plus
+* Support forums - http://forums.pimoroni.com/c/support
+* Discord - https://discord.gg/hr93ByC
#!/bin/bash
-LIBRARY_VERSION=`cat library/setup.py | grep version | awk -F"'" '{print $2}'`
-LIBRARY_NAME=`cat library/setup.py | grep name | awk -F"'" '{print $2}'`
CONFIG=/boot/config.txt
DATESTAMP=`date "+%Y-%M-%d-%H-%M-%S"`
+CONFIG_BACKUP=false
+
+CONFIG_VARS=`python - <<EOF
+from configparser import ConfigParser
+c = ConfigParser()
+c.read('library/setup.cfg')
+p = dict(c['pimoroni'])
+# Convert multi-line config entries into bash arrays
+for k in p.keys():
+ fmt = '"{}"'
+ if '\n' in p[k]:
+ p[k] = "'\n\t'".join(p[k].split('\n')[1:])
+ fmt = "('{}')"
+ p[k] = fmt.format(p[k])
+print("""
+LIBRARY_NAME="{name}"
+LIBRARY_VERSION="{version}"
+""".format(**c['metadata']))
+print("""
+PY3_DEPS={py3deps}
+PY2_DEPS={py2deps}
+SETUP_CMDS={commands}
+CONFIG_TXT={configtxt}
+""".format(**p))
+EOF`
+
+if [ $? -ne 0 ]; then
+ printf "Error parsing configuration...\n"
+ exit 1
+fi
+
+function do_config_backup {
+ if [ ! $CONFIG_BACKUP == true ]; then
+ CONFIG_BACKUP=true
+ FILENAME="/boot/config.preinstall-$LIBRARY_NAME-$DATESTAMP.txt"
+ printf "Backing up $CONFIG to $FILENAME\n"
+ cp $CONFIG $FILENAME
+ fi
+}
+
+function apt_pkg_install {
+ PACKAGES=()
+ PACKAGES_IN=("$@")
+ for ((i = 0; i < ${#PACKAGES_IN[@]}; i++)); do
+ PACKAGE="${PACKAGES_IN[$i]}"
+ printf "Checking for $PACKAGE\n"
+ dpkg -L $PACKAGE > /dev/null 2>&1
+ if [ "$?" == "1" ]; then
+ PACKAGES+=("$PACKAGE")
+ fi
+ done
+ PACKAGES="${PACKAGES[@]}"
+ if ! [ "$PACKAGES" == "" ]; then
+ echo "Installing missing packages: $PACKAGES"
+ sudo apt update
+ sudo apt install -y $PACKAGES
+ fi
+}
+
+eval $CONFIG_VARS
printf "$LIBRARY_NAME $LIBRARY_VERSION Python Library: Installer\n\n"
cd library
printf "Installing for Python 2..\n"
+apt_pkg_install "${PY2_DEPS[@]}"
python setup.py install
if [ -f "/usr/bin/python3" ]; then
printf "Installing for Python 3..\n"
+ apt_pkg_install "${PY3_DEPS[@]}"
python3 setup.py install
fi
cd ..
-printf "Backing up $CONFIG\n"
-cp $CONFIG "config.preinstall-$DATESTAMP.txt"
-
-printf "Setting up i2c and SPI..\n"
-raspi-config nonint do_spi 0
-raspi-config nonint do_i2c 0
-
-printf "Setting up serial for PMS5003..\n"
-# Disable serial terminal over /dev/ttyAMA0
-raspi-config nonint do_serial 1
-# Enable serial port
-raspi-config nonint set_config_var enable_uart 1 $CONFIG
-# Switch serial port to full UART for stability (may adversely affect bluetooth)
-sed -i 's/^#dtoverlay=pi3-miniuart-bt/dtoverlay=pi3-miniuart-bt/' $CONFIG
-if ! grep -q -E "^dtoverlay=pi3-miniuart-bt" $CONFIG; then
- printf "dtoverlay=pi3-miniuart-bt\n" >> $CONFIG
-fi
+for ((i = 0; i < ${#SETUP_CMDS[@]}; i++)); do
+ CMD="${SETUP_CMDS[$i]}"
+ # Attempt to catch anything that touches /boot/config.txt and trigger a backup
+ if [[ "$CMD" == *"raspi-config"* ]] || [[ "$CMD" == *"$CONFIG"* ]] || [[ "$CMD" == *"\$CONFIG"* ]]; then
+ do_config_backup
+ fi
+ eval $CMD
+done
+
+for ((i = 0; i < ${#CONFIG_TXT[@]}; i++)); do
+ CONFIG_LINE="${CONFIG_TXT[$i]}"
+ if ! [ "$CONFIG_LINE" == "" ]; then
+ do_config_backup
+ printf "Adding $CONFIG_LINE to $CONFIG\n"
+ sed -i "s/^#$CONFIG_LINE/$CONFIG_LINE/" $CONFIG
+ if ! grep -q "^$CONFIG_LINE" $CONFIG; then
+ printf "$CONFIG_LINE\n" >> $CONFIG
+ fi
+ fi
+done
printf "Done!\n"
Enviro+ pHAT
============
-|Build Status| |Coverage Status| |PyPi Package| |Python Versions|
+`Build Status <https://travis-ci.com/pimoroni/enviroplus-python>`__
+`Coverage
+Status <https://coveralls.io/github/pimoroni/enviroplus-python?branch=master>`__
+`PyPi Package <https://pypi.python.org/pypi/enviroplus>`__ `Python
+Versions <https://pypi.python.org/pypi/enviroplus>`__
Installing
==========
- Just run ``sudo pip install enviroplus``
-(**Note** that you're best using the git clone / install.sh method below
+(**Note** that you’re best using the git clone / install.sh method below
if you want all of the UART serial configuration for the PMS5003
particulate matter sensor to run automatically)
- ``cd enviroplus-python``
- ``sudo ./install.sh``
-.. |Build Status| image:: https://travis-ci.com/pimoroni/enviroplus-python.svg?branch=master
- :target: https://travis-ci.com/pimoroni/enviroplus-python
-.. |Coverage Status| image:: https://coveralls.io/repos/github/pimoroni/enviroplus-python/badge.svg?branch=master
- :target: https://coveralls.io/github/pimoroni/enviroplus-python?branch=master
-.. |PyPi Package| image:: https://img.shields.io/pypi/v/enviroplus.svg
- :target: https://pypi.python.org/pypi/enviroplus
-.. |Python Versions| image:: https://img.shields.io/pypi/pyversions/enviroplus.svg
- :target: https://pypi.python.org/pypi/enviroplus
+0.0.1
+-----
+
+* Initial Release
+# -*- coding: utf-8 -*-
[metadata]
+name = enviroplus
+version = 0.0.1
+author = Philip Howard
+author_email = phil@pimoroni.com
+description = Enviro pHAT Plus environmental monitoring add-on for Raspberry Pi"
+long_description = file: README.rst
+keywords = Raspberry Pi
+url = https://www.pimoroni.com
+project_urls =
+ GitHub=https://www.github.com/pimoroni/enviroplus-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
[flake8]
exclude =
dist
ignore =
E501
+
+[pimoroni]
+py2deps =
+ python-numpy
+ python-smbus
+py3deps =
+ python3-numpy
+ python3-smbus
+configtxt =
+ dtoverlay=pi3-miniuart-bt # for Enviro+
+commands =
+ printf "Setting up i2c and SPI..\n"
+ raspi-config nonint do_spi 0
+ raspi-config nonint do_i2c 0
+ printf "Setting up serial for PMS5003..\n"
+ raspi-config nonint do_serial 1 # Disable serial terminal over /dev/ttyAMA0
+ raspi-config nonint set_config_var enable_uart 1 $CONFIG # Enable serial port
SOFTWARE.
"""
-try:
- from setuptools import setup
-except ImportError:
- from distutils.core import setup
-
-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 :: System :: Hardware']
+from setuptools import setup
setup(
- name='enviroplus',
- version='0.0.1',
- author='Philip Howard',
- author_email='phil@pimoroni.com',
- description="""Enviro pHAT Plus environmental monitoring add-on for Raspberry Pi""",
- long_description=open('README.rst').read() + '\n' + open('CHANGELOG.txt').read(),
- license='MIT',
- keywords='Raspberry Pi',
- url='http://www.pimoroni.com',
- project_urls={'GitHub': 'https://www.github.com/pimoroni/enviroplus-python'},
- classifiers=classifiers,
packages=['enviroplus'],
install_requires=['pimoroni-bme280', 'pms5003', 'ltr559', 'st7735', 'ads1015']
)
#!/bin/bash
-LIBRARY_VERSION=`cat library/setup.py | grep version | awk -F"'" '{print $2}'`
-LIBRARY_NAME=`cat library/setup.py | grep name | awk -F"'" '{print $2}'`
+LIBRARY_VERSION=`cat library/setup.cfg | grep version | awk -F" = " '{print $2}'`
+LIBRARY_NAME=`cat library/setup.cfg | grep name | awk -F" = " '{print $2}'`
printf "$LIBRARY_NAME $LIBRARY_VERSION Python Library: Uninstaller\n\n"
# Disable serial port
raspi-config nonint set_config_var enable_uart 0 /boot/config.txt
# Switch serial port back to miniUART
-sed -i 's/^dtoverlay=pi3-miniuart-bt/#dtoverlay=pi3-miniuart-bt/' /boot/config.txt
+sed -i 's/^dtoverlay=pi3-miniuart-bt # for Enviro+/#dtoverlay=pi3-miniuart-bt # for Enviro+/' /boot/config.txt
printf "Done!\n"