Skip to content

Commit

Permalink
Merge 2147974 into 048b6fb
Browse files Browse the repository at this point in the history
  • Loading branch information
matthew-brett committed Aug 31, 2015
2 parents 048b6fb + 2147974 commit 99f6bf8
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 13 deletions.
10 changes: 9 additions & 1 deletion .travis.yml
Expand Up @@ -5,6 +5,11 @@
# - There can't be any leading "-"s - All newlines will be removed, so use
# ";"s
sudo: false # To use travis container infrastructure
addons:
apt:
packages:
- libblas-dev
- liblapack-dev
language: python
cache:
directories:
Expand All @@ -27,14 +32,17 @@ matrix:
- python: 2.7
env:
- DEPENDS="numpy==1.6.0 scipy==0.7.0 sympy==0.7.0 nibabel==1.2.0"
# Test compiling against external lapack
- python: 3.4
env:
- NIPY_EXTERNAL_LAPACK=1
before_install:
- source tools/travis_tools.sh
- virtualenv --python=python venv
- source venv/bin/activate
- python --version # just to check
- retry pip install nose # always
- wheelhouse_pip_install $DEPENDS
# - sudo apt-get install -qq libatlas-dev libatlas-base-dev gfortran libpng-dev
- if [ "${COVERAGE}" == "1" ]; then
pip install coverage;
pip install coveralls;
Expand Down
58 changes: 46 additions & 12 deletions nipy/labs/setup.py
Expand Up @@ -3,14 +3,44 @@
import os
from distutils import log

try:
from configparser import ConfigParser, NoSectionError, NoOptionError
except ImportError:
from ConfigParser import ConfigParser, NoSectionError, NoOptionError

# Global variables
LIBS = os.path.realpath('lib')

# The following variable disables linking with Lapack by default. So
# far, the only way to attempt at linking with Lapack is to edit this
# file and set WANT_LAPACK_LINKING=True. We might later want to pass
# in this variable as an optional argument of `python setup.py build`.
WANT_LAPACK_LINKING = False
# Stuff for reading setup file
SETUP_FILE = 'setup.cfg'
SECTION = 'lapack'
KEY = 'external'
EXTERNAL_LAPACK_VAR = 'NIPY_EXTERNAL_LAPACK'

def get_link_external():
""" Return True if we should link to system BLAS / LAPACK
If True, attempt to link to system BLAS / LAPACK. Otherwise, compile
lapack_lite, and link to that.
First check ``setup.cfg`` file for section ``[lapack]`` key ``external``.
If this value undefined, then get string from environment variable
NIPY_EXTERNAL_LAPACK.
If value from ``setup.cfg`` or environment variable is not 'False' or '0',
then return True.
"""
config = ConfigParser()
try:
config.read(SETUP_FILE)
external_link = config.get(SECTION, KEY)
except (IOError, KeyError, NoOptionError, NoSectionError):
external_link = os.environ.get(EXTERNAL_LAPACK_VAR)
if external_link is None:
return False
return external_link.lower() not in ('0', 'false')


def configuration(parent_package='',top_path=None):
from numpy.distutils.misc_util import Configuration, get_numpy_include_dirs
Expand Down Expand Up @@ -50,16 +80,20 @@ def configuration(parent_package='',top_path=None):
# If lapack linking not required or no lapack install is found, we
# use the rescue lapack lite distribution included in the package
# (sources have been translated to C using f2c)
if not WANT_LAPACK_LINKING or not lapack_info:
if WANT_LAPACK_LINKING:
log.warn('Lapack not found')
log.warn('Building Lapack lite distribution')
want_lapack_link = get_link_external()
if not want_lapack_link:
log.warn('Building with (slow) Lapack lite distribution: '
'set {0} environment variable or use setup.cfg '
'to enable link to optimized BLAS / LAPACK'.format(
EXTERNAL_LAPACK_VAR)
)
sources.append(os.path.join(LIBS,'lapack_lite','*.c'))
library_dirs = []
libraries = []

# Best-case scenario: lapack found
else:
else: # Best-case scenario: external lapack found
if not lapack_info:
raise RuntimeError('Specified external lapack linking but '
'numpy does not report external lapack')
log.warn('Linking with system Lapack')
library_dirs = lapack_info['library_dirs']
libraries = lapack_info['libraries']
Expand Down
8 changes: 8 additions & 0 deletions setup.cfg
Expand Up @@ -19,3 +19,11 @@ cover-package = nipy
#with-doctest=1
doctest-extension=rst

# In this section specify if you want to link to external BLAS / LAPACK
[lapack]
# Value of 0 or False implies compile of, link to lapack_lite
# Value of 1 or True will cause setup to try and link to external BLAS /
# LAPACK as identified with the numpy configuration. Default is False.
# The value in this file overrides the equivalent setting in the environment
# variable NIPY_EXTERNAL_LAPACK.
#external = False

0 comments on commit 99f6bf8

Please sign in to comment.