setup.py 6.76 KB
Newer Older
1 2 3 4 5
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
# Andre Anjos <andre.anjos@idiap.ch>
# Mon 16 Apr 08:18:08 2012 CEST

Manuel Günther's avatar
Manuel Günther committed
6 7
bob_packages = ['bob.core']

8
from setuptools import setup, find_packages, dist
Manuel Günther's avatar
Manuel Günther committed
9
dist.Distribution(dict(setup_requires=['bob.blitz', 'numpy'] + bob_packages))
10
from bob.blitz.extension import Extension, Library, build_ext
11
from bob.extension.utils import uniq, find_library
12

13

14 15 16 17 18 19 20 21 22 23 24 25 26
def get_flags(keys):
  """Returns link/include flags for LAPACK/BLAS based on what NumPy uses

  In case NumPy is using a fallback (i.e., no LAPACK/BLAS installed on the host
  system), then defaults to linking against 'lapack' and 'blas' and hope it
  works.
  """

  import numpy.__config__ as npconf

  retval = dict(
      library_dirs = [],
      libraries = [],
27
      system_include_dirs = [],
28 29 30 31 32 33 34 35 36 37 38 39 40 41
      define_macros = [],
      extra_compile_args = [],
      extra_link_args = [],
      )

  for key in keys:

    if not hasattr(npconf, key): continue
    obj = getattr(npconf, key)
    if not obj: continue #it is empty

    retval = dict(
        library_dirs = obj.get('library_dirs', []),
        libraries = obj.get('libraries', []),
42
        system_include_dirs = obj.get('include_dirs', []),
43 44 45 46 47 48 49 50 51
        define_macros = obj.get('define_macros', []),
        extra_compile_args = obj.get('extra_compile_args', []),
        extra_link_args = obj.get('extra_link_args', []),
        )

  return retval

lapack_flags = get_flags(['lapack_info', 'lapack_opt_info', 'lapack_mkl_info'])
blas_flags = get_flags(['blas_info', 'blas_opt_info', 'blas_mkl_info'])
52 53

# mix-in
54 55 56
math_flags = dict(
    library_dirs = [],
    libraries = [],
57
    system_include_dirs = [],
58 59 60 61 62 63 64 65 66 67 68 69 70 71
    define_macros = [],
    extra_compile_args = [],
    extra_link_args = [],
    )
for key in math_flags:
  math_flags[key] = uniq(lapack_flags.get(key, []) + blas_flags.get(key, []))

# checks if any libraries are being linked, otherwise we
# search through the filesystem in stock locations.
if not math_flags['libraries']:
  # reset all entries
  math_flags = dict(
      library_dirs = [],
      libraries = [],
72
      system_include_dirs = [],
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
      define_macros = [],
      extra_compile_args = [],
      extra_link_args = [],
      )

  # tries first to find an MKL implementation
  lapack = find_library('mkl_lapack64')
  if not lapack:
    # if that fails, go for the default implementation
    lapack = find_library('lapack', subpaths=['sse2', ''])

  if not lapack:
    print("ERROR: LAPACK library not found - have that installed or set BOB_PREFIX_PATH to point to the correct installation prefix")
    sys.exit(1)

  # tries first to find an MKL implementation
  blas = find_library('mkl')
  if not blas:
    # if that fails, go for the default implementation of cblas
    blas = find_library('cblas', subpaths=['sse2', ''])
  if not blas:
    # if that fails, go for the default implementation of blas
    blas = find_library('blas', subpaths=['sse2', ''])

  if not blas:
    print("ERROR: BLAS library not found - have that installed or set BOB_PREFIX_PATH to point to the correct installation prefix")
    sys.exit(1)

  # at this point both lapack and blas were detected, proceed
  def libname(f): return os.path.splitext(os.path.basename(f))[0][3:]

  math_flags['library_dirs'] = uniq([
    os.path.dirname(lapack[0]),
    os.path.dirname(blas[0]),
    ])
  math_flags['libraries'] = uniq([
    libname(lapack[0]),
    libname(blas[0])
    ])

  print("\nLAPACK/BLAS configuration from filesystem scan:")

else:

  print("\nLAPACK/BLAS configuration from NumPy:")

119
print(" * system include directories: %s" % ', '.join(math_flags['system_include_dirs']))
120 121 122 123 124
print(" * defines: %s" % \
  ', '.join(['-D%s=%s' % k for k in math_flags['define_macros']]))
print(" * linking arguments: %s" % ', '.join(math_flags['extra_link_args']))
print(" * libraries: %s" % ', '.join(math_flags['libraries']))
print(" * library directories: %s\n" % ', '.join(math_flags['library_dirs']))
125 126 127 128 129

version = '2.0.0a0'

setup(

André Anjos's avatar
André Anjos committed
130
    name='bob.math',
131 132
    version=version,
    description='Bindings for bob.math',
André Anjos's avatar
André Anjos committed
133
    url='http://github.com/bioidiap/bob.math',
134 135 136 137 138 139 140 141
    license='BSD',
    author='Andre Anjos',
    author_email='andre.anjos@idiap.ch',

    long_description=open('README.rst').read(),

    packages=find_packages(),
    include_package_data=True,
André Anjos's avatar
André Anjos committed
142
    zip_safe=False,
143 144 145

    install_requires=[
      'setuptools',
André Anjos's avatar
André Anjos committed
146
      'bob.blitz',
147
      'bob.core',
148 149 150
    ],

    namespace_packages=[
André Anjos's avatar
André Anjos committed
151
      "bob",
Manuel Günther's avatar
Manuel Günther committed
152
    ],
153 154

    ext_modules = [
André Anjos's avatar
André Anjos committed
155
      Extension("bob.math.version",
156
        [
André Anjos's avatar
André Anjos committed
157
          "bob/math/version.cpp",
Manuel Günther's avatar
Manuel Günther committed
158
        ],
159
        version = version,
160
        system_include_dirs = math_flags.get('system_include_dirs', []),
161 162 163
        library_dirs = math_flags.get('library_dirs', []),
        libraries = math_flags.get('libraries', []),
        define_macros = math_flags.get('define_macros', []),
164
        extra_compile_args = math_flags['extra_compile_args'],
165
        extra_link_args = math_flags.get('extra_link_args', []),
Manuel Günther's avatar
Manuel Günther committed
166 167
        bob_packages = bob_packages,
      ),
168

169
      Library("bob.math.bob_math",
170
        [
171 172 173 174 175 176 177 178 179 180 181 182
          "bob/math/cpp/det.cpp",
          "bob/math/cpp/eig.cpp",
          "bob/math/cpp/inv.cpp",
          "bob/math/cpp/linsolve.cpp",
          "bob/math/cpp/log.cpp",
          "bob/math/cpp/LPInteriorPoint.cpp",
          "bob/math/cpp/lu.cpp",
          "bob/math/cpp/norminv.cpp",
          "bob/math/cpp/pavx.cpp",
          "bob/math/cpp/pinv.cpp",
          "bob/math/cpp/svd.cpp",
          "bob/math/cpp/sqrtm.cpp",
183 184
        ],
        version = version,
Manuel Günther's avatar
Manuel Günther committed
185
        bob_packages = bob_packages,
186
        system_include_dirs = math_flags['system_include_dirs'],
187 188 189 190
        library_dirs = math_flags['library_dirs'],
        libraries = math_flags['libraries'],
        define_macros = math_flags['define_macros'],
      ),
191

192 193
      Extension("bob.math._library",
        [
André Anjos's avatar
André Anjos committed
194 195 196 197 198 199 200
          "bob/math/histogram.cpp",
          "bob/math/linsolve.cpp",
          "bob/math/pavx.cpp",
          "bob/math/norminv.cpp",
          "bob/math/scatter.cpp",
          "bob/math/lp_interior_point.cpp",
          "bob/math/main.cpp",
Manuel Günther's avatar
Manuel Günther committed
201
        ],
202
        version = version,
Manuel Günther's avatar
Manuel Günther committed
203
        bob_packages = bob_packages,
204
        system_include_dirs = math_flags['system_include_dirs'],
205
        library_dirs = math_flags['library_dirs'],
206
        libraries = math_flags['libraries'],
207 208 209
        define_macros = math_flags['define_macros'],
        extra_compile_args = math_flags['extra_compile_args'],
        extra_link_args = math_flags['extra_link_args'],
210 211
      ),
    ],
212

213 214 215 216
    cmdclass = {
      'build_ext': build_ext
    },

217 218 219 220 221 222 223 224
    classifiers = [
      'Development Status :: 3 - Alpha',
      'Intended Audience :: Developers',
      'License :: OSI Approved :: BSD License',
      'Natural Language :: English',
      'Programming Language :: Python',
      'Programming Language :: Python :: 3',
      'Topic :: Software Development :: Libraries :: Python Modules',
Manuel Günther's avatar
Manuel Günther committed
225
    ],
226

Manuel Günther's avatar
Manuel Günther committed
227
  )