Skip to content

Commit

Permalink
support building Debian source / binary packages
Browse files Browse the repository at this point in the history
  • Loading branch information
Montellese committed Sep 3, 2021
1 parent 1049450 commit 436ad04
Show file tree
Hide file tree
Showing 12 changed files with 152 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ __pycache__/
.Python
build/
develop-eggs/
deb_dist/
dist/
downloads/
eggs/
Expand Down
6 changes: 5 additions & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ licenseheaders = "*"
pipenv-setup = "*"
pylint = "*"
setuptools = "*"
stdeb = {version="*", markers="sys_platform == 'linux'"}
twine = "*"
wheel = "*"

Expand All @@ -25,7 +26,10 @@ python_version = "3.8"
[scripts]
build = "bash ./scripts/build.sh"
build_check = "twine check dist/*"
clean = "rm -rf .eggs build dist smartmeter_datacollector.egg-info"
build_srcdeb = "bash ./scripts/build_srcdeb.sh"
build_deb = "bash ./scripts/build_deb.sh"
clean = "rm -rf .eggs build dist deb_dist smartmeter_datacollector.egg-info"
debianize = "bash ./scripts/debianize.sh"
format_check = "autopep8 --diff -r --aggressive smartmeter_datacollector/"
format = "autopep8 --in-place -r --aggressive smartmeter_datacollector/"
isort = "isort ."
Expand Down
10 changes: 9 additions & 1 deletion Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
smartmeter-datacollector (0.4.1-1) unstable; urgency=low

* support building Debian source and binary packages for distribution on Debian Buster amd64 and raspios

-- Supercomputing Systems AG <[email protected]> Sun, 29 Aug 2021 21:04:55 +0000
1 change: 1 addition & 0 deletions debian/compat
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
9
21 changes: 21 additions & 0 deletions debian/control
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Source: smartmeter-datacollector
Maintainer: Supercomputing Systems AG <[email protected]>
Section: python
Priority: optional
Build-Depends: python3-setuptools, python3-all, debhelper (>= 9)
Standards-Version: 3.9.1
Homepage: https://github.com/scs/smartmeter-datacollector

Package: python3-smartmeter-datacollector
Architecture: all
Depends: ${misc:Depends}, ${python3:Depends}
Description: Smart Meter Data Collector
# Smart Meter Data Collector
.
<p align="center">
<a href="LICENSE"><img alt="License: GPL-2.0-only" src="https://img.shields.io/badge/license-GPLv2-blue.svg"></a> <a href="https://github.com/scs/smartmeter-datacollector/pulls"><img alt="Pull Requests Welcome" src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg"></a> <a href="https://github.com/scs/smartmeter-datacollector/pulls"><img alt="Contributions Welcome" src="https://img.shields.io/badge/contributions-welcome-brightgreen.svg"></a>
<br />
<img alt="Python Code Checks" src="https://github.com/scs/smartmeter-datacollector/actions/workflows/python-code-checks.yml/badge.svg?branch=master"> <a href="https://pypi.org/project/smartmeter-datacollector/"><img alt="PyPI - Python Version" src="https://img.shields.io/pypi/pyversions/smartmeter-datacollector"></a>
</p>
.

19 changes: 19 additions & 0 deletions debian/rules
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/make -f

%:
dh $@ --with python3 --buildsystem=python_distutils

override_dh_auto_clean:
python3 setup.py clean -a
find . -name \*.pyc -exec rm {} \;

override_dh_auto_build:
python3 setup.py build --force

override_dh_auto_install:
python3 setup.py install --force --root=debian/python3-smartmeter-datacollector --no-compile -O0 --install-layout=deb --prefix=/usr
rm -rf debian/python-smartmeter-datacollector/trash

override_dh_python2:
dh_python2 --no-guessing-versions

1 change: 1 addition & 0 deletions debian/source/format
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.0 (quilt)
1 change: 1 addition & 0 deletions debian/source/options
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
extend-diff-ignore="\.egg-info$"
7 changes: 7 additions & 0 deletions scripts/build_deb.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

# exit on any error
set -e

# re-use build_srcdeb.sh
pipenv run build_srcdeb full
66 changes: 66 additions & 0 deletions scripts/build_srcdeb.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/usr/bin/env bash

# exit on any error
set -e

BUILD_TYPE=source
if [[ "$#" -eq 1 ]]; then
BUILD_TYPE=$1
fi

PACKAGE_NAME=smartmeter-datacollector

CWD=$PWD
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
WORK_DIR=${SCRIPT_DIR}/..

OUTPUT_DIR=${WORK_DIR}/deb_dist
DIST_DIR=${WORK_DIR}/dist

# Delete previously built Debian distribution
echo -n "Cleaning up from previous builds.."
rm -rf ${OUTPUT_DIR} ${DIST_DIR}

# remove the source Debian package from the root folder
rm -f ${WORK_DIR}/${PACKAGE_NAME}-*.tar.gz
echo "..done"

# build the Python source distribution package
echo -n "Building Python source distribution package.."
pipenv run build > /dev/null 2>&1
echo "..done"

# prepare the output directory
mkdir -p ${OUTPUT_DIR}

# get and extract the Python source distribution package
echo -n "Extracting the Python source distribution package.."
cp ${DIST_DIR}/${PACKAGE_NAME}-*.tar.gz ${OUTPUT_DIR}
tar -xf ${OUTPUT_DIR}/${PACKAGE_NAME}-*.tar.gz -C ${OUTPUT_DIR}
echo "..done"

PACKAGE_DIR=$(find ${OUTPUT_DIR} -type d -name "${PACKAGE_NAME}-*")

# go into the output directory
cd ${OUTPUT_DIR}

# rename <package name>-<version>.tar.gz to <package name>_<version>.orig.tar.gz
echo -n "Preparing the Debian source package.."
PACKAGE_FILENAME_FULL=$(find . -type f -name "${PACKAGE_NAME}-*.tar.gz")
PACKAGE_FILENAME="${PACKAGE_FILENAME_FULL%.tar.gz}"
PACKAGE_FILENAME=$(echo ${PACKAGE_FILENAME} | sed "s/${PACKAGE_NAME}-\(.*\)$/${PACKAGE_NAME}_\1/")
mv ${PACKAGE_FILENAME_FULL} ${PACKAGE_FILENAME}.orig.tar.gz

# copy the prepared "debian" directory
cp -R ${WORK_DIR}/debian ${PACKAGE_DIR}/
echo "..done"

# build the Debian source package
echo -n "Building the Debian package (${BUILD_TYPE}).."
cd ${PACKAGE_DIR}/
dpkg-buildpackage --build=${BUILD_TYPE} -rfakeroot -sa -us -uc > /dev/null 2>&1
echo "..done"

cd ${CWD}

echo "SUCCESS: Debian package (${BUILD_TYPE}) has been successfully built at ${OUTPUT_DIR}/"
16 changes: 16 additions & 0 deletions scripts/debianize.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash

# exit on any error
set -e

# delete previously generated debian directory
rm -rf debian

# create the debian directory
python setup.py \
--command-packages=stdeb.command debianize \
--with-python2=false \
--with-python3=true \
--no-python2-scripts=true

echo "SUCCESS: Project has been successfully debianized at debian/"

0 comments on commit 436ad04

Please sign in to comment.