-
Notifications
You must be signed in to change notification settings - Fork 8
/
setup.py
98 lines (86 loc) · 2.76 KB
/
setup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
53
54
55
56
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
98
from __future__ import print_function
import os
import sys
# Work around Setuptools' broken (Cython-unaware) monkeypatching
# to support Pyrex. I don't want to use Setuptools in this file, but it
# is used automatically (and automatically monkeypatches) if we're
# installed, for example, with pip.
try:
import setuptools.dist
import setuptools.extension
except ImportError:
pass
else:
setuptools.extension.Extension.__init__ = \
setuptools.dist._get_unpatched(setuptools.extension.Extension).__init__
from setuptools import setup
from distutils.command import sdist
from distutils.extension import Extension
# Import and use Cython if available.
try:
from Cython.Distutils import build_ext as build_pyx
HAVE_CYTHON = True
except ImportError:
HAVE_CYTHON = False
def _read(fn):
path = os.path.join(os.path.dirname(__file__), fn)
return open(path).read()
# Search far and wide for the dependencies.
INC_DIRS = ['/opt/local/include', os.path.expanduser('~/.brew/include')]
ext = Extension(
"lastfp._fplib",
[
"fplib.pyx",
"fplib/src/Filter.cpp",
"fplib/src/FingerprintExtractor.cpp",
"fplib/src/OptFFT.cpp",
],
language="c++",
include_dirs=['fplib/include'] + INC_DIRS,
libraries=["stdc++", "samplerate", "fftw3f"],
)
# If we don't have Cython, build from *.cpp instead of the Cython
# source. Also, if we do have Cython, make sure we use its build
# command.
cmdclass = {}
if HAVE_CYTHON:
cmdclass['build_ext'] = build_pyx
else:
ext.sources[0] = 'fplib.cpp'
# This silly hack, inspired by the pymt setup.py, runs Cython if we're
# doing a source distribution. The MANIFEST.in file ensures that the
# C++ source is included in the tarball also.
if 'sdist' in sys.argv:
if not HAVE_CYTHON:
print('We need Cython to build a source distribution.')
sys.exit(1)
from Cython.Compiler import Main
source = ext.sources[0] # hacky!
Main.compile(
source,
cplus = True,
full_module_name = ext.name,
)
setup(
name = 'pylastfp',
version = '0.6',
description = "bindings for Last.fm's acoustic fingerprinting (fplib)",
author = 'Adrian Sampson',
author_email = '[email protected]',
url = 'http://github.com/sampsyo/pylastfp/',
license = 'LGPL',
platforms = 'ALL',
long_description = _read('README.rst'),
classifiers = [
'Topic :: Multimedia :: Sound/Audio :: Analysis',
'License :: OSI Approved :: GNU Library or Lesser General '
'Public License (LGPL)',
'Development Status :: 4 - Beta',
'Intended Audience :: Developers',
],
install_requires = ['audioread'],
cmdclass = cmdclass,
ext_modules = [ext],
packages = ['lastfp'],
scripts = ['lastmatch.py'],
)