Skip to content

Commit 0b120a3

Browse files
committed
Merge branch 'setup-cfg'
2 parents ce99c73 + 318491f commit 0b120a3

File tree

8 files changed

+303
-76
lines changed

8 files changed

+303
-76
lines changed

Makefile

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
LIBRARY_VERSION=$(shell cat library/setup.py | grep version | awk -F"'" '{print $$2}')
2-
LIBRARY_NAME=bme280
3-
#$(shell cat library/setup.py | grep name | awk -F"'" '{print $$2}')
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}')
43

54
.PHONY: usage install uninstall
65
usage:
@@ -10,7 +9,7 @@ usage:
109
@echo "install: install the library locally from source"
1110
@echo "uninstall: uninstall the local library"
1211
@echo "check: peform basic integrity checks on the codebase"
13-
@echo "python-readme: generate library/README.rst from README.md"
12+
@echo "python-readme: generate library/README.md from README.md + library/CHANGELOG.txt"
1413
@echo "python-wheels: build python .whl files for distribution"
1514
@echo "python-sdist: build python source distribution"
1615
@echo "python-clean: clean python build and dist directories"
@@ -37,12 +36,14 @@ check:
3736
tag:
3837
git tag -a "v${LIBRARY_VERSION}" -m "Version ${LIBRARY_VERSION}"
3938

40-
python-readme: library/README.rst
39+
python-readme: library/README.md
4140

4241
python-license: library/LICENSE.txt
4342

44-
library/README.rst: README.md
45-
pandoc --from=markdown --to=rst -o library/README.rst README.md
43+
library/README.md: README.md library/CHANGELOG.txt
44+
cp README.md library/README.md
45+
printf "\n# Changelog\n\n" >> library/README.md
46+
cat library/CHANGELOG.txt >> library/README.md
4647

4748
library/LICENSE.txt: LICENSE
4849
cp LICENSE library/LICENSE.txt

install.sh

Lines changed: 194 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,210 @@
11
#!/bin/bash
22

3-
LIBRARY_VERSION=`cat library/setup.py | grep version | awk -F"'" '{print $2}'`
4-
LIBRARY_NAME=`cat library/setup.py | grep name | awk -F"'" '{print $2}'`
3+
CONFIG=/boot/config.txt
4+
DATESTAMP=`date "+%Y-%M-%d-%H-%M-%S"`
5+
CONFIG_BACKUP=false
6+
APT_HAS_UPDATED=false
7+
USER_HOME=/home/$SUDO_USER
8+
RESOURCES_TOP_DIR=$USER_HOME/Pimoroni
9+
WD=`pwd`
510

6-
printf "$LIBRARY_NAME $LIBRARY_VERSION Python Library: Installer\n\n"
11+
user_check() {
12+
if [ $(id -u) -ne 0 ]; then
13+
printf "Script must be run as root. Try 'sudo ./install.sh'\n"
14+
exit 1
15+
fi
16+
}
17+
18+
confirm() {
19+
if [ "$FORCE" == '-y' ]; then
20+
true
21+
else
22+
read -r -p "$1 [y/N] " response < /dev/tty
23+
if [[ $response =~ ^(yes|y|Y)$ ]]; then
24+
true
25+
else
26+
false
27+
fi
28+
fi
29+
}
30+
31+
prompt() {
32+
read -r -p "$1 [y/N] " response < /dev/tty
33+
if [[ $response =~ ^(yes|y|Y)$ ]]; then
34+
true
35+
else
36+
false
37+
fi
38+
}
39+
40+
success() {
41+
echo -e "$(tput setaf 2)$1$(tput sgr0)"
42+
}
43+
44+
inform() {
45+
echo -e "$(tput setaf 6)$1$(tput sgr0)"
46+
}
47+
48+
warning() {
49+
echo -e "$(tput setaf 1)$1$(tput sgr0)"
50+
}
51+
52+
function do_config_backup {
53+
if [ ! $CONFIG_BACKUP == true ]; then
54+
CONFIG_BACKUP=true
55+
FILENAME="config.preinstall-$LIBRARY_NAME-$DATESTAMP.txt"
56+
inform "Backing up $CONFIG to /boot/$FILENAME\n"
57+
cp $CONFIG /boot/$FILENAME
58+
mkdir -p $RESOURCES_TOP_DIR/config-backups/
59+
cp $CONFIG $RESOURCES_TOP_DIR/config-backups/$FILENAME
60+
if [ -f "$UNINSTALLER" ]; then
61+
echo "cp $RESOURCES_TOP_DIR/config-backups/$FILENAME $CONFIG" >> $UNINSTALLER
62+
fi
63+
fi
64+
}
765

8-
if [ $(id -u) -ne 0 ]; then
9-
printf "Script must be run as root. Try 'sudo ./install.sh'\n"
66+
function apt_pkg_install {
67+
PACKAGES=()
68+
PACKAGES_IN=("$@")
69+
for ((i = 0; i < ${#PACKAGES_IN[@]}; i++)); do
70+
PACKAGE="${PACKAGES_IN[$i]}"
71+
if [ "$PACKAGE" == "" ]; then continue; fi
72+
printf "Checking for $PACKAGE\n"
73+
dpkg -L $PACKAGE > /dev/null 2>&1
74+
if [ "$?" == "1" ]; then
75+
PACKAGES+=("$PACKAGE")
76+
fi
77+
done
78+
PACKAGES="${PACKAGES[@]}"
79+
if ! [ "$PACKAGES" == "" ]; then
80+
echo "Installing missing packages: $PACKAGES"
81+
if [ ! $APT_HAS_UPDATED ]; then
82+
apt update
83+
APT_HAS_UPDATED=true
84+
fi
85+
apt install -y $PACKAGES
86+
if [ -f "$UNINSTALLER" ]; then
87+
echo "apt uninstall -y $PACKAGES"
88+
fi
89+
fi
90+
}
91+
92+
user_check
93+
94+
apt_pkg_install python-configparser
95+
96+
CONFIG_VARS=`python - <<EOF
97+
from configparser import ConfigParser
98+
c = ConfigParser()
99+
c.read('library/setup.cfg')
100+
p = dict(c['pimoroni'])
101+
# Convert multi-line config entries into bash arrays
102+
for k in p.keys():
103+
fmt = '"{}"'
104+
if '\n' in p[k]:
105+
p[k] = "'\n\t'".join(p[k].split('\n')[1:])
106+
fmt = "('{}')"
107+
p[k] = fmt.format(p[k])
108+
print("""
109+
LIBRARY_NAME="{name}"
110+
LIBRARY_VERSION="{version}"
111+
""".format(**c['metadata']))
112+
print("""
113+
PY3_DEPS={py3deps}
114+
PY2_DEPS={py2deps}
115+
SETUP_CMDS={commands}
116+
CONFIG_TXT={configtxt}
117+
""".format(**p))
118+
EOF`
119+
120+
if [ $? -ne 0 ]; then
121+
warning "Error parsing configuration...\n"
10122
exit 1
11123
fi
12124
125+
eval $CONFIG_VARS
126+
127+
RESOURCES_DIR=$RESOURCES_TOP_DIR/$LIBRARY_NAME
128+
UNINSTALLER=$RESOURCES_DIR/uninstall.sh
129+
130+
mkdir -p $RESOURCES_DIR
131+
132+
cat << EOF > $UNINSTALLER
133+
printf "It's recommended you run these steps manually.\n"
134+
printf "If you want to run the full script, open it in\n"
135+
printf "an editor and remove 'exit 1' from below.\n"
136+
exit 1
137+
EOF
138+
139+
printf "$LIBRARY_NAME $LIBRARY_VERSION Python Library: Installer\n\n"
140+
13141
cd library
14142
15143
printf "Installing for Python 2..\n"
16-
python setup.py install
144+
apt_pkg_install "${PY2_DEPS[@]}"
145+
python setup.py install > /dev/null
146+
if [ $? -eq 0 ]; then
147+
success "Done!\n"
148+
echo "pip uninstall $LIBRARY_NAME" >> $UNINSTALLER
149+
fi
17150
18151
if [ -f "/usr/bin/python3" ]; then
19152
printf "Installing for Python 3..\n"
20-
python3 setup.py install
153+
apt_pkg_install "${PY3_DEPS[@]}"
154+
python3 setup.py install > /dev/null
155+
if [ $? -eq 0 ]; then
156+
success "Done!\n"
157+
echo "pip3 uninstall $LIBRARY_NAME" >> $UNINSTALLER
158+
fi
159+
fi
160+
161+
cd $WD
162+
163+
for ((i = 0; i < ${#SETUP_CMDS[@]}; i++)); do
164+
CMD="${SETUP_CMDS[$i]}"
165+
# Attempt to catch anything that touches /boot/config.txt and trigger a backup
166+
if [[ "$CMD" == *"raspi-config"* ]] || [[ "$CMD" == *"$CONFIG"* ]] || [[ "$CMD" == *"\$CONFIG"* ]]; then
167+
do_config_backup
168+
fi
169+
eval $CMD
170+
done
171+
172+
for ((i = 0; i < ${#CONFIG_TXT[@]}; i++)); do
173+
CONFIG_LINE="${CONFIG_TXT[$i]}"
174+
if ! [ "$CONFIG_LINE" == "" ]; then
175+
do_config_backup
176+
inform "Adding $CONFIG_LINE to $CONFIG\n"
177+
sed -i "s/^#$CONFIG_LINE/$CONFIG_LINE/" $CONFIG
178+
if ! grep -q "^$CONFIG_LINE" $CONFIG; then
179+
printf "$CONFIG_LINE\n" >> $CONFIG
180+
fi
181+
fi
182+
done
183+
184+
if [ -d "examples" ]; then
185+
if confirm "Would you like to copy examples to $RESOURCES_DIR?"; then
186+
inform "Copying examples to $RESOURCES_DIR"
187+
cp -r examples/ $RESOURCES_DIR
188+
echo "rm -r $RESOURCES_DIR" >> $UNINSTALLER
189+
success "Done!"
190+
fi
21191
fi
22192
23-
cd ..
193+
printf "\n"
194+
195+
if [ -f "/usr/bin/pydoc" ]; then
196+
printf "Generating documentation.\n"
197+
pydoc -w $LIBRARY_NAME > /dev/null
198+
if [ -f "$LIBRARY_NAME.html" ]; then
199+
cp $LIBRARY_NAME.html $RESOURCES_DIR/docs.html
200+
rm -f $LIBRARY_NAME.html
201+
inform "Documentation saved to $RESOURCES_DIR/docs.html"
202+
success "Done!"
203+
else
204+
error "Failed to generate documentation."
205+
fi
206+
fi
24207
25-
printf "Done!\n"
208+
success "\nAll done!"
209+
inform "If this is your first time installing you should reboot for hardware changes to take effect.\n"
210+
inform "Find uninstall steps in $UNINSTALLER\n"

library/CHANGELOG.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
0.1.0
2+
-----
3+
4+
* Switch to setup.cfg
5+
16
0.0.2
27
-----
38

library/MANIFEST.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
include CHANGELOG.txt
22
include LICENSE.txt
3-
include README.rst
3+
include README.md
44
include setup.py
55
recursive-include bme280 *.py

library/README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# BME280 Temperature, Pressure, & Humidity Sensor
2+
3+
[![Build Status](https://travis-ci.com/pimoroni/bme280-python.svg?branch=master)](https://travis-ci.com/pimoroni/bme280-python)
4+
[![Coverage Status](https://coveralls.io/repos/github/pimoroni/bme280-python/badge.svg?branch=master)](https://coveralls.io/github/pimoroni/bme280-python?branch=master)
5+
[![PyPi Package](https://img.shields.io/pypi/v/pimoroni-bme280.svg)](https://pypi.python.org/pypi/pimoroni-bme280)
6+
[![Python Versions](https://img.shields.io/pypi/pyversions/pimoroni-bme280.svg)](https://pypi.python.org/pypi/pimoroni-bme280)
7+
8+
Suitable for measuring ambient temperature, barometric pressure, and humidity, the BME280 is a great indoor environmental sensor.
9+
10+
# Pre-requisites
11+
12+
You must enable:
13+
14+
* i2c: `sudo raspi-config nonint do_i2c 0`
15+
16+
You can optionally run `sudo raspi-config` or the graphical Raspberry Pi Configuration UI to enable interfaces.
17+
18+
# Installing
19+
20+
Stable library from PyPi:
21+
22+
* Just run `sudo pip install pimoroni-bme280`
23+
24+
Latest/development library from GitHub:
25+
26+
* `git clone https://github.com/pimoroni/bme280-python`
27+
* `cd bme280-python`
28+
* `sudo ./install.sh`
29+
30+
31+
# Changelog
32+
33+
0.1.0
34+
-----
35+
36+
* Switch to setup.cfg
37+
38+
0.0.2
39+
-----
40+
41+
* Update to i2cdevice>=0.0.6 set/get API
42+
43+
0.0.1
44+
-----
45+
46+
* Initial Release

library/README.rst

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)