setup.py 7.59 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']

André Anjos's avatar
André Anjos committed
8
from setuptools import setup, find_packages, dist
9
dist.Distribution(dict(setup_requires=['bob.extension', 'bob.blitz'] + bob_packages))
10
from bob.extension.utils import egrep, find_header, find_library
11
from bob.extension import pkgconfig
12
from bob.blitz.extension import Extension, Library, build_ext
13

14
15
16
from bob.extension.utils import load_requirements
build_requires = load_requirements()

17
18
# Define package version
version = open("version.txt").read().rstrip()
19

20
packages = ['boost']
Manuel Günther's avatar
Manuel Günther committed
21
22
boost_modules = ['system', 'filesystem']

23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import os
def libhdf5_version(header):

  vv = egrep(header, r"#\s*define\s+H5_VERSION\s+\"([\d\.]+)\"")
  if not len(vv): return None
  return vv[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

    self.name = 'hdf5'
53
54
55
56

    # try to locate pkg-config on our own first
    try:

57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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
      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_directories = [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')
          vv = libhdf5_version(version_header)
          available = LooseVersion(vv)
          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_directories = [os.path.dirname(candidate)]
            self.version = vv
            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
Manuel Günther's avatar
Manuel Günther committed
98
      self.include_directories = [os.path.normpath(i) for i in self.include_directories]
99
100

      # find library
Manuel Günther's avatar
Manuel Günther committed
101
      prefix = os.path.dirname(os.path.dirname(self.include_directories[0]))
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
      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 libhdf5 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_directories = [os.path.dirname(candidates[0])]

119
120
121
122
123
124
125
126
127
128
    except RuntimeError:
      # now, we try to use pkg-config, which seems to be only available on Debian
      pkg = pkgconfig('hdf5')
      self.include_directories = pkg.include_directories()
      version_header = os.path.join(self.include_directories[0], 'H5pubconf.h')
      self.version = libhdf5_version(version_header)
      self.libraries = pkg.libraries()
      self.library_directories = pkg.library_directories()


129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
  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_directories

library_dirs = hdf5_pkg.library_directories

libraries = hdf5_pkg.libraries

define_macros = hdf5_pkg.macros()


147
148
setup(

André Anjos's avatar
André Anjos committed
149
    name='bob.io.base',
150
    version=version,
151
    description='Basic IO for Bob',
André Anjos's avatar
André Anjos committed
152
    url='http://github.com/bioidiap/bob.io.base',
153
154
155
156
157
158
159
160
    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
161
    zip_safe=False,
162

163
164
    setup_requires = build_requires,
    install_requires = build_requires,
165

166

167
168

    ext_modules = [
André Anjos's avatar
André Anjos committed
169
      Extension("bob.io.base.version",
170
        [
André Anjos's avatar
André Anjos committed
171
          "bob/io/base/version.cpp",
172
        ],
173
174
        define_macros = define_macros,
        system_include_dirs = system_include_dirs,
175
        version = version,
Manuel Günther's avatar
Manuel Günther committed
176
177
178
179
        bob_packages = bob_packages,
        packages = packages,
        boost_modules = boost_modules,
      ),
180

181
      Library("bob.io.base.bob_io_base",
182
        [
André Anjos's avatar
André Anjos committed
183
          "bob/io/base/cpp/CodecRegistry.cpp",
184
185
186
          "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
187
188
189
190
191
192
          "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",
193
194
195
196
197
198
199
200
201
          "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",
202
        ],
203
204
205
206
        libraries = libraries,
        library_dirs = library_dirs,
        system_include_dirs = system_include_dirs,
        define_macros = define_macros,
207
        version = version,
Manuel Günther's avatar
Manuel Günther committed
208
209
210
        bob_packages = bob_packages,
        packages = packages,
        boost_modules = boost_modules,
211
      ),
André Anjos's avatar
André Anjos committed
212

213
214
      Extension("bob.io.base._library",
        [
André Anjos's avatar
André Anjos committed
215
216
          "bob/io/base/bobskin.cpp",
          "bob/io/base/codec.cpp",
217
          "bob/io/base/file.cpp",
André Anjos's avatar
André Anjos committed
218
219
          "bob/io/base/hdf5.cpp",
          "bob/io/base/main.cpp",
220
        ],
221
222
223
224
        library_dirs = library_dirs,
        libraries = libraries,
        define_macros = define_macros,
        system_include_dirs = system_include_dirs,
225
        version = version,
Manuel Günther's avatar
Manuel Günther committed
226
227
228
        bob_packages = bob_packages,
        packages = packages,
        boost_modules = boost_modules,
229
230
      ),
    ],
231

232
233
234
235
    cmdclass = {
      'build_ext': build_ext
    },

236
    classifiers = [
237
238
      'Framework :: Bob',
      'Development Status :: 4 - Beta',
239
240
241
242
243
244
      'Intended Audience :: Developers',
      'License :: OSI Approved :: BSD License',
      'Natural Language :: English',
      'Programming Language :: Python',
      'Programming Language :: Python :: 3',
      'Topic :: Software Development :: Libraries :: Python Modules',
245
    ],
246

247
  )