forked from wnd-charm/wnd-charm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
121 lines (105 loc) · 4.19 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/usr/bin/env python
"""
setup.py file for SWIG-ified wndchrm
"""
from setuptools import setup, Extension
# Need to subclass setuptools/distutils objects to change build order
# such that dynamically-generated swig files will be present when MANIFEST is created.
# See http://stackoverflow.com/a/21236111/1017549
from distutils.command.build import build
from setuptools.command.install import install
class CustomBuild( build):
def run(self):
self.run_command('build_ext')
build.run(self)
class CustomInstall(install):
def run(self):
self.run_command('build_ext')
self.do_egg_install()
import os
pkg_dir = os.path.join( os.path.dirname( os.path.realpath(__file__)), 'wndcharm' )
# this sets the __version__ variable
# the wndcharm/_version.py file contains a single line assigning the __version__ variable
# This file gets imported by __init__.py to set __version__ during package import
# Here we do NOT want to import the package we are building to set this variable!
# We DO want to set the version in setup() and have it all synchronized from a single place (wndcharm/_version.py)
execfile(os.path.join (pkg_dir,'_version.py'))
try:
from subprocess import check_output
from os import devnull
with open( devnull, 'w' ) as bitbucket:
# Get the git hash for this commit
# If this returns non-zero, a.k.a. got a git repo, throws CalledProcessError
git_hash = check_output(['git', 'rev-parse', '--short', 'HEAD'], stderr=bitbucket ).strip()
# Check for local modifications
if check_output(['git', 'diff-index', '--name-only', 'HEAD'], stderr=bitbucket ).strip():
git_hash += 'localmod'
print "Building WND-CHARM {} at git repo commit {}...".format( __version__, git_hash )
# this construction matches what is done in __init__.py by importing
# both _version.py and _git_hash.py use "normalized" semantic version string (a.k.a., dots)
__version__ = __version__+ '+' + git_hash
with open( os.path.join( pkg_dir, '_git_hash.py' ), 'w+' ) as f:
f.write( "__git_hash__ = '{0}'\n".format( git_hash) )
except:
print "Building WND-CHARM {} release version...".format( __version__ )
# Since there's a large C++ underpinning for the wndcharm Python API, run autotools to test build environment
import os
if not os.path.exists( 'config.h' ):
cmd = os.getcwd() + os.sep + 'configure'
import subprocess
p = subprocess.call( [cmd] )
if p != 0:
print "Error running configure script"
import sys
sys.exit(p)
wndchrm_module = Extension('_wndcharm',
sources=[
'wndcharm/swig/wndcharm.i',
'src/colors/FuzzyCalc.cpp',
'src/statistics/CombFirst4Moments.cpp',
'src/statistics/FeatureStatistics.cpp',
'src/textures/gabor.cpp',
'src/textures/haralick/CVIPtexture.cpp',
'src/textures/haralick/haralick.cpp',
'src/textures/tamura.cpp',
'src/textures/zernike/complex.cpp',
'src/textures/zernike/zernike.cpp',
'src/transforms/ChebyshevFourier.cpp',
'src/transforms/chebyshev.cpp',
'src/transforms/radon.cpp',
'src/transforms/wavelet/Common.cpp',
'src/transforms/wavelet/convolution.cpp',
'src/transforms/wavelet/DataGrid2D.cpp',
'src/transforms/wavelet/DataGrid3D.cpp',
'src/transforms/wavelet/Filter.cpp',
'src/transforms/wavelet/FilterSet.cpp',
'src/transforms/wavelet/Symlet5.cpp',
'src/transforms/wavelet/Wavelet.cpp',
'src/transforms/wavelet/WaveletHigh.cpp',
'src/transforms/wavelet/WaveletLow.cpp',
'src/transforms/wavelet/WaveletMedium.cpp',
'src/transforms/wavelet/wt.cpp',
'src/cmatrix.cpp',
'src/wndchrm_error.cpp',
'src/ImageTransforms.cpp',
'src/FeatureAlgorithms.cpp',
'src/Tasks.cpp',
'src/FeatureNames.cpp',
'src/gsl/specfunc.cpp',
],
include_dirs=['./','src/', '/usr/local/include'],
swig_opts=['-threads', '-c++', '-I./', '-I./src', '-outdir', 'wndcharm'],
libraries=['tiff','fftw3'],
)
setup (
cmdclass={'build': CustomBuild, 'install': CustomInstall},
name = 'wndcharm',
version = __version__,
author = "Chris Coletta, Ilya Goldberg",
url = 'https://github.com/wnd-charm/wnd-charm',
description = """Python bindings for wnd-charm""",
license = 'LGPLv2',
ext_modules = [wndchrm_module],
packages = ['wndcharm'],
install_requires=['numpy', 'scipy'],
)