[SCM] Packaging for cctbx branch, master, updated. upstream/2012.05.08.2305-55-g34c2a37

Baptiste Carvello devel at baptiste-carvello.net
Fri Jul 27 12:21:37 UTC 2012


The following commit has been merged in the master branch:
commit 34c2a3753248189ffdb4abd8874ef829c0fd6965
Author: Baptiste Carvello <devel at baptiste-carvello.net>
Date:   Fri Jul 27 08:56:10 2012 +0200

    Add features to setup.py (clean, test, etc)

diff --git a/debian/patches/0010-adding-setup_py.patch b/debian/patches/0010-adding-setup_py.patch
index 4a271a5..8ca9a9e 100644
--- a/debian/patches/0010-adding-setup_py.patch
+++ b/debian/patches/0010-adding-setup_py.patch
@@ -1,12 +1,12 @@
-From: =?UTF-8?q?Picca=20Fr=C3=A9d=C3=A9ric-Emmanuel?= <picca at debian.org>
-Date: Sat, 30 Jun 2012 16:03:05 +0200
+From: Baptiste Carvello <devel at baptiste-carvello.net>
+Date: Thu, 26 Jul 2012 21:55:12 +0200
 Subject: adding-setup_py
 
 ---
- cctbx_sources/stdlib.py |    4 ++
- sconsutils.py           |  155 +++++++++++++++++++++++++++++++++++++++++++++++
- setup.py                |  129 +++++++++++++++++++++++++++++++++++++++
- 3 files changed, 288 insertions(+)
+ cctbx_sources/stdlib.py |    4 +
+ sconsutils.py           |  399 +++++++++++++++++++++++++++++++++++++++++++++++
+ setup.py                |  128 +++++++++++++++
+ 3 files changed, 531 insertions(+)
  create mode 100755 cctbx_sources/stdlib.py
  create mode 100644 sconsutils.py
  create mode 100755 setup.py
@@ -23,14 +23,20 @@ index 0000000..759f689
 +random = stdlib_import("random")
 diff --git a/sconsutils.py b/sconsutils.py
 new file mode 100644
-index 0000000..07d393d
+index 0000000..550a691
 --- /dev/null
 +++ b/sconsutils.py
-@@ -0,0 +1,155 @@
-+from distutils.sysconfig import get_python_lib
+@@ -0,0 +1,399 @@
++from distutils.sysconfig import get_python_lib, get_config_var
 +from distutils.command.build_ext import build_ext as _build_ext
++from distutils.command.build_py import build_py as _build_py
 +from distutils.command.install_lib import install_lib as _install_lib
++from distutils.command.install_data import install_data as _install_data
++from distutils.command.clean import clean as _clean
 +from distutils.cmd import Command as _Command
++from distutils.dir_util import remove_tree
++from distutils.util import change_root, convert_path
++from distutils import log
 +import sys, os
 +import SCons.Script
 +import libtbx
@@ -39,44 +45,269 @@ index 0000000..07d393d
 +import threading
 +import pickle
 +
-+BUILDDIR = ''
++opj = os.path.join
 +configure_list = []
 +scons_buildargv = []
 +scons_installargv = []
-+PREFIX = ''
 +
-+class Command(_Command, object):
++class Command(_Command):
 +    def run_scons(self, argv):
 +        cwd = os.getcwd()
-+        if not os.path.exists(BUILDDIR):
-+            os.mkdir(BUILDDIR)
-+        elif not os.path.isdir(BUILDDIR):
++        builddir = opj(os.path.abspath(self.build_temp), 'cctbx-build')    # build_temp must be set by subclass
++        if not os.path.exists(builddir):
++            if not os.path.exists(os.path.abspath(self.build_temp)):
++                os.mkdir(os.path.abspath(self.build_temp))
++            os.mkdir(builddir)
++        elif not os.path.isdir(builddir):
 +            raise RuntimeError(("Build directory '%s' cannot be created "
-+                                "because of existing file") % BUILDDIR)
-+        os.chdir(BUILDDIR)
++                                "because of existing file") % builddir)
++        os.chdir(builddir)
++        if '%PREFIX%' in configure_list:
++            idx=configure_list.index('%PREFIX%')
++            configure_list[idx] = self.prefix    # prefix must be set by subclass
 +        libtbx.env_config.cold_start(configure_list)
-+        os.environ["LIBTBX_BUILD"] = BUILDDIR
++        os.environ["LIBTBX_BUILD"] = builddir
 +        os.environ['PYTHONPATH'] = ':'.join(sys.path)
 +        self.spawn(argv)
 +        os.chdir(cwd)
++
++class build_ext(_build_ext, Command):
++    user_options = _build_ext.user_options + [
++        ('prefix=', None, "installation prefix (default: python installation prefix")
++    ]
++    def initialize_options(self):
++        _build_ext.initialize_options(self)
++        self.prefix = None
++    def finalize_options(self):
++        _build_ext.finalize_options(self)
++        if not self.prefix:
++            self.prefix = get_config_var('prefix')    # on Debian: 'usr'
++    def run(self):
++        builddir = opj(os.path.abspath(self.build_temp), 'cctbx-build')    # build_temp set by _build_ext
++        self.run_scons(scons_buildargv)
++        for ext in self.extensions:
++            if len(ext.sources) != 1 or  ext.sources[0] != '%SCONSLIB%':
++                log.warn("Don't know how to build extension '%s' -- skipping",
++                    ext.name)
++                continue
++            dst = self.get_ext_fullpath(ext.name)
++            bld = opj(builddir, 'lib', os.path.basename(dst))
++            if os.path.isfile(bld):
++                self.copy_file(bld, dst)
++
++class build_py(_build_py):
++    def build_module (self, module, module_file, package):
++        if type(package) is str:
++            package = package.split('.')
++        elif type(package) not in (list, tuple):
++            raise TypeError, \
++                  "'package' must be a string (dot-separated), list, or tuple"
++
++        # Now put the module source file into the "build" area -- this is
++        # easy, we just copy it somewhere under self.build_lib (the build
++        # directory for Python source).
++        outfile = self.get_module_outfile(self.build_lib, package, module)
++        dir = os.path.dirname(outfile)
++        self.mkpath(dir)
++        # If the module contains non-blank, non-comment/docstring lines, and doesn't have
++        # the __future__ import, add it before the first non-comment/docstring line
++        empty = True
++        found = False
++        docstring = None
++        file_obj = open(module_file)
++        for line in file_obj:
++            if docstring:
++                if (line.count(docstring) % 2) == 1:
++                    # FIXME this logic will fail with lines such as """ + ''',
++                    # but nobody with a sane mind would do that, would they ?
++                    docstring = None
++                continue
++            if line == "from __future__ import division\n":
++                found = True
++                break
++            if line.isspace() or line.startswith('#'):
++                continue
++            if line.startswith('"""') and (line.count('"""') % 2) == 1:
++                docstring = '"""'
++                continue
++            if line.startswith('"'):
++                continue
++            if line.startswith("'''") and (line.count("'''") % 2) == 1:
++                docstring = "'''"
++                continue
++            if line.startswith("'"):
++                continue
++            empty = False
++            break
++        file_obj.close()
++        if empty or found:
++            return self.copy_file(module_file, outfile, preserve_mode=0)
++        elif self.dry_run:
++            if os.path.isdir(outfile):
++                outfile = opj(outfile, os.path.basename(module_file))
++            log.info("copying with modification %s -> %s", module_file, outfile)
++            return outfile, True
++        else:
++            if os.path.isdir(outfile):
++                outfile = opj(outfile, os.path.basename(module_file))
++            log.info("copying with modification %s -> %s", module_file, outfile)
++            file_obj = open(module_file)
++            outfile_obj = open(outfile, 'w')
++            written = False
++            docstring = None
++            for line in file_obj:
++                if not written:
++                    if docstring:
++                        if (line.count(docstring) % 2) == 1:
++                            docstring = None
++                        outfile_obj.write(line)
++                        continue
++                    if line.isspace() or line.startswith('#'):
++                        outfile_obj.write(line)
++                        continue
++                    if line.startswith('"""') and (line.count('"""') % 2) == 1:
++                        docstring = '"""'
++                        outfile_obj.write(line)
++                        continue
++                    if line.startswith('"'):
++                        outfile_obj.write(line)
++                        continue
++                    if line.startswith("'''") and (line.count("'''") % 2) == 1:
++                        docstring = "'''"
++                        outfile_obj.write(line)
++                        continue
++                    if line.startswith("'"):
++                        outfile_obj.write(line)
++                        continue
++                    outfile_obj.write("from __future__ import division\n")
++                    written = True
++                outfile_obj.write(line)
++            outfile_obj.close()
++            file_obj.close()
++            return outfile, True
++
++class test(_Command):
++    description = "runs the tests in the distutils build directory"
++    user_options = [
++        ('build-lib=', None,
++         "distutils build directory (default: 'build.build-lib')"),
++        ('build-temp=', 't',
++         "directory for temporary files (default: 'build.build-temp')")
++    ]
++    def initialize_options(self):
++        self.build_lib = None
++        self.build_temp = None
++    def finalize_options(self):
++        self.set_undefined_options('build',
++                                   ('build_lib', 'build_lib'),
++                                   ('build_temp', 'build_temp'))
++    def run(self):
++        libdir = os.path.abspath(os.path.abspath(self.build_lib))
++        builddir = opj(os.path.abspath(self.build_temp), 'cctbx-build')
++        testdir = opj(os.path.abspath(self.build_temp), 'cctbx-test')
++        os.environ["LIBTBX_BUILD"] = builddir
++        env = libtbx.env_config.unpickle()
++        scripts = [opj(libdir, s.relocatable.partition('cctbx_sources'+os.sep)[2])
++            for s in env.collect_test_scripts()
++            ]
++        os.environ['PYTHONPATH'] = ':'.join([libdir] + sys.path[5:])
++        llp = os.environ.get('LD_LIBRARY_PATH')
++        if llp is not None:
++            os.environ['LD_LIBRARY_PATH'] = ':'.join([opj(builddir, 'lib', '.libs'), llp])
++        else:
++            os.environ['LD_LIBRARY_PATH'] = opj(builddir, 'lib', '.libs')
++        if not os.path.exists(testdir):
++            if not os.path.exists(os.path.abspath(self.build_temp)):
++                os.mkdir(os.path.abspath(self.build_temp))
++            os.mkdir(testdir)
++        elif not os.path.isdir(testdir):
++            raise RuntimeError(("Test directory '%s' cannot be created "
++                                "because of existing file") % testdir)
++        os.chdir(testdir)
++        os.environ["LIBTBX_TEST_BUILDDIR"] = builddir
++        os.environ["LIBTBX_TEST_DISTDIR"] = libdir
++        for s in scripts:
++            try:
++                self.spawn([sys.executable, s])
++            except Exception, e:
++                log.warn("Could not run script '%s':\n%s", s, str(e))
++
 +class install_lib(_install_lib, Command):
++    user_options = _install_lib.user_options + [
++        ('build-temp=', 't',
++         "directory for temporary files (default: 'build.build-temp')"),
++        ('prefix=', None, "installation prefix (default: 'install.prefix')"),
++        ('root=', None,
++         "install everything relative to this alternate root directory (default: 'install.root')")
++    ]
++    def initialize_options(self):
++        _install_lib.initialize_options(self)
++        self.build_temp = None
++        self.prefix = None
++        self.root = None
++    def finalize_options(self):
++        _install_lib.finalize_options(self)
++        self.set_undefined_options('build',
++                                   ('build_temp', 'build_temp'))
++        self.set_undefined_options('install',
++                                   ('prefix', 'prefix'),
++                                   ('root', 'root'))
 +    def run(self):
-+        super(install_lib, self).run()
-+        install_root = self.get_finalized_command('install').root
-+        if install_root != None:
++        _install_lib.run(self)
++        if self.root != None:
 +            ip = '--install_destdir'
 +            if ip not in configure_list:
-+                configure_list.extend([ip, install_root])
++                configure_list.extend([ip, self.root])
 +        self.run_scons(scons_installargv)
-+        self.modify_libtbx_env()
 +
-+    def modify_libtbx_env(self):
++class install_data(_install_data, Command):
++    user_options = _install_data.user_options + [
++        ('build-temp=', 't',
++         "directory for temporary files (default: 'build.build-temp')"),
++        ('prefix=', None, "installation prefix (default: 'install.prefix')")
++    ]
++    def initialize_options(self):
++        _install_data.initialize_options(self)
++        self.build_temp = None
++        self.prefix = None
++    def finalize_options(self):
++        _install_data.finalize_options(self)
++        self.set_undefined_options('build',
++                                   ('build_temp', 'build_temp'))
++        self.set_undefined_options('install',
++                                   ('prefix', 'prefix'))
++    def run(self):
++        # filter the list
++        newdf = []
++        libtbx_env_path = None
++        for f in self.data_files:
++            if type(f) is str:
++                newdf.append(f)
++                continue
++            if '%LIBTBXENV%' in f[1]:
++                f = (f[0], [p for p in f[1] if p != '%LIBTBXENV%'])
++                libtbx_env_path = opj(convert_path(f[0]), 'libtbx_env')
++                if not os.path.isabs(libtbx_env_path):    # mimic the logic in install_data
++                    libtbx_env_path = opj(self.install_dir, libtbx_env_path)
++                elif self.root:
++                    libtbx_env_path = change_root(self.root, libtbx_env_path)
++                # we leave the directory in, so that distutils will create it
++            newdf.append(f)
++        self.data_files = newdf
++        _install_data.run(self)
++        if libtbx_env_path is not None:
++            self.install_libtbx_env(libtbx_env_path)
++            self.outfiles.append(libtbx_env_path)
++
++    def install_libtbx_env(self, libtbx_env_path):
 +        """ Modify libtbx_env pickle object to set the correct paths. """
++        builddir = opj(os.path.abspath(self.build_temp), 'cctbx-build')
++        os.environ["LIBTBX_BUILD"] = builddir
 +        env = libtbx.env_config.unpickle()
-+        env.build_path = absolute_path(PREFIX)
++        env.build_path = absolute_path(self.prefix)
 +        build_path = env.build_path
 +        python_lib = get_python_lib()
-+        rel_path = os.path.join(python_lib, 'cctbx')
++        rel_path = opj(python_lib, 'cctbx')
 +        env.bin_path = relocatable_path(build_path, 'bin')
 +        env.lib_path = relocatable_path(build_path, 'lib')
 +        env.include_path = relocatable_path(build_path, 'include')
@@ -86,40 +317,47 @@ index 0000000..07d393d
 +        env.exe_path = env.bin_path
 +        env.python_exe = relocatable_path(build_path, sys.executable)
 +        env.path_utility = relocatable_path(build_path,
-+                os.path.join(rel_path, 'libtbx/command_line/path_utility.py'))
++                opj(rel_path, 'libtbx', 'command_line', 'path_utility.py'))
 +        module_dist_paths = {}
 +        for key, value in env.module_dist_paths.items():
 +            head, module = os.path.split(abs(value))
 +            module_dist_paths[key] = relocatable_path(build_path,
-+                    os.path.join(rel_path, module))
++                    opj(rel_path, module))
 +        env.module_dist_paths = module_dist_paths
 +        for module in env.module_list:
 +            paths = []
 +            for path in module.dist_paths:
 +                if path != None:
 +                    head, tail = os.path.split(abs(path))
-+                    rp = relocatable_path(build_path, os.path.join(rel_path, tail))
++                    rp = relocatable_path(build_path, opj(rel_path, tail))
 +                    paths.append(rp)
 +                else:
 +                    paths.append(None)
 +            module.dist_paths = paths
 +        env.reset_dispatcher_bookkeeping()
-+        # Don't want to override libtbx_env so I put it into BUILDDIR/lib
-+        # So data_files sould look in their
-+        file_name = os.path.join(BUILDDIR, 'lib', "libtbx_env")
-+        file_path = open(file_name, 'wb')
-+        pickle.dump(env, file_path, 0)
-+        file_path.close()
++        # install the environment file in the data dir
++        file_obj = open(libtbx_env_path, 'wb')
++        pickle.dump(env, file_obj, 0)
++        file_obj.close()
 +
-+class build_ext(_build_ext, Command):
++class clean(_clean):
 +    def run(self):
-+        self.run_scons(scons_buildargv)
-+        for ext in self.extensions:
-+            src = ext.sources[0]
-+            bld = os.path.join(BUILDDIR, src)
-+            dst = self.get_ext_fullpath(ext.name)
-+            if os.path.isfile(bld):
-+                self.copy_file(bld, dst)
++        # remove the scons build dir
++        builddir = opj(os.path.abspath(self.build_temp), 'cctbx-build')
++        if os.path.exists(builddir):
++            remove_tree(builddir, dry_run=self.dry_run)
++        else:
++            log.debug("'%s' does not exist -- can't clean it",
++                      builddir)
++        # remove the scons test dir
++        testdir = opj(os.path.abspath(self.build_temp), 'cctbx-test')
++        if os.path.exists(testdir):
++            remove_tree(testdir, dry_run=self.dry_run)
++        else:
++            log.debug("'%s' does not exist -- can't clean it",
++                      testdir)
++        # call the base class to remove the distutils dirs
++        _clean.run(self)
 +
 +# adapted from setuptools
 +# authors: Phillip J. Eby, Tarek Ziade and the distutils SIG
@@ -131,6 +369,7 @@ index 0000000..07d393d
 +EXTPAT1 = re.compile(r"^from (\S+_ext) import")
 +EXTPAT2 = re.compile(r"^import (\S+_ext)$")
 +EXTPAT3 = re.compile(r"boost.python.import_ext\(['\"](\S+_ext)['\"]\)$")
++EXTPAT4 = re.compile(r"import_ext\(['\"](\S+_ext)['\"]\)$")    # in module boost.python!
 +
 +def find_packages_and_extensions(where='.', exclude=()):
 +    """Return a list all Python packages found within directory 'where'
@@ -151,16 +390,16 @@ index 0000000..07d393d
 +        where,prefix = stack.pop(0)
 +        for name in os.listdir(where):
 +
-+            fn = os.path.join(where,name)
++            fn = opj(where,name)
 +            if ('.' not in name and os.path.isdir(fn) and
-+                os.path.isfile(os.path.join(fn,'__init__.py'))
++                os.path.isfile(opj(fn,'__init__.py'))
 +            ):
 +
 +                out.append(prefix+name); stack.append((fn,prefix+name+'.'))
 +
 +            if name.endswith('.py'):
 +
-+                f = open(os.path.join(where, name))
++                f = open(opj(where, name))
 +                for l in f:
 +
 +                    m = EXTPAT1.match(l)
@@ -175,6 +414,11 @@ index 0000000..07d393d
 +                    if m is not None:
 +                        outext.add(m.group(1))
 +
++                    if name == 'python.py' and prefix.endswith('boost.'):
++                        m = EXTPAT4.search(l)
++                        if m is not None:
++                            outext.add(m.group(1))
++
 +                f.close()
 +
 +    for pat in list(exclude)+['ez_setup', 'distribute_setup']:
@@ -184,27 +428,27 @@ index 0000000..07d393d
 +    return out, list(outext)
 diff --git a/setup.py b/setup.py
 new file mode 100755
-index 0000000..c298997
+index 0000000..09b5759
 --- /dev/null
 +++ b/setup.py
-@@ -0,0 +1,129 @@
+@@ -0,0 +1,128 @@
 +from distutils.core import setup, Extension
++from distutils.util import convert_path
 +import sys, os, shutil
 +
 +# General settings
 +opj = os.path.join
 +CURDIR = os.getcwd()
-+SRCDIR = opj(CURDIR, 'cctbx_sources/')
++SRCDIR = opj(CURDIR, 'cctbx_sources')
 +py_vers = sys.version_info
 +py_major = py_vers[0]
 +py_minor = py_vers[1]
 +py_str = 'python%s.%s'%(py_major, py_minor)
-+BUILDDIR = opj(CURDIR, 'build%i.%i'%(py_major, py_minor))
-+clipper = 'clipper_adaptbx/clipper'
-+boost = 'boost_adaptbx/boost'
-+libtbx_pypath = 'libtbx/pythonpath'
++clipper = opj('clipper_adaptbx','clipper')
++boost = opj('boost_adaptbx','boost')
++libtbx_pypath = opj('libtbx','pythonpath')
++scons_exe = '/usr/bin/scons'    # FIXME platform dependent path
 +scons_path = '/usr/lib/scons/'
-+PREFIX = '/usr'
 +PATHLIST= [ SRCDIR,
 +            opj(SRCDIR, libtbx_pypath),
 +            opj(SRCDIR, clipper),
@@ -213,19 +457,20 @@ index 0000000..c298997
 +          ]
 +for p in PATHLIST:
 +    if p not in sys.path:
-+        sys.path.append(p)
++        # we need to insert at the front, in case cctbx is already installed
++        sys.path.insert(0,p)
 +
 +import sconsutils
-+from sconsutils import build_ext, find_packages_and_extensions, install_lib
++from sconsutils import find_packages_and_extensions, build_ext, build_py, test, install_lib, install_data, clean
 +
 +# Configure settings
 +# We need this directory to get env_config.cold_start to run!
 +# trailing slash is important
-+init_dir = opj(BUILDDIR, SRCDIR, 'libtbx/')
++init_dir = opj(SRCDIR, 'libtbx')+os.sep    # the separator is needed for dirname to do the right thing
 +build_opts = [ '--libtoolize',
 +               '--use_system_libs',
 +               '--use-environment-flags',
-+               '--install_prefix', PREFIX,
++               '--install_prefix', '%PREFIX%',    # prefix will be replaced at run time
 +             ]
 +conf_modules = [ 'annlib_adaptbx',
 +                 'boost_adaptbx',
@@ -254,14 +499,12 @@ index 0000000..c298997
 +sconsutils.configure_list = [init_dir]
 +sconsutils.configure_list.extend(build_opts)
 +sconsutils.configure_list.extend(conf_modules)
-+sconsutils.BUILDDIR = BUILDDIR
-+sconsutils.PREFIX = PREFIX
 +
 +# Build settings
-+sconsutils.scons_buildargv = [sys.executable, '/usr/bin/scons']
++sconsutils.scons_buildargv = [sys.executable, scons_exe]
 +
 +# Install settings
-+sconsutils.scons_installargv = [sys.executable, '/usr/bin/scons', 'install']
++sconsutils.scons_installargv = [sys.executable, scons_exe, 'install']
 +
 +# Setup settings
 +
@@ -276,29 +519,25 @@ index 0000000..c298997
 +SCRIPTS = []
 +PKG_DATA = {}
 +EXTRA_PATH = 'cctbx'
-+PACKDIR = { 'boost' : SRCDIR + 'boost_adaptbx/boost',
-+            'clipper' : SRCDIR + 'clipper_adaptbx/clipper',
-+            'optik' : SRCDIR + 'libtbx/pythonpath/optik',
-+            'tntbx' : SRCDIR + 'tntbx/tntbx',
-+            '' : SRCDIR,
++PACKDIR = { 'boost' : 'cctbx_sources/boost_adaptbx/boost',    # in setup, paths must stay in unix syntax
++            'clipper' : 'cctbx_sources/clipper_adaptbx/clipper',    # also, let's keep them relative
++            'optik' : 'cctbx_sources/libtbx/pythonpath/optik',
++            'tntbx' : 'cctbx_sources/tntbx/tntbx',
++            '' : 'cctbx_sources',
 +          }
 +
 +MODS = ['stdlib']
 +PACKS = []
 +EXT_MODULES = []
 +for key, value in PACKDIR.items():
-+    p, e = find_packages_and_extensions(value)
++    p, e = find_packages_and_extensions(convert_path(value))
 +    PACKS.extend(p)
 +    EXT_MODULES.extend(e)
 +    if key != '':
 +        PACKS.append(key)
 +
-+# TODO: This should also work with Mac OSX and Windows without hard coding the
-+# file ext.
-+EXT_MODULES = [ Extension(e, ['lib/%s.so'%e]) for e in EXT_MODULES ]
++EXT_MODULES = [ Extension(e, ['%SCONSLIB%']) for e in EXT_MODULES ]    # special treatment from install_lib
 +
-+# modified version of libtbx_env lies in BUILDDIR/lib
-+libtbx_env = opj(BUILDDIR, 'lib', 'libtbx_env')
 +setup(name=NAME,
 +      version = VERSION,
 +      author = AUTHOR,
@@ -313,8 +552,12 @@ index 0000000..c298997
 +      package_dir = PACKDIR,
 +      ext_modules = EXT_MODULES,
 +      cmdclass = {'build_ext': build_ext,
-+                  'install_lib': install_lib},
++                  'build_py': build_py,
++                  'test': test,
++                  'install_lib': install_lib,
++                  'install_data': install_data,
++                  'clean': clean},
 +      py_modules = MODS,
-+      data_files = [('/usr/share/cctbx/%s'%(py_str), [libtbx_env])],
++      data_files = [('share/cctbx/%s'%(py_str), ['%LIBTBXENV%'])],    # special treatment from install_data
 +     )
 -- 
diff --git a/debian/patches/0016-adapt-test_utils-in-libtbx-for-setup_py-test.patch b/debian/patches/0016-adapt-test_utils-in-libtbx-for-setup_py-test.patch
new file mode 100644
index 0000000..eadcf26
--- /dev/null
+++ b/debian/patches/0016-adapt-test_utils-in-libtbx-for-setup_py-test.patch
@@ -0,0 +1,50 @@
+From: Baptiste Carvello <devel at baptiste-carvello.net>
+Date: Thu, 26 Jul 2012 22:16:38 +0200
+Subject: adapt test_utils in libtbx for setup_py test
+
+---
+ cctbx_sources/libtbx/test_utils.py |   23 ++++++++++++++++++++++-
+ 1 file changed, 22 insertions(+), 1 deletion(-)
+
+diff --git a/cctbx_sources/libtbx/test_utils.py b/cctbx_sources/libtbx/test_utils.py
+index 13b6e67..c93867f 100644
+--- a/cctbx_sources/libtbx/test_utils.py
++++ b/cctbx_sources/libtbx/test_utils.py
+@@ -157,6 +157,27 @@ def make_pick_and_run_tests(working_dir, interrupted,
+   return func
+ 
+ def iter_tests_cmd(co, build_dir, dist_dir, tst_list):
++  if build_dir is not None and 'LIBTBX_TEST_BUILDDIR' in os.environ:
++    build_path=abs(libtbx.env.build_path)
++    if build_dir == build_path:
++        build_dir = os.environ['LIBTBX_TEST_BUILDDIR']
++    elif build_dir.startswith(build_path+os.sep):
++      build_dir = build_dir.replace(build_path, os.environ['LIBTBX_TEST_BUILDDIR'])
++    else:
++      raise RuntimeError("Resource not in build dir: %s" % build_dir)
++  if dist_dir is not None and 'LIBTBX_TEST_DISTDIR' in os.environ:
++    for module, dist_path in libtbx.env.module_dist_paths.items():
++      dist_path = abs(dist_path)
++      if dist_dir == dist_path:
++        dist_dir = os.path.join(os.environ['LIBTBX_TEST_DISTDIR'], module)
++        break
++      elif dist_dir.startswith(dist_path+os.sep):
++        dist_dir = dist_dir.replace(dist_path,
++          os.path.join(os.environ['LIBTBX_TEST_DISTDIR'], module)
++          )
++        break
++    else:
++      raise RuntimeError("Resource not in a dist dir: %s" % dist_dir)
+   for tst in tst_list:
+     cmd_args = ""
+     if (type(tst) == type([])):
+@@ -178,7 +199,7 @@ def iter_tests_cmd(co, build_dir, dist_dir, tst_list):
+     if (tst_path.endswith(".py")):
+       if (co.valgrind):
+         cmd = "libtbx.valgrind "
+-      cmd += "libtbx.python "
++      cmd += sys.executable + " "
+     else:
+       if (co.valgrind):
+         cmd = os.environ.get(
+-- 
diff --git a/debian/patches/series b/debian/patches/series
index 7c163b7..d89ab1a 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -13,3 +13,4 @@
 0013-fix-to-support-LDFLAGS-in-use_enviroment_flags.patch
 0014-Fix-to-append-CPPFLAGS-to-CXXFLAGS.patch
 0015-fix-cif-parser-to-work-with-antlr3c-3.2.patch
+0016-adapt-test_utils-in-libtbx-for-setup_py-test.patch

-- 
Packaging for cctbx



More information about the debian-science-commits mailing list