Skip to content

Commit

Permalink
Rewrite Debian/Ubuntu packaging
Browse files Browse the repository at this point in the history
To avoid having to deal with the setup.py install vagueries when installing python for Debian packaging, let pybuild take care of the building and installing of python. Rewrite debian/rules to make use of debhelper for as much as possible and minimize hackery. Also remove Debian-packaging-specific hacks in Makefile.in

The recipe we are now following is to install everything in debian/tmp (instead of straight into the debian/<package>/ directories), and divide the resulting files up over the packages using debian/<package.install> files. Try to clean up some Lintin errors and warnings in the process.

Note that we are still using distutils in the setup.py files and calling
"python setup.py install" which are both deprecated. Only this
combination appears to not be hit by pypa/pip#10978
so just leaving as is.

Also introduces:
* testing on both Focal and Jammy
* fix intermittent test failure in build process
  • Loading branch information
stephankramer committed Oct 31, 2022
1 parent e2a52a3 commit b096ac3
Show file tree
Hide file tree
Showing 18 changed files with 91 additions and 185 deletions.
24 changes: 20 additions & 4 deletions .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,26 @@ on:
- main

jobs:
Ubuntu-Focal:
ubuntu-local-builds:
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
name: [ "Local Build Focal", "Local Build Jammy" ]
include:

- name: "Local Build Focal"
release: focal
python: python3.8

- name: "Local Build Jammy"
release: jammy
python: python3.10


container:
image: ubuntu:focal
image: ubuntu:${{ matrix.release }}

steps:
- name: Check Out Repo
Expand All @@ -22,7 +38,7 @@ jobs:
run: |
echo "Europe/London" > /etc/timezone
apt-get -y update
DEBIAN_FRONTEND=noninteractive apt-get -y install gfortran g++ python3-setuptools python3-all-dev debhelper dh-python texlive python3-junit.xml
DEBIAN_FRONTEND=noninteractive apt-get -y install gfortran g++ python3-setuptools python3-pip python3-all-dev debhelper dh-python texlive python3-junit.xml
- name: Configuring
run: ./configure --prefix=/tmp
Expand All @@ -37,7 +53,7 @@ jobs:

- name: Testing
env:
PYTHONPATH: /tmp/lib/python3.8/site-packages
PYTHONPATH: /tmp/lib/${{ matrix.python }}/site-packages
LD_LIBRARY_PATH: /tmp/lib
run: |
cd python
Expand Down
15 changes: 5 additions & 10 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ VPATH = src/
.cpp.lo:
./libtool --mode=compile --tag=CXX $(CXX) $(CXXFLAGS) -c $<

default: libspud.la build-diamond
default: libspud.la build-diamond build-pyspud

libspud.la: $(OBJS)
./libtool --mode=link --tag=FC $(FC) $(FCFLAGS) -o $(LIB) $(OBJS) $(LIBS) -rpath @prefix@/lib
Expand All @@ -61,6 +61,9 @@ libspud.la: $(OBJS)
build-diamond:
cd diamond; python3 setup.py build; cd ..

build-pyspud: libspud.la
cd python; python3 setup.py build; cd ..

test: unittest

unittest: libspud.la
Expand Down Expand Up @@ -95,21 +98,13 @@ install-spudtools:
@INSTALL@ -m644 schema/spud_base.rng $(DESTDIR)@prefix@/share/spud

install-diamond:
cd diamond; python3 setup.py install --prefix=$(DESTDIR)@prefix@; cd ..
cd diamond; python3 setup.py install --prefix=$(DESTDIR)@prefix@; cd ..

install-pyspud:
ifeq ($(origin BUILDING_DEBIAN),undefined)
cd python; python3 setup.py install --prefix=$(DESTDIR)@prefix@; cd ..
else
cd python; for python in $(shell py3versions -r); do $$python setup.py install --prefix=$(DESTDIR)@prefix@ --install-layout=deb; done; cd ..
endif

install-dxdiff:
ifeq ($(origin BUILDING_DEBIAN),undefined)
cd dxdiff; python3 setup.py install --prefix=$(DESTDIR)@prefix@; cd ..
else
cd dxdiff; for python in $(shell py3versions -r); do $$python setup.py install --prefix=$(DESTDIR)@prefix@ --install-layout=deb; done; cd ..
endif

clean:
@cd doc; $(MAKE) clean
Expand Down
6 changes: 6 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
spud (1.2) UNRELEASED; urgency=medium

* Rewrite Debian/Ubuntu packaging

-- Stephan Kramer <s.kramer@imperial.ac.uk> Tue, 25 Oct 2022 12:12:05 +0100

spud (1.1.8) buster; urgency=medium

* Change to python3 and remove python(2) dependecies
Expand Down
2 changes: 1 addition & 1 deletion debian/compat
Original file line number Diff line number Diff line change
@@ -1 +1 @@
9
11
16 changes: 8 additions & 8 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ Source: spud
Maintainer: The ICOM team <patrick.farrell@imperial.ac.uk>
Uploaders: David Ham <david.ham@imperial.ac.uk>
Section: science
Priority: extra
Build-Depends: gfortran (>=4.2), g++ (>=4.2), python3-setuptools (>= 0.6b3-1), python3-all-dev (>= 2.3.5-11), debhelper (>= 5.0.38), dh-python, texlive
Priority: optional
Build-Depends: gfortran (>=4.2), g++ (>=4.2), python3-setuptools (>= 39), python3-pip, python3-all-dev , debhelper (>= 5.0.38), dh-python, texlive
Standards-Version: 3.8.0
XS-Python-Version: >= 2.5
X-Python3-Version: >= 3.6

Package: spud-diamond
Architecture: all
Expand All @@ -16,7 +16,7 @@ Conflicts: python-diamond, diamond
Replaces: python-diamond
Provides: ${python:Provides}
X-Python-Version: ${python:Versions}
Description: A schema-driven interface for writing XML documents
Description: Schema-driven interface for writing XML documents
Diamond is a dynamic schema-driven graphical user interface for writing
XML documents. The interface is automatically generated from a schema
written in RELAX NG describing an XML language. The interface is optimised
Expand All @@ -29,7 +29,7 @@ Depends: ${shlibs:Depends}, spudtools, libtinyxml-dev, ${misc:Depends}
Recommends: spud-diamond
Section: libdevel
Suggests:
Description: An automatic options system for scientific models.
Description: Automatic options system for scientific models.
Spud is an automatic options system which reads an xml options file
into a dictionary for immediate access from within the model. The xml
file is generated using a spud-compatible RELAX NG schema and a
Expand All @@ -43,7 +43,7 @@ Conflicts: libspud-dev (<<1.0.6)
Replaces: libspud-dev (<<1.0.6)
Section: science
Suggests:
Description: An automatic options system for scientific models.
Description: Automatic options system for scientific models.
Spud is an automatic options system which reads an xml options file
into a dictionary for immediate access from within the model. The xml
file is generated using a spud-compatible RELAX NG schema and a
Expand All @@ -58,7 +58,7 @@ Replaces: python-spud
Architecture: any
X-Python-Version: ${python:Versions}
Depends: libspud-dev (= ${binary:Version}), ${python3:Depends}, ${shlibs:Depends}, ${misc:Depends}
Description: An automatic options system for scientific models (python interface).
Description: Automatic options system for scientific models (python interface).
Spud is an automatic options system which reads an xml options file
into a dictionary for immediate access from within the model. The xml
file is generated using a spud-compatible RELAX NG schema and a
Expand All @@ -72,6 +72,6 @@ Replaces: python-dxdiff
Architecture: all
X-Python-Version: ${python:Versions}
Depends: ${python3:Depends}, ${misc:Depends}
Description: An XML aware diff tool.
Description: XML aware diff tool.
DXdiff (Diamond Xml diff) is an XML aware diff tool for finding edit scripts
between two XML files.
1 change: 0 additions & 1 deletion debian/install.spud-diamond

This file was deleted.

2 changes: 0 additions & 2 deletions debian/libspud-dev.dirs

This file was deleted.

2 changes: 2 additions & 0 deletions debian/libspud-dev.install
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
usr/lib/libspud*
usr/include/spud*
2 changes: 0 additions & 2 deletions debian/postinst

This file was deleted.

2 changes: 2 additions & 0 deletions debian/python3-dxdiff.install
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
usr/lib/python3*/dist-packages/dxdiff*
usr/bin/dxdiff
1 change: 1 addition & 0 deletions debian/python3-spud.install
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
usr/lib/python3*/dist-packages/libspud*
157 changes: 20 additions & 137 deletions debian/rules
Original file line number Diff line number Diff line change
@@ -1,139 +1,22 @@
#!/usr/bin/make -f

PACKAGE_NAME=spud-diamond
MODULE_NAME=diamond
DEB_UPSTREAM_VERSION=1.0

PYVERS=$(shell py3versions -dv)

# These are used for cross-compiling and for saving the configure script
# from having to guess our platform (since we know it already)
DEB_HOST_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_BUILD_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)


config.status: configure
dh_testdir
# Add here commands to configure the package.

ifneq "$(wildcard /usr/share/misc/config.sub)" ""
cp -f /usr/share/misc/config.sub config.sub
endif
ifneq "$(wildcard /usr/share/misc/config.guess)" ""
cp -f /usr/share/misc/config.guess config.guess
endif
./configure --host=$(DEB_HOST_GNU_TYPE) --build=$(DEB_BUILD_GNU_TYPE) --prefix=/usr --mandir=\$${prefix}/share/man --infodir=\$${prefix}/share/info CFLAGS="$(CFLAGS)" LDFLAGS="-Wl,-z,defs"

build-libspud: build-libspud-stamp
build-libspud-stamp:
touch $@

build-libspud: config.status
dh_testdir

# Add here commands to compile the package.
$(MAKE) libspud.la
#docbook-to-man debian/fluidity.sgml > fluidity.1
$(MAKE) doc


build-spud-diamond: build-spud-diamond-stamp
build-spud-diamond-stamp: $(PYVERS:%=build-python%)
touch $@
build-python%: config.status
# Force setuptools, but reset sys.argv[0] to 'setup.py' because setup.py files expect that.
cd diamond;python$* -c "import setuptools,sys;f='setup.py';sys.argv[0]=f;exec(open(f,'r').read(),{'__file__':f,'__name__':'__main__'})" build
touch $@
clean:
dh_testdir
dh_testroot
rm -f *-stamp
rm -rf dist build
-find -name '*.py[co]' | xargs rm -f
$(MAKE) clean || true
# find . -name *.pyc -exec rm {} \;
dh_clean

install-libspud: build-libspud install-prereq
$(MAKE) install-libspud DESTDIR=$(CURDIR)/debian/libspud-dev
rm -f $(CURDIR)/debian/libspud-dev/usr/include/tiny*h

install-spudtools: install-prereq
$(MAKE) install-spudtools DESTDIR=$(CURDIR)/debian/spudtools

install-spud-diamond: build-spud-diamond install-prereq $(PYVERS:%=install-python%)
dh_install
install-prereq:
dh_testdir
dh_testroot
dh_clean -k
dh_installdirs -a

install-python%:
# Force setuptools, but reset sys.argv[0] to 'setup.py' because setup.py files expect that.
cd diamond;python$* -c "import setuptools,sys;f='setup.py';sys.argv[0]=f;exec(open(f,'r').read(),{'__file__':f,'__name__':'__main__'})" install --prefix=/usr --no-compile --single-version-externally-managed --root=$(CURDIR)/debian/${PACKAGE_NAME}
if [ -d debian/${PACKAGE_NAME}/usr/lib/python$*/site-packages/${MODULE_NAME}-${DEB_UPSTREAM_VERSION}.egg-info ]; then \
mv debian/${PACKAGE_NAME}/usr/lib/python$*/site-packages debian/${PACKAGE_NAME}/usr/lib/python$*/dist-packages ; \
mv debian/${PACKAGE_NAME}/usr/lib/python$*/dist-packages/${MODULE_NAME}-${DEB_UPSTREAM_VERSION}.egg-info debian/${PACKAGE_NAME}/usr/lib/python$*/dist-packages/${MODULE_NAME}.egg-info ; \
elif [ -d debian/${PACKAGE_NAME}/usr/lib/python$*/site-packages/${MODULE_NAME}-${DEB_UPSTREAM_VERSION}-py$*.egg-info ]; then \
mv debian/${PACKAGE_NAME}/usr/lib/python$*/site-packages debian/${PACKAGE_NAME}/usr/lib/python$*/dist-packages ; \
mv debian/${PACKAGE_NAME}/usr/lib/python$*/dist-packages/${MODULE_NAME}-${DEB_UPSTREAM_VERSION}-py$*.egg-info debian/${PACKAGE_NAME}/usr/lib/python$*/dist-packages/${MODULE_NAME}.egg-info ; \
else \
echo "Failed to locate python egg, was it built correctly?" && exit 1 ; \
fi

install-pyspud:
$(MAKE) install-pyspud DESTDIR=$(CURDIR)/debian/python3-spud BUILDING_DEBIAN=yes

install-dxdiff:
$(MAKE) install-dxdiff DESTDIR=$(CURDIR)/debian/python3-dxdiff

binary-arch: build-libspud install-libspud install-spudtools install-pyspud
dh_testdir
dh_testroot
dh_installchangelogs
dh_installdocs
dh_installexamples
# dh_install
# dh_installmenu
# dh_installdebconf
# dh_installlogrotate
# dh_installemacsen
# dh_installpam
# dh_installmime
dh_python3
# dh_installinit
# dh_installcron
# dh_installinfo
dh_installman
dh_link
dh_strip
dh_compress
dh_fixperms
# dh_perl
dh_makeshlibs
dh_installdeb
dh_shlibdeps
dh_gencontrol
dh_md5sums
dh_builddeb

binary-indep: build-spud-diamond install-spud-diamond build-libspud install-libspud install-spudtools install-dxdiff
dh_testdir -i
dh_testroot -i
dh_python3 -i
dh_installdocs -i
dh_installdirs -i
dh_installexamples -i
dh_strip -i
dh_compress -i -X.py
dh_fixperms -i
dh_installdeb -i
dh_gencontrol -i
dh_md5sums -i
dh_builddeb -i

binary: binary-indep binary-arch


.PHONY: build clean binary-indep binary-arch binary-spud-diamond binary-libspud install configure
#export DH_VERBOSE=1
export BUILDING_DEBIAN=yes
PYTHON_DIRS=diamond dxdiff python

# standard rule
%:
dh $@ --with=python3

# instead of calling make/make default to build
# call "make libspud.la" separately and use pybuild for building the python packages
override_dh_auto_build:
dh_auto_build -- libspud.la
for i in $(PYTHON_DIRS); do PYBUILD_NAME=$$i; dh_auto_build --buildsystem=pybuild --sourcedir=$$i; done

# instead of a single "make install" into debian/tmp
# only use makefile for install-libspud and install-spudtools
# and use pybuild to install python packages
override_dh_auto_install:
make install-libspud install-spudtools DESTDIR=debian/tmp/
for i in $(PYTHON_DIRS); do PYBUILD_NAME=$$i; dh_auto_install --buildsystem=pybuild --sourcedir=$$i; done
1 change: 1 addition & 0 deletions debian/source/format
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.0 (native)
3 changes: 3 additions & 0 deletions debian/spud-diamond.install
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
usr/lib/python3*/dist-packages/diamond*
usr/bin/diamond
usr/share/diamond*
1 change: 0 additions & 1 deletion debian/spudtools.dirs

This file was deleted.

2 changes: 2 additions & 0 deletions debian/spudtools.install
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
usr/bin/spud*
usr/share/spud*
Loading

0 comments on commit b096ac3

Please sign in to comment.