Skip to content

Commit e882a2b

Browse files
committed
Update packaging, installer & README
1 parent 3686a10 commit e882a2b

File tree

9 files changed

+610
-54
lines changed

9 files changed

+610
-54
lines changed

Makefile

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

44
.PHONY: usage install uninstall
55
usage:
@@ -9,7 +9,7 @@ usage:
99
@echo "install: install the library locally from source"
1010
@echo "uninstall: uninstall the local library"
1111
@echo "check: peform basic integrity checks on the codebase"
12-
@echo "python-readme: generate library/README.rst from README.md"
12+
@echo "python-readme: generate library/README.md from README.md + library/CHANGELOG.txt"
1313
@echo "python-wheels: build python .whl files for distribution"
1414
@echo "python-sdist: build python source distribution"
1515
@echo "python-clean: clean python build and dist directories"
@@ -27,7 +27,7 @@ check:
2727
@echo "Checking for trailing whitespace"
2828
@! grep -IUrn --color "[[:blank:]]$$" --exclude-dir=sphinx --exclude-dir=.tox --exclude-dir=.git --exclude=PKG-INFO
2929
@echo "Checking for DOS line-endings"
30-
@! grep -IUrn --color "" --exclude-dir=sphinx --exclude-dir=.tox --exclude-dir=.git --exclude=Makefile
30+
@! grep -lIUrn --color "" --exclude-dir=sphinx --exclude-dir=.tox --exclude-dir=.git --exclude=Makefile
3131
@echo "Checking library/CHANGELOG.txt"
3232
@cat library/CHANGELOG.txt | grep ^${LIBRARY_VERSION}
3333
@echo "Checking library/${LIBRARY_NAME}/__init__.py"
@@ -36,12 +36,14 @@ check:
3636
tag:
3737
git tag -a "v${LIBRARY_VERSION}" -m "Version ${LIBRARY_VERSION}"
3838

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

4141
python-license: library/LICENSE.txt
4242

43-
library/README.rst: README.md
44-
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" >> library/README.md
46+
cat library/CHANGELOG.txt >> library/README.md
4547

4648
library/LICENSE.txt: LICENSE
4749
cp LICENSE library/LICENSE.txt

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# lsm303d Accelerometer And Compass
22

3-
[![Build Status](https://travis-ci.com/pimoroni/lsm303d-python.svg?branch=master)](https://travis-ci.com/pimoroni/lsm303d-python)
3+
[![Build Status](https://shields.io/github/workflow/status/pimoroni/lsm303d-python/Python%20Tests.svg)](https://github.com/pimoroni/sgp30-python/actions/workflows/test.yml)
44
[![Coverage Status](https://coveralls.io/repos/github/pimoroni/lsm303d-python/badge.svg?branch=master)](https://coveralls.io/github/pimoroni/lsm303d-python?branch=master)
55
[![PyPi Package](https://img.shields.io/pypi/v/lsm303d.svg)](https://pypi.python.org/pypi/lsm303d)
66
[![Python Versions](https://img.shields.io/pypi/pyversions/lsm303d.svg)](https://pypi.python.org/pypi/lsm303d)
@@ -11,11 +11,11 @@ Suitable for measuring orientation and motion, the lsm303d has a 3-axis accelero
1111

1212
Stable library from PyPi:
1313

14-
* Just run `sudo pip install lsm303d`
14+
* Just run `python3 -m pip install lsm303d`
1515

1616
Latest/development library from GitHub:
1717

1818
* `git clone https://github.com/pimoroni/lsm303d-python`
1919
* `cd lsm303d-python`
20-
* `sudo ./install.sh`
20+
* `sudo ./install.sh --unstable`
2121

install-legacy.sh

Lines changed: 256 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,256 @@
1+
#!/bin/bash
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`
10+
USAGE="sudo ./install.sh (--unstable)"
11+
POSITIONAL_ARGS=()
12+
FORCE=false
13+
UNSTABLE=false
14+
CODENAME=`lsb_release -sc`
15+
16+
if [[ $CODENAME == "bullseye" ]]; then
17+
bash ./install.sh $@
18+
exit $?
19+
fi
20+
21+
user_check() {
22+
if [ $(id -u) -ne 0 ]; then
23+
printf "Script must be run as root. Try 'sudo ./install.sh'\n"
24+
exit 1
25+
fi
26+
}
27+
28+
confirm() {
29+
if $FORCE; then
30+
true
31+
else
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+
fi
39+
}
40+
41+
prompt() {
42+
read -r -p "$1 [y/N] " response < /dev/tty
43+
if [[ $response =~ ^(yes|y|Y)$ ]]; then
44+
true
45+
else
46+
false
47+
fi
48+
}
49+
50+
success() {
51+
echo -e "$(tput setaf 2)$1$(tput sgr0)"
52+
}
53+
54+
inform() {
55+
echo -e "$(tput setaf 6)$1$(tput sgr0)"
56+
}
57+
58+
warning() {
59+
echo -e "$(tput setaf 1)$1$(tput sgr0)"
60+
}
61+
62+
function do_config_backup {
63+
if [ ! $CONFIG_BACKUP == true ]; then
64+
CONFIG_BACKUP=true
65+
FILENAME="config.preinstall-$LIBRARY_NAME-$DATESTAMP.txt"
66+
inform "Backing up $CONFIG to /boot/$FILENAME\n"
67+
cp $CONFIG /boot/$FILENAME
68+
mkdir -p $RESOURCES_TOP_DIR/config-backups/
69+
cp $CONFIG $RESOURCES_TOP_DIR/config-backups/$FILENAME
70+
if [ -f "$UNINSTALLER" ]; then
71+
echo "cp $RESOURCES_TOP_DIR/config-backups/$FILENAME $CONFIG" >> $UNINSTALLER
72+
fi
73+
fi
74+
}
75+
76+
function apt_pkg_install {
77+
PACKAGES=()
78+
PACKAGES_IN=("$@")
79+
for ((i = 0; i < ${#PACKAGES_IN[@]}; i++)); do
80+
PACKAGE="${PACKAGES_IN[$i]}"
81+
if [ "$PACKAGE" == "" ]; then continue; fi
82+
printf "Checking for $PACKAGE\n"
83+
dpkg -L $PACKAGE > /dev/null 2>&1
84+
if [ "$?" == "1" ]; then
85+
PACKAGES+=("$PACKAGE")
86+
fi
87+
done
88+
PACKAGES="${PACKAGES[@]}"
89+
if ! [ "$PACKAGES" == "" ]; then
90+
echo "Installing missing packages: $PACKAGES"
91+
if [ ! $APT_HAS_UPDATED ]; then
92+
apt update
93+
APT_HAS_UPDATED=true
94+
fi
95+
apt install -y $PACKAGES
96+
if [ -f "$UNINSTALLER" ]; then
97+
echo "apt uninstall -y $PACKAGES"
98+
fi
99+
fi
100+
}
101+
102+
while [[ $# -gt 0 ]]; do
103+
K="$1"
104+
case $K in
105+
-u|--unstable)
106+
UNSTABLE=true
107+
shift
108+
;;
109+
-f|--force)
110+
FORCE=true
111+
shift
112+
;;
113+
*)
114+
if [[ $1 == -* ]]; then
115+
printf "Unrecognised option: $1\n";
116+
printf "Usage: $USAGE\n";
117+
exit 1
118+
fi
119+
POSITIONAL_ARGS+=("$1")
120+
shift
121+
esac
122+
done
123+
124+
user_check
125+
126+
apt_pkg_install python-configparser
127+
128+
CONFIG_VARS=`python - <<EOF
129+
from configparser import ConfigParser
130+
c = ConfigParser()
131+
c.read('library/setup.cfg')
132+
p = dict(c['pimoroni'])
133+
# Convert multi-line config entries into bash arrays
134+
for k in p.keys():
135+
fmt = '"{}"'
136+
if '\n' in p[k]:
137+
p[k] = "'\n\t'".join(p[k].split('\n')[1:])
138+
fmt = "('{}')"
139+
p[k] = fmt.format(p[k])
140+
print("""
141+
LIBRARY_NAME="{name}"
142+
LIBRARY_VERSION="{version}"
143+
""".format(**c['metadata']))
144+
print("""
145+
PY3_DEPS={py3deps}
146+
PY2_DEPS={py2deps}
147+
SETUP_CMDS={commands}
148+
CONFIG_TXT={configtxt}
149+
""".format(**p))
150+
EOF`
151+
152+
if [ $? -ne 0 ]; then
153+
warning "Error parsing configuration...\n"
154+
exit 1
155+
fi
156+
157+
eval $CONFIG_VARS
158+
159+
RESOURCES_DIR=$RESOURCES_TOP_DIR/$LIBRARY_NAME
160+
UNINSTALLER=$RESOURCES_DIR/uninstall.sh
161+
162+
mkdir -p $RESOURCES_DIR
163+
164+
cat << EOF > $UNINSTALLER
165+
printf "It's recommended you run these steps manually.\n"
166+
printf "If you want to run the full script, open it in\n"
167+
printf "an editor and remove 'exit 1' from below.\n"
168+
exit 1
169+
EOF
170+
171+
printf "$LIBRARY_NAME $LIBRARY_VERSION Python Library: Installer\n\n"
172+
173+
if $UNSTABLE; then
174+
warning "Installing unstable library from source.\n\n"
175+
else
176+
printf "Installing stable library from pypi.\n\n"
177+
fi
178+
179+
cd library
180+
181+
printf "Installing for Python 2..\n"
182+
apt_pkg_install "${PY2_DEPS[@]}"
183+
if $UNSTABLE; then
184+
python setup.py install > /dev/null
185+
else
186+
pip install --upgrade $LIBRARY_NAME
187+
fi
188+
if [ $? -eq 0 ]; then
189+
success "Done!\n"
190+
echo "pip uninstall $LIBRARY_NAME" >> $UNINSTALLER
191+
fi
192+
193+
if [ -f "/usr/bin/python3" ]; then
194+
printf "Installing for Python 3..\n"
195+
apt_pkg_install "${PY3_DEPS[@]}"
196+
if $UNSTABLE; then
197+
python3 setup.py install > /dev/null
198+
else
199+
pip3 install --upgrade $LIBRARY_NAME
200+
fi
201+
if [ $? -eq 0 ]; then
202+
success "Done!\n"
203+
echo "pip3 uninstall $LIBRARY_NAME" >> $UNINSTALLER
204+
fi
205+
fi
206+
207+
cd $WD
208+
209+
for ((i = 0; i < ${#SETUP_CMDS[@]}; i++)); do
210+
CMD="${SETUP_CMDS[$i]}"
211+
# Attempt to catch anything that touches /boot/config.txt and trigger a backup
212+
if [[ "$CMD" == *"raspi-config"* ]] || [[ "$CMD" == *"$CONFIG"* ]] || [[ "$CMD" == *"\$CONFIG"* ]]; then
213+
do_config_backup
214+
fi
215+
eval $CMD
216+
done
217+
218+
for ((i = 0; i < ${#CONFIG_TXT[@]}; i++)); do
219+
CONFIG_LINE="${CONFIG_TXT[$i]}"
220+
if ! [ "$CONFIG_LINE" == "" ]; then
221+
do_config_backup
222+
inform "Adding $CONFIG_LINE to $CONFIG\n"
223+
sed -i "s/^#$CONFIG_LINE/$CONFIG_LINE/" $CONFIG
224+
if ! grep -q "^$CONFIG_LINE" $CONFIG; then
225+
printf "$CONFIG_LINE\n" >> $CONFIG
226+
fi
227+
fi
228+
done
229+
230+
if [ -d "examples" ]; then
231+
if confirm "Would you like to copy examples to $RESOURCES_DIR?"; then
232+
inform "Copying examples to $RESOURCES_DIR"
233+
cp -r examples/ $RESOURCES_DIR
234+
echo "rm -r $RESOURCES_DIR" >> $UNINSTALLER
235+
success "Done!"
236+
fi
237+
fi
238+
239+
printf "\n"
240+
241+
if [ -f "/usr/bin/pydoc" ]; then
242+
printf "Generating documentation.\n"
243+
pydoc -w $LIBRARY_NAME > /dev/null
244+
if [ -f "$LIBRARY_NAME.html" ]; then
245+
cp $LIBRARY_NAME.html $RESOURCES_DIR/docs.html
246+
rm -f $LIBRARY_NAME.html
247+
inform "Documentation saved to $RESOURCES_DIR/docs.html"
248+
success "Done!"
249+
else
250+
warning "Error: Failed to generate documentation."
251+
fi
252+
fi
253+
254+
success "\nAll done!"
255+
inform "If this is your first time installing you should reboot for hardware changes to take effect.\n"
256+
inform "Find uninstall steps in $UNINSTALLER\n"

0 commit comments

Comments
 (0)