[sasmodels] 07/10: Precompile models into package

Stuart Prescott stuart at debian.org
Sun Dec 31 07:17:26 UTC 2017


This is an automated email from the git hooks/post-receive script.

stuart pushed a commit to branch master
in repository sasmodels.

commit 67a98225a9f342b3039f653295c3febd6c727a29
Author: Stuart Prescott <stuart at debian.org>
Date:   Sun Dec 31 00:16:39 2017 +1100

    Precompile models into package
---
 debian/compile_models                              | 10 +++++++
 debian/control                                     | 15 ++++++++++
 debian/patches/precompiled_path.patch              | 33 ++++++++++++++++++++++
 debian/patches/series                              |  2 ++
 debian/patches/setup-install-so.patch              | 20 +++++++++++++
 debian/rules                                       | 25 ++++++++++++----
 debian/sasmodels-private-libs.install              |  1 +
 debian/tests/control                               | 11 ++++++++
 debian/tests/python-sasmodels                      |  5 +++-
 .../{python-sasmodels => python-sasmodels-opencl}  |  5 ++--
 debian/tests/python3-sasmodels                     |  5 +++-
 ...{python3-sasmodels => python3-sasmodels-opencl} |  5 ++--
 12 files changed, 125 insertions(+), 12 deletions(-)

diff --git a/debian/compile_models b/debian/compile_models
new file mode 100755
index 0000000..398a1df
--- /dev/null
+++ b/debian/compile_models
@@ -0,0 +1,10 @@
+#!/usr/bin/python3
+
+import logging
+logging.basicConfig(level=logging.INFO)
+
+import sasmodels.core
+
+dll_path = 'sasmodels/compiled_models'
+compiled_dlls = sasmodels.core.precompile_dlls(dll_path, dtype='double')
+
diff --git a/debian/control b/debian/control
index b363aea..4692392 100644
--- a/debian/control
+++ b/debian/control
@@ -37,6 +37,7 @@ Depends:
  python-numpy,
  python-pyopencl,
  python-scipy,
+ sasmodels-private-libs,
  ${misc:Depends},
  ${python:Depends}
 Suggests: python-sasmodels-doc
@@ -54,6 +55,7 @@ Depends:
  python3-numpy,
  python3-pyopencl,
  python3-scipy,
+ sasmodels-private-libs,
  ${misc:Depends},
  ${python3:Depends}
 Suggests: python-sasmodels-doc
@@ -64,6 +66,19 @@ Description: Theoretical models for small angle scattering (Python 3)
  .
  This package contains the Python 3 version of the module.
 
+Package: sasmodels-private-libs
+Architecture: any
+Section: libs
+Depends:
+ ${misc:Depends},
+ ${shlibs:Depends}
+Description: Theoretical models for small angle scattering (compiled models)
+ sasmodels is a Python module for calculating theoretical Small Angle
+ Scattering patterns. The models provided are usable directly in the bumps
+ fitting package and in the sasview analysis package.
+ .
+ This package contains the precompiled versions of the models.
+
 Package: python-sasmodels-doc
 Architecture: all
 Section: doc
diff --git a/debian/patches/precompiled_path.patch b/debian/patches/precompiled_path.patch
new file mode 100644
index 0000000..7445eae
--- /dev/null
+++ b/debian/patches/precompiled_path.patch
@@ -0,0 +1,33 @@
+Description: Set library location to pick up precompiled models
+ models can be precompiled or compiled just-in-time; for a binary distribution such
+ as Debian, it makes sense to precompile the models and ship them in the package.
+Author: Stuart Prescott <stuart at debian.org>
+--- a/sasmodels/kerneldll.py
++++ b/sasmodels/kerneldll.py
+@@ -68,7 +68,7 @@
+ 
+ import sys
+ import os
+-from os.path import join as joinpath, splitext
++from os.path import join as joinpath, splitext, abspath, dirname
+ import subprocess
+ import tempfile
+ import ctypes as ct  # type: ignore
+@@ -161,7 +161,7 @@
+         os.makedirs(DLL_PATH)
+ else:
+     # Set up the default path for compiled modules.
+-    DLL_PATH = tempfile.gettempdir()
++    DLL_PATH = joinpath(abspath(dirname(__file__)), 'compiled_models')
+ 
+ ALLOW_SINGLE_PRECISION_DLLS = True
+ 
+@@ -208,7 +208,7 @@
+     Complete path to the dll for the model.  Note that the dll may not
+     exist yet if it hasn't been compiled.
+     """
+-    return os.path.join(DLL_PATH, dll_name(model_info, dtype))
++    return dll_name(model_info, dtype)
+ 
+ 
+ def make_dll(source, model_info, dtype=F64):
diff --git a/debian/patches/series b/debian/patches/series
index 508e0b3..9dd8bbd 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -1,2 +1,4 @@
 disable-failing-test.patch
 sphinx-local-mathjax.patch
+precompiled_path.patch
+setup-install-so.patch
diff --git a/debian/patches/setup-install-so.patch b/debian/patches/setup-install-so.patch
new file mode 100644
index 0000000..f956601
--- /dev/null
+++ b/debian/patches/setup-install-so.patch
@@ -0,0 +1,20 @@
+Description: Have setup.py install the precopmiled model files
+Author: Stuart Prescott <stuart at debian.org>
+
+--- a/setup.py
++++ b/setup.py
+@@ -41,11 +41,13 @@
+     packages=[
+         'sasmodels',
+         'sasmodels.models',
+-        'sasmodels.custom'
++        'sasmodels.custom',
++        'sasmodels.compiled_models',
+     ],
+     package_data={
+         'sasmodels.models': ['*.c', 'lib/*.c'],
+         'sasmodels': ['*.c', '*.cl'],
++        'sasmodels.compiled_models': ['*.so'],
+     },
+     install_requires = [
+     ],
diff --git a/debian/rules b/debian/rules
index 5540004..83ffbb8 100755
--- a/debian/rules
+++ b/debian/rules
@@ -6,10 +6,15 @@ export PYBUILD_NAME=sasmodels
 
 # opencl needs somewhere to cache compiled objects
 export POCL_CACHE_DIR=$(CURDIR)/.cache/
+export XDG_CACHE_HOME=$(CURDIR)/.cache/
 # and also tell pyopencl not to cache
 export PYOPENCL_NO_CACHE=1
-# and give somewhere for sasmodels to look for custom models
+# and give somewhere for sasmodels to look for models
 export SAS_MODELPATH=$(CURDIR)/.sasmodels/
+export SAS_MODELPATH_COMPILED=./sasmodels/compiled_models/
+
+# ensure test logs don't get accidentally installed
+export PYBUILD_AFTER_INSTALL=rm -rf {build_dir}/logs
 
 %:
 	dh $@ --with python2,python3,sphinxdoc --buildsystem=pybuild
@@ -17,16 +22,24 @@ export SAS_MODELPATH=$(CURDIR)/.sasmodels/
 override_dh_clean:
 	dh_clean
 	make -C doc clean
-	rm -rf $(POCL_CACHE_DIR) $(SAS_MODELPATH)
+	rm -rf $(POCL_CACHE_DIR) $(SAS_MODELPATH) $(SAS_MODELPATH_COMPILED)
 	rm -rf doc/guide/models/
 	rm -rf sasmodels.egg-info
 	find -name logs -type d -exec rm -rf {} +
 
 override_dh_auto_build:
-	mkdir -p $(POCL_CACHE_DIR) $(SAS_MODELPATH)
+	mkdir -p $(POCL_CACHE_DIR) $(SAS_MODELPATH) $(SAS_MODELPATH_COMPILED)
+	PYTHONPATH=. ./debian/compile_models
 	dh_auto_build
-	MPLBACKEND=Agg make -C doc html
-	ln -sf /usr/share/javascript/mathjax/ doc/_build/html/_static/mathjax
+	MPLBACKEND=Agg SAS_OPENCL=none make -C doc html
+	ln -sf /usr/share/javascript/mathjax doc/_build/html/_static/
+
+override_dh_auto_install:
+	dh_auto_install
+	for d in debian/*/usr/lib/python*/*packages/sasmodels/compiled_models; do \
+	  rm -rf $$d; \
+	  ln -s /usr/lib/sasmodels/compiled_models $$d ; \
+	done
 
 override_dh_auto_test:
 	# don't run the tests if suppressed with DEB_BUILD_OPTIONS=nocheck
@@ -34,7 +47,7 @@ ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
 	mkdir -p $(POCL_CACHE_DIR)
 	PYBUILD_SYSTEM=custom \
 	  PYBUILD_TEST_ARGS='cd {build_dir} && \
-	    {interpreter} -m sasmodels.model_test opencl all && \
+	    {interpreter} -m sasmodels.model_test dll all && \
 	    {interpreter} -m unittest -v sasmodels.resolution; \
 	    ' \
           dh_auto_test --buildsystem=pybuild
diff --git a/debian/sasmodels-private-libs.install b/debian/sasmodels-private-libs.install
new file mode 100644
index 0000000..2eb1607
--- /dev/null
+++ b/debian/sasmodels-private-libs.install
@@ -0,0 +1 @@
+sasmodels/compiled_models usr/lib/sasmodels/
diff --git a/debian/tests/control b/debian/tests/control
index eff76f9..64af40e 100644
--- a/debian/tests/control
+++ b/debian/tests/control
@@ -10,3 +10,14 @@ Depends:
  python3-all,
  python3-sasmodels
 
+Tests: python-sasmodels-opencl
+Restrictions: allow-stderr
+Depends:
+ python-all,
+ python-sasmodels
+
+Tests: python3-sasmodels-opencl
+Restrictions: allow-stderr
+Depends:
+ python3-all,
+ python3-sasmodels
diff --git a/debian/tests/python-sasmodels b/debian/tests/python-sasmodels
index 9591a81..2e3ef10 100755
--- a/debian/tests/python-sasmodels
+++ b/debian/tests/python-sasmodels
@@ -6,13 +6,16 @@ cd "$ADTTMP"
 
 # opencl needs somewhere to cache compiled objects
 export POCL_CACHE_DIR="$PWD/.cache/"
+export XDG_CACHE_HOME="$PWD/.cache/"
 mkdir "$POCL_CACHE_DIR"
 export SAS_MODELPATH="$PWD/.sasmodels/"
 mkdir "$SAS_MODELPATH"
 # and also tell pyopencl not to cache
 export PYOPENCL_NO_CACHE=1
 
+export SAS_OPENCL=none
+
 for py in $(pyversions -i); do
-  $py -m sasmodels.model_test opencl all
+  $py -m sasmodels.model_test dll all
   $py -m unittest -v sasmodels.resolution
 done
diff --git a/debian/tests/python-sasmodels b/debian/tests/python-sasmodels-opencl
old mode 100755
new mode 100644
similarity index 70%
copy from debian/tests/python-sasmodels
copy to debian/tests/python-sasmodels-opencl
index 9591a81..f10e68a
--- a/debian/tests/python-sasmodels
+++ b/debian/tests/python-sasmodels-opencl
@@ -6,6 +6,7 @@ cd "$ADTTMP"
 
 # opencl needs somewhere to cache compiled objects
 export POCL_CACHE_DIR="$PWD/.cache/"
+export XDG_CACHE_HOME="$PWD/.cache/"
 mkdir "$POCL_CACHE_DIR"
 export SAS_MODELPATH="$PWD/.sasmodels/"
 mkdir "$SAS_MODELPATH"
@@ -13,6 +14,6 @@ mkdir "$SAS_MODELPATH"
 export PYOPENCL_NO_CACHE=1
 
 for py in $(pyversions -i); do
-  $py -m sasmodels.model_test opencl all
-  $py -m unittest -v sasmodels.resolution
+  echo "##### These tests are likely to fail #####"
+  $py -m sasmodels.model_test opencl all || true
 done
diff --git a/debian/tests/python3-sasmodels b/debian/tests/python3-sasmodels
index 8bb4bf3..4359680 100755
--- a/debian/tests/python3-sasmodels
+++ b/debian/tests/python3-sasmodels
@@ -6,13 +6,16 @@ cd "$ADTTMP"
 
 # opencl needs somewhere to cache compiled objects
 export POCL_CACHE_DIR="$PWD/.cache/"
+export XDG_CACHE_HOME="$PWD/.cache/"
 mkdir "$POCL_CACHE_DIR"
 export SAS_MODELPATH="$PWD/.sasmodels/"
 mkdir "$SAS_MODELPATH"
 # and also tell pyopencl not to cache
 export PYOPENCL_NO_CACHE=1
 
+export SAS_OPENCL=none
+
 for py in $(py3versions -i); do
-  $py -m sasmodels.model_test opencl all
+  $py -m sasmodels.model_test dll all
   $py -m unittest -v sasmodels.resolution
 done
diff --git a/debian/tests/python3-sasmodels b/debian/tests/python3-sasmodels-opencl
old mode 100755
new mode 100644
similarity index 70%
copy from debian/tests/python3-sasmodels
copy to debian/tests/python3-sasmodels-opencl
index 8bb4bf3..30665e3
--- a/debian/tests/python3-sasmodels
+++ b/debian/tests/python3-sasmodels-opencl
@@ -6,6 +6,7 @@ cd "$ADTTMP"
 
 # opencl needs somewhere to cache compiled objects
 export POCL_CACHE_DIR="$PWD/.cache/"
+export XDG_CACHE_HOME="$PWD/.cache/"
 mkdir "$POCL_CACHE_DIR"
 export SAS_MODELPATH="$PWD/.sasmodels/"
 mkdir "$SAS_MODELPATH"
@@ -13,6 +14,6 @@ mkdir "$SAS_MODELPATH"
 export PYOPENCL_NO_CACHE=1
 
 for py in $(py3versions -i); do
-  $py -m sasmodels.model_test opencl all
-  $py -m unittest -v sasmodels.resolution
+  echo "##### These tests are likely to fail #####"
+  $py -m sasmodels.model_test opencl all || true
 done

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/sasmodels.git



More information about the debian-science-commits mailing list