-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
#!/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="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 =
+py3deps =
+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"