From: Philip Howard Date: Wed, 3 Jul 2019 13:27:01 +0000 (+0100) Subject: Merge pull request #5 from pimoroni/pimstaller-v2 X-Git-Url: https://zdv2.bktei.com/gitweb/EVA-2020-02-2.git/commitdiff_plain/fd822cfe4853c1124f84a433046e20ec52a59275?hp=870b67fb2aafac5ba97285e9e2f8d3836a89ce10 Merge pull request #5 from pimoroni/pimstaller-v2 Switch to v2 installer --- diff --git a/Makefile b/Makefile index f17d128..d2bba49 100644 --- a/Makefile +++ b/Makefile @@ -1,8 +1,10 @@ -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 , where target is one of:\n" @echo "install: install the library locally from source" @echo "uninstall: uninstall the local library" @@ -13,6 +15,7 @@ usage: @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 @@ -22,20 +25,25 @@ uninstall: 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 " " --exclude-dir=fonts --exclude-dir=.tox --exclude-dir=.git --exclude=Makefile + @! grep -IUrn --color " " --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 diff --git a/README.md b/README.md index 07923f5..8c4249d 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,6 @@ -# 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) @@ -7,15 +9,47 @@ # 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 diff --git a/install.sh b/install.sh index 1136de8..5cde03b 100755 --- a/install.sh +++ b/install.sh @@ -1,9 +1,67 @@ #!/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 - < /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" @@ -15,31 +73,36 @@ fi 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" diff --git a/library/README.rst b/library/README.rst index 91f88fe..f90e072 100644 --- a/library/README.rst +++ b/library/README.rst @@ -1,7 +1,11 @@ Enviro+ pHAT ============ -|Build Status| |Coverage Status| |PyPi Package| |Python Versions| +`Build Status `__ +`Coverage +Status `__ +`PyPi Package `__ `Python +Versions `__ Installing ========== @@ -10,7 +14,7 @@ Stable library from PyPi: - 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) @@ -20,11 +24,7 @@ Latest/development library from GitHub: - ``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 diff --git a/library/setup.cfg b/library/setup.cfg index 5f24723..0f16015 100644 --- a/library/setup.cfg +++ b/library/setup.cfg @@ -1,7 +1,30 @@ +# -*- 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 = @@ -13,3 +36,20 @@ 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 diff --git a/library/setup.py b/library/setup.py index 23a965f..aefc022 100755 --- a/library/setup.py +++ b/library/setup.py @@ -22,33 +22,9 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 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'] ) diff --git a/uninstall.sh b/uninstall.sh index aaac11b..e317444 100755 --- a/uninstall.sh +++ b/uninstall.sh @@ -1,7 +1,7 @@ #!/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" @@ -28,6 +28,6 @@ raspi-config nonint do_serial 0 # 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"