diff --git a/examples/wave_driver.py b/examples/wave_driver.py index 800f566..0a7789f 100755 --- a/examples/wave_driver.py +++ b/examples/wave_driver.py @@ -7,6 +7,7 @@ import math from itertools import tee from time import sleep +from sys import exit try: import numpy diff --git a/library/piglow.py b/library/piglow.py index 3409d93..b05bd49 100644 --- a/library/piglow.py +++ b/library/piglow.py @@ -1,11 +1,13 @@ import atexit import time +from sys import exit try: import sn3218 except ImportError: exit("This library requires the sn3218 module\nInstall with: sudo pip install sn3218") +__version__ = '1.2.3' sn3218.enable() sn3218.enable_leds(0b111111111111111111) diff --git a/library/test/test.py b/library/test/test.py index f6d1b9b..e79269b 100755 --- a/library/test/test.py +++ b/library/test/test.py @@ -6,6 +6,7 @@ # Once running you'll need to press ctrl-C to cancel stop the script import time +from sys import exit, version_info try: from smbus import SMBus diff --git a/packaging/debian/control b/packaging/debian/control index 68093f2..48b2695 100644 --- a/packaging/debian/control +++ b/packaging/debian/control @@ -2,7 +2,7 @@ Source: piglow Maintainer: Phil Howard Homepage: https://github.com/pimoroni/piglow Section: python -Priority: optional +Priority: extra Build-Depends: debhelper (>= 9.0.0), dh-python, python-all (>= 2.7), python-setuptools, python3-all (>= 3.4), python3-setuptools Standards-Version: 3.9.6 X-Python-Version: >= 2.7 diff --git a/packaging/makeall.sh b/packaging/makeall.sh new file mode 100755 index 0000000..abca395 --- /dev/null +++ b/packaging/makeall.sh @@ -0,0 +1,165 @@ +#!/bin/bash + +# script control variables + +reponame="" # leave this blank for auto-detection +libname="" # leave this blank for auto-detection +packagename="" # leave this blank for auto-selection + +debianlog="debian/changelog" +debcontrol="debian/control" +debcopyright="debian/copyright" +debrules="debian/rules" +debreadme="debian/README" + +debdir="$(pwd)" +rootdir="$(dirname $debdir)" +libdir="$rootdir/library" + +FLAG=false + +# function define + +success() { + echo "$(tput setaf 2)$1$(tput sgr0)" +} + +inform() { + echo "$(tput setaf 6)$1$(tput sgr0)" +} + +warning() { + echo "$(tput setaf 1)$1$(tput sgr0)" +} + +newline() { + echo "" +} + +# assessing repo and library variables + +if [ -z "$reponame" ] || [ -z "$libname" ]; then + inform "detecting reponame and libname..." +else + inform "using reponame and libname overrides" +fi + +if [ -z "$reponame" ]; then + if [[ $rootdir == *"python"* ]]; then + repodir="$(dirname $rootdir)" + reponame="$(basename $repodir)" + else + repodir="$rootdir" + reponame="$(basename $repodir)" + fi + reponame=$(echo "$reponame" | tr "[A-Z]" "[a-z]") +fi + +if [ -z "$libname" ]; then + cd "$libdir" + libname=$(grep "name" setup.py | tr -d "[:space:]" | cut -c 7- | rev | cut -c 3- | rev) + libname=$(echo "$libname" | tr "[A-Z]" "[a-z]") && cd "$debdir" +fi + +if [ -z "$packagename" ]; then + packagename="$libname" +fi + +echo "reponame is $reponame and libname is $libname" +echo "output packages will be python-$packagename and python3-$packagename" + +# checking generating changelog file + +./makelog.sh +version=$(head -n 1 "$libdir/CHANGELOG.txt") +echo "building $libname version $version" + +# checking debian/changelog file + +inform "checking debian/changelog file..." + +if ! head -n 1 $debianlog | grep "$libname" &> /dev/null; then + warning "library not mentioned in header!" && FLAG=true +elif head -n 1 $debianlog | grep "UNRELEASED"; then + warning "this changelog is not going to generate a release!" + warning "change distribution to 'stable'" && FLAG=true +fi + +# checking debian/copyright file + +inform "checking debian/copyright file..." + +if ! grep "^Source" $debcopyright | grep "$reponame" &> /dev/null; then + warning "$(grep "^Source" $debcopyright)" && FLAG=true +fi + +if ! grep "^Upstream-Name" $debcopyright | grep "$libname" &> /dev/null; then + warning "$(grep "^Upstream-Name" $debcopyright)" && FLAG=true +fi + +# checking debian/control file + +inform "checking debian/control file..." + +if ! grep "^Source" $debcontrol | grep "$libname" &> /dev/null; then + warning "$(grep "^Source" $debcontrol)" && FLAG=true +fi + +if ! grep "^Homepage" $debcontrol | grep "$reponame" &> /dev/null; then + warning "$(grep "^Homepage" $debcontrol)" && FLAG=true +fi + +if ! grep "^Package: python-$packagename" $debcontrol &> /dev/null; then + warning "$(grep "^Package: python-" $debcontrol)" && FLAG=true +fi + +if ! grep "^Package: python3-$packagename" $debcontrol &> /dev/null; then + warning "$(grep "^Package: python3-" $debcontrol)" && FLAG=true +fi + +if ! grep "^Priority: extra" $debcontrol &> /dev/null; then + warning "$(grep "^Priority" $debcontrol)" && FLAG=true +fi + + +# checking debian/rules file + +inform "checking debian/rules file..." + +if ! grep "debian/python-$packagename" $debrules &> /dev/null; then + warning "$(grep "debian/python-" $debrules)" && FLAG=true +fi + +if ! grep "debian/python3-$packagename" $debrules &> /dev/null; then + warning "$(grep "debian/python3-" $debrules)" && FLAG=true +fi + +# checking debian/README file + +inform "checking debian/readme file..." + +if ! grep -e "$libname" -e "$reponame" $debreadme &> /dev/null; then + warning "README does not seem to mention product, repo or lib!" && FLAG=true +fi + +# summary of checks pre build + +if $FLAG; then + warning "Check all of the above and correct!" && exit 1 +else + inform "we're good to go... bulding!" +fi + +# building deb and final checks + +./makedeb.sh + +inform "running lintian..." +lintian -v $(find -name "python*$version*.deb") +lintian -v $(find -name "python3*$version*.deb") + +inform "checking signatures..." +gpg --verify $(find -name "*$version*changes") +gpg --verify $(find -name "*$version*dsc") + +exit 0 diff --git a/packaging/makedeb.sh b/packaging/makedeb.sh index 5b63fd3..84ba0e2 100755 --- a/packaging/makedeb.sh +++ b/packaging/makedeb.sh @@ -1,6 +1,6 @@ #!/bin/bash -gettools="yes" +gettools="no" setup="yes" cleanup="yes" pkgfiles=( "build" "changes" "deb" "dsc" "tar.xz" ) @@ -16,7 +16,7 @@ if [ $setup == "yes" ]; then cp -R ./debian/ ../library/ fi -cd ../library && debuild +cd ../library && debuild -aarmhf for file in ${pkgfiles[@]}; do mv ../*.$file ../packaging diff --git a/packaging/makelog.sh b/packaging/makelog.sh index c36bdd3..1055987 100755 --- a/packaging/makelog.sh +++ b/packaging/makelog.sh @@ -1,18 +1,82 @@ #!/bin/bash +# script control variables + +libname="" # leave this blank for auto-detection +sibname=() # name of sibling in packages list +versionwarn="yes" # set to anything but 'yes' to turn off warning + +debdir="$(pwd)" +rootdir="$(dirname $debdir)" +libdir="$rootdir/library" + mainlog="CHANGELOG" debianlog="debian/changelog" -pypilog="../library/CHANGELOG.txt" +pypilog="$libdir/CHANGELOG.txt" + +# function define + +success() { + echo "$(tput setaf 2)$1$(tput sgr0)" +} + +inform() { + echo "$(tput setaf 6)$1$(tput sgr0)" +} + +warning() { + echo "$(tput setaf 1)$1$(tput sgr0)" +} + +newline() { + echo "" +} # generate debian changelog cat $mainlog > $debianlog +inform "seeded debian changelog" # generate pypi changelog sed -e "/--/d" -e "s/ \*/\*/" \ -e "s/.*\([0-9].[0-9].[0-9]\).*/\1/" \ -e '/[0-9].[0-9].[0-9]/ a\ - -----' $mainlog | cat -s > $pypilog +-----' $mainlog | cat -s > $pypilog + +version=$(head -n 1 $pypilog) +inform "pypi changelog generated" + +# touch up version in setup.py file + +if [ -n $(grep version "$libdir/setup.py" &> /dev/null) ]; then + inform "touched up version in setup.py" + sed -i "s/'[0-9].[0-9].[0-9]'/'$version'/" "$libdir/setup.py" +else + warning "couldn't touch up version in setup, no match found" +fi + +# touch up version in lib or package siblings + +if [ -z "$libname" ]; then + cd "$libdir" + libname=$(grep "name" setup.py | tr -d "[:space:]" | cut -c 7- | rev | cut -c 3- | rev) + libname=$(echo "$libname" | tr "[A-Z]" "[a-z]") && cd "$debdir" + sibname+=( "$libname" ) +elif [ "$libname" != "package" ]; then + sibname+=( "$libname" ) +fi + +for sibling in ${sibname[@]}; do + if grep -e "__version__" "$libdir/$sibling.py" &> /dev/null; then + sed -i "s/__version__ = '[0-9].[0-9].[0-9]'/__version__ = '$version'/" "$libdir/$sibling.py" + inform "touched up version in $sibling.py" + elif grep -e "__version__" "$libdir/$sibling/__init__.py" &> /dev/null; then + sed -i "s/__version__ = '[0-9].[0-9].[0-9]'/__version__ = '$version'/" "$libdir/$sibling/__init__.py" + inform "touched up version in $sibling/__init__.py" + elif [ "$versionwarn" == "yes" ]; then + warning "couldn't touch up __version__ in $sibling, no match found" + fi +done exit 0