Skip to content
Snippets Groups Projects
setup.py 6.88 KiB
Newer Older
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
# Andre Anjos <andre.anjos@idiap.ch>
# Mon 16 Apr 08:18:08 2012 CEST

bob_packages = ['bob.core']

André Anjos's avatar
André Anjos committed
from setuptools import setup, find_packages, dist
dist.Distribution(dict(setup_requires=['bob.blitz'] + bob_packages))
André Anjos's avatar
André Anjos committed
from bob.extension.utils import egrep, find_header, find_library
from bob.blitz.extension import Extension, Library, build_ext
packages = ['boost']
boost_modules = ['system', 'filesystem']

version = '2.0.0a0'

André Anjos's avatar
André Anjos committed
def libhdf5_version(header):

  version = egrep(header, r"#\s*define\s+H5_VERSION\s+\"([\d\.]+)\"")
  if not len(version): return None
  return version[0].group(1)

class hdf5:

  def __init__ (self, requirement='', only_static=False):
    """
    Searches for libhdf5 in stock locations. Allows user to override.

    If the user sets the environment variable BOB_PREFIX_PATH, that prefixes
    the standard path locations.

    Parameters:

    requirement, str
      A string, indicating a version requirement for this library. For example,
      ``'>= 8.2'``.

    only_static, boolean
      A flag, that indicates if we intend to link against the static library
      only. This will trigger our library search to disconsider shared
      libraries when searching.
    """
    import os
André Anjos's avatar
André Anjos committed

    self.name = 'hdf5'
    header = 'hdf5.h'

    candidates = find_header(header)

    if not candidates:
      raise RuntimeError("could not find %s's `%s' - have you installed %s on this machine?" % (self.name, header, self.name))

    found = False

    if not requirement:
      self.include_directory = os.path.dirname(candidates[0])
      directory = os.path.dirname(candidates[0])
      version_header = os.path.join(directory, 'H5pubconf.h')
      self.version = libhdf5_version(version_header)
      found = True

    else:

      # requirement is 'operator' 'version'
      operator, required = [k.strip() for k in requirement.split(' ', 1)]

      # now check for user requirements
      for candidate in candidates:
        directory = os.path.dirname(candidate)
        version_header = os.path.join(directory, 'H5pubconf.h')
        version = libhdf5_version(version_header)
        available = LooseVersion(version)
        if (operator == '<' and available < required) or \
           (operator == '<=' and available <= required) or \
           (operator == '>' and available > required) or \
           (operator == '>=' and available >= required) or \
           (operator == '==' and available == required):
          self.include_directory = os.path.dirname(candidate)
          self.version = version
          found = True
          break

    if not found:
      raise RuntimeError("could not find the required (%s) version of %s on the file system (looked at: %s)" % (requirement, self.name, ', '.join(candidates)))

    # normalize
    self.include_directory = os.path.normpath(self.include_directory)

    # find library
    prefix = os.path.dirname(os.path.dirname(self.include_directory))
    module = 'hdf5'
    candidates = find_library(module, version=self.version, prefixes=[prefix], only_static=only_static)

    if not candidates:
      raise RuntimeError("cannot find required %s binary module `%s' - make sure libsvm is installed on `%s'" % (self.name, module, prefix))

    # libraries
    self.libraries = []
    name, ext = os.path.splitext(os.path.basename(candidates[0]))
    if ext in ['.so', '.a', '.dylib', '.dll']:
      self.libraries.append(name[3:]) #strip 'lib' from the name
    else: #link against the whole thing
      self.libraries.append(':' + os.path.basename(candidates[0]))

    # library path
    self.library_directory = os.path.dirname(candidates[0])

  def macros(self):
    return [
        ('HAVE_%s' % self.name.upper(), '1'),
        ('%s_VERSION' % self.name.upper(), '"%s"' % self.version),
        ]


hdf5_pkg = hdf5()

system_include_dirs = [hdf5_pkg.include_directory]
library_dirs = [hdf5_pkg.library_directory]
André Anjos's avatar
André Anjos committed

libraries = hdf5_pkg.libraries

define_macros = hdf5_pkg.macros()


André Anjos's avatar
André Anjos committed
    name='bob.io.base',
    version=version,
    description='Base bindings for bob.io',
André Anjos's avatar
André Anjos committed
    url='http://github.com/bioidiap/bob.io.base',
    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
    zip_safe=False,

    install_requires=[
      'setuptools',
André Anjos's avatar
André Anjos committed
      'bob.blitz',
      'bob.core'

    namespace_packages=[
André Anjos's avatar
André Anjos committed
      "bob",
      "bob.io",

    ext_modules = [
André Anjos's avatar
André Anjos committed
      Extension("bob.io.base.version",
André Anjos's avatar
André Anjos committed
          "bob/io/base/version.cpp",
André Anjos's avatar
André Anjos committed
        define_macros = define_macros,
        system_include_dirs = system_include_dirs,
        version = version,
        bob_packages = bob_packages,
        packages = packages,
        boost_modules = boost_modules,
      ),
      Library("bob.io.base.bob_io_base",
André Anjos's avatar
André Anjos committed
          "bob/io/base/cpp/CodecRegistry.cpp",
          "bob/io/base/cpp/CSVFile.cpp",
          "bob/io/base/cpp/File.cpp",
          "bob/io/base/cpp/HDF5ArrayFile.cpp",
André Anjos's avatar
André Anjos committed
          "bob/io/base/cpp/HDF5Attribute.cpp",
          "bob/io/base/cpp/HDF5Dataset.cpp",
          "bob/io/base/cpp/HDF5File.cpp",
          "bob/io/base/cpp/HDF5Group.cpp",
          "bob/io/base/cpp/HDF5Types.cpp",
          "bob/io/base/cpp/HDF5Utils.cpp",
          "bob/io/base/cpp/reorder.cpp",
          "bob/io/base/cpp/T3File.cpp",
          "bob/io/base/cpp/TensorArrayFile.cpp",
          "bob/io/base/cpp/TensorFileHeader.cpp",
          "bob/io/base/cpp/utils.cpp",
          "bob/io/base/cpp/TensorFile.cpp",
          "bob/io/base/cpp/array.cpp",
          "bob/io/base/cpp/array_type.cpp",
          "bob/io/base/cpp/blitz_array.cpp",
        ],
        libraries = libraries,
        library_dirs = library_dirs,
        system_include_dirs = system_include_dirs,
        define_macros = define_macros,
        version = version,
        bob_packages = bob_packages,
        packages = packages,
        boost_modules = boost_modules,
      Extension("bob.io.base._library",
        [
André Anjos's avatar
André Anjos committed
          "bob/io/base/bobskin.cpp",
          "bob/io/base/codec.cpp",
André Anjos's avatar
André Anjos committed
          "bob/io/base/hdf5.cpp",
          "bob/io/base/main.cpp",
André Anjos's avatar
André Anjos committed
        library_dirs = library_dirs,
        libraries = libraries,
André Anjos's avatar
André Anjos committed
        define_macros = define_macros,
        system_include_dirs = system_include_dirs,
        version = version,
        bob_packages = bob_packages,
        packages = packages,
        boost_modules = boost_modules,
    cmdclass = {
      'build_ext': build_ext
    },

    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',