Commit 1af257e5 authored by Leo Pound Singer's avatar Leo Pound Singer

Make wheel building a lot simpler by integrating with autotools

Also, include installed Python scripts in the wheel.
parent 36bac6df
......@@ -7,6 +7,7 @@
.dirstamp
/Makefile
/Makefile.in
/wheel/Makefile.in
/_build/
/_inst/
/index.html
......@@ -27,3 +28,6 @@ lalsuite-user-env.fish
lalsuite-user-env.sh
lalsuite-user-env.shell
tags
/wheel/build/
/wheel/destdir/
/wheel/setup.py
......@@ -514,22 +514,15 @@ nightly:macos:
image: containers.ligo.org/lscsoft/lalsuite-manylinux:master
stage: nightly
script:
# Build and install LALSuite
- PYPREFIX=/opt/python/$(echo ${CI_JOB_NAME} | sed 's/.*:\(.*\)-manylinux1/\1/')
# Build wheel
- ./00boot
- VERS=$(./configure --version | sed -n 's/LALSuite configure \(.*\)/\1/p')
# FIXME: laldetchar depends on glib >= 2.14, too new for manylinux1
- ./configure PYTHON=${PYPREFIX}/bin/python --enable-swig-python
--disable-laldetchar
# FIXME: laldetchar depends on glib >= 2.14, too new for manylinux1
- make -j4 install pyexecdir=$(pwd)/pyinst
# Build wheel
- pushd pyinst
- echo -e '[metadata]\nversion = '${VERS} > setup.cfg
- cp ../gnuscripts/wheel_setup.py setup.py
- ${PYPREFIX}/bin/python setup.py bdist_wheel -d ../dist
- popd
- make -j4 wheel
# Bundle and fix up dependent shared libraries
- auditwheel repair dist/*
- auditwheel repair wheel/*.whl
# Test
- ${PYPREFIX}/bin/virtualenv test
- source test/bin/activate
......@@ -555,19 +548,12 @@ nightly:macos:
- virtualenv-${PYVERS} env
- source env/bin/activate
- pip install -q git+https://github.com/lpsinger/delocate@fix-duplicate-libs glob2 numpy==1.7.0
# Build and install LALSuite
- ./00boot
- VERS=$(./configure --version | sed -n 's/LALSuite configure \(.*\)/\1/p')
- ./configure --enable-swig-python --prefix=$(pwd)/inst PYTHON=$(which python${PYVERS})
- make -j4 install pyexecdir=$(pwd)/pyinst
# Build wheel
- pushd pyinst
- echo -e '[metadata]\nversion = '${VERS} > setup.cfg
- cp ../gnuscripts/wheel_setup.py setup.py
- python setup.py bdist_wheel -d ../dist
- popd
- ./00boot
- ./configure --enable-swig-python PYTHON=$(which python${PYVERS})
- make -j4 wheel
# Bundle and fix up dependent shared libraries
- delocate-wheel -v -w wheelhouse dist/*.whl
- delocate-wheel -v -w wheelhouse wheel/*.whl
# Test
- virtualenv-${PYVERS} test
- source test/bin/activate
......
......@@ -6,7 +6,10 @@ include $(top_srcdir)/gnuscripts/lalsuite_top.am
ACLOCAL_AMFLAGS = -I gnuscripts
SUBDIRS = @subdirs@
SUBDIRS = @subdirs@ wheel
wheel:
$(MAKE) -C wheel wheel
# Override automake's default rule for rebuilding aclocal.m4, to ensure that
# ./configure is successfully recreated after certain build system changes which
......@@ -20,15 +23,15 @@ $(ACLOCAL_M4): $(am__aclocal_m4_deps)
$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
$(SHELL) $(top_srcdir)/configure $(ac_configure_args)
.PHONY: cscopelist-subdirs
.PHONY: cscopelist-subdirs wheel
cscopelist-am: cscopelist-subdirs
cscopelist-subdirs:
for subdir in $(SUBDIRS); do \
for subdir in @subdirs@; do \
sed "s|^|$${subdir}/|" $${subdir}/cscope.files >> $(top_builddir)/cscope.files; \
done
user_environment = \
`for dir in $(SUBDIRS); do printf 'source %s; ' "$(sysconfdir)/$${dir}-user-env"; done` \
`for dir in @subdirs@; do printf 'source %s; ' "$(sysconfdir)/$${dir}-user-env"; done` \
$(END_OF_LIST)
BUILT_SOURCES += $(PACKAGE)rc
......
......@@ -4,7 +4,7 @@ AC_CONFIG_SRCDIR([configure.ac])
AC_CONFIG_AUX_DIR([gnuscripts])
AC_CONFIG_MACRO_DIR([gnuscripts])
AC_PREFIX_DEFAULT(["`pwd`/_inst"])
AC_CONFIG_FILES([Makefile])
AC_CONFIG_FILES([Makefile wheel/Makefile wheel/setup.py])
AM_INIT_AUTOMAKE([ \
1.11 \
foreign \
......@@ -25,6 +25,9 @@ AM_SILENT_RULES([yes])
AC_PROG_AWK
AC_PROG_SED
LALSUITE_ENABLE_NIGHTLY
LALSUITE_CHECK_PYTHON([2.6])
# provide LAL library enable/disable options
LALSUITE_ENABLE_ALL_LAL
lal=true
......
# FIXME: this command overrides ${prefix}. If you have run `make install`
# beforehand, you may need to run `make clean` for the wheel to build
# successfully.
wheel: setup.py
$(MAKE) prefix=$(abs_builddir)/build/inst -C .. install-strip && \
$(PYTHON) setup.py bdist_wheel -d .
clean-local:
rm -rf build destdir *.whl
EXTRA_DIST = setup.py.in
......@@ -17,25 +17,74 @@ To install, simply run::
$ pip install lalsuite
"""
import os
import re
from string import Template
import shutil
import tempfile
from setuptools import Extension, find_packages, setup
from setuptools.command.build_ext import build_ext as _build_ext
from distutils.command.build_scripts import build_scripts as _build_scripts
# Recursive globbing like in Python 3.5
from glob2 import glob
# These variables come from automake.
subst = dict(prefix=os.path.abspath('build/inst'))
subst['exec_prefix'] = Template('@exec_prefix@').substitute(**subst)
LIBEXECDIR = Template('@libexecdir@').substitute(**subst)
PYTHONDIR = Template('@pythondir@').substitute(**subst)
BASE_VERSION = '@BASE_VERSION@'
NIGHTLY_VERSION = '@NIGHTLY_VERSION@'
if NIGHTLY_VERSION:
VERSION = BASE_VERSION + '.' + NIGHTLY_VERSION
else:
VERSION = BASE_VERSION
class build_ext(_build_ext):
"""Override setuptools build_ext: just copy pre-built modules."""
def build_extension(self, ext):
src = ext.name.replace('.', '/') + '.so'
src = os.path.join(PYTHONDIR, ext.name.replace('.', '/') + '.so')
dst = self.get_ext_fullpath(ext.name)
self.copy_file(src, dst)
class build_scripts(_build_scripts):
"""Override setuptools install_scripts: strip the .py extensions and
add the shebang lines."""
def run(self):
old_scripts = self.scripts[:]
new_scripts = []
self.mkpath(self.build_dir)
tmpdir = tempfile.mkdtemp(dir=self.build_dir)
try:
for old_script in old_scripts:
base, ext = os.path.splitext(old_script)
if ext == '.py':
new_script = os.path.join(tmpdir, base)
with open(new_script, 'wb') as outfile:
outfile.write(b'#!python\n')
with open(old_script, 'rb') as infile:
shutil.copyfileobj(infile, outfile)
else:
new_script = old_script
new_scripts.append(new_script)
self.scripts = new_scripts
_build_scripts.run(self)
self.scripts = old_scripts
finally:
shutil.rmtree(tmpdir)
setup(
name='lalsuite',
license='GPL-2+',
version=VERSION,
description=__doc__.strip().split('\n')[0],
long_description='\n'.join(__doc__.strip().split('\n')[1:]).strip(),
url='https://git.ligo.org/lscsoft/lalsuite',
......@@ -55,10 +104,13 @@ setup(
'Programming Language :: Python :: 3.6',
'Topic :: Scientific/Engineering :: Astronomy',
'Topic :: Scientific/Engineering :: Physics'],
cmdclass={'build_ext': build_ext},
packages=find_packages(),
package_data={'': ['*.so']},
ext_modules=[Extension(filename.replace('.so', '').replace('/', '.'), [])
for filename in glob('lal*/**/*.so')],
cmdclass={'build_ext': build_ext, 'build_scripts': build_scripts},
package_dir={'': PYTHONDIR},
packages=find_packages(PYTHONDIR),
scripts=glob(LIBEXECDIR + '/**/*.py'),
ext_modules=[Extension(os.path.relpath(filename, PYTHONDIR)
.replace('.so', '')
.replace('/', '.'), [])
for filename in glob(PYTHONDIR + '/**/*.so')],
install_requires=['numpy>=1.7']
)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment