forked from nipy/nipy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
executable file
·165 lines (139 loc) · 5.95 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#!/usr/bin/env python
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:
import os
from os.path import join as pjoin, exists
import sys
from glob import glob
from distutils import log
# BEFORE importing distutils, remove MANIFEST. distutils doesn't properly
# update it when the contents of directories change.
if exists('MANIFEST'): os.remove('MANIFEST')
# Import build helpers
try:
from nisext.sexts import package_check, get_comrec_build
except ImportError:
raise RuntimeError('Need nisext package from nibabel installation'
' - please install nibabel first')
from setup_helpers import (generate_a_pyrex_source,
cmdclass, INFO_VARS,
build_py) # build_py will do 2to3 for Python3
# monkey-patch numpy distutils to use Cython instead of Pyrex
from numpy.distutils.command.build_src import build_src
build_src.generate_a_pyrex_source = generate_a_pyrex_source
# Add custom commit-recording build command
cmdclass['build_py'] = get_comrec_build('nipy', build_py)
def configuration(parent_package='',top_path=None):
from numpy.distutils.misc_util import Configuration
config = Configuration(None, parent_package, top_path)
config.set_options(ignore_setup_xxx_py=True,
assume_default_configuration=True,
delegate_options_to_subpackages=True,
quiet=True)
# The quiet=True option will silence all of the name setting warnings:
# Ignoring attempt to set 'name' (from 'nipy.core' to
# 'nipy.core.image')
# Robert Kern recommends setting quiet=True on the numpy list, stating
# these messages are probably only used in debugging numpy distutils.
config.get_version(pjoin('nipy', 'info.py')) # sets config.version
config.add_subpackage('nipy', 'nipy')
return config
################################################################################
# For some commands, use setuptools
if len(set(('develop', 'bdist_egg', 'bdist_rpm', 'bdist', 'bdist_dumb',
'bdist_wininst', 'install_egg_info', 'egg_info', 'easy_install',
'bdist_mpkg',
)).intersection(sys.argv)) > 0:
from setup_egg import extra_setuptools_args
# extra_setuptools_args can be defined from the line above, but it can
# also be defined here because setup.py has been exec'ed from
# setup_egg.py.
if not 'extra_setuptools_args' in globals():
extra_setuptools_args = dict()
# Hard and soft dependency checking
package_check('numpy', INFO_VARS['NUMPY_MIN_VERSION'])
package_check('scipy', INFO_VARS['SCIPY_MIN_VERSION'])
package_check('nibabel', INFO_VARS['NIBABEL_MIN_VERSION'])
package_check('sympy', INFO_VARS['SYMPY_MIN_VERSION'])
def _mayavi_version(pkg_name):
"""Mayavi2 pruned enthought. namespace at 4.0.0
"""
v = ''
try:
from mayavi import version
v = version.version
if v == '':
v = '4.0.0' # must be the one in Debian
except ImportError:
from enthought.mayavi import version
v = version.version
return v
package_check('mayavi',
INFO_VARS['MAYAVI_MIN_VERSION'],
optional=True,
version_getter=_mayavi_version)
# Cython can be a build dependency
def _cython_version(pkg_name):
from Cython.Compiler.Version import version
return version
package_check('cython',
INFO_VARS['CYTHON_MIN_VERSION'],
optional=True,
version_getter=_cython_version,
messages={'opt suffix': ' - you will not be able '
'to rebuild Cython source files into C files',
'missing opt': 'Missing optional build-time '
'package "%s"'}
)
################################################################################
# commands for installing the data
from numpy.distutils.command.install_data import install_data
from numpy.distutils.command.build_ext import build_ext
def data_install_msgs():
# Check whether we have data packages
from nibabel.data import datasource_or_bomber
DATA_PKGS = INFO_VARS['DATA_PKGS']
templates = datasource_or_bomber(DATA_PKGS['nipy-templates'])
example_data = datasource_or_bomber(DATA_PKGS['nipy-data'])
for dpkg in (templates, example_data):
if hasattr(dpkg, 'msg'): # a bomber object, warn
log.warn('%s\n%s' % ('_'*80, dpkg.msg))
class MyInstallData(install_data):
""" Subclass the install_data to generate data install warnings if necessary
"""
def run(self):
install_data.run(self)
data_install_msgs()
class MyBuildExt(build_ext):
""" Subclass the build_ext to generate data install warnings if
necessary: warn at build == warn early
This is also important to get a warning when run a 'develop'.
"""
def run(self):
build_ext.run(self)
data_install_msgs()
cmdclass['install_data'] = MyInstallData
cmdclass['build_ext'] = MyBuildExt
################################################################################
def main(**extra_args):
from numpy.distutils.core import setup
setup(name=INFO_VARS['NAME'],
maintainer=INFO_VARS['MAINTAINER'],
maintainer_email=INFO_VARS['MAINTAINER_EMAIL'],
description=INFO_VARS['DESCRIPTION'],
long_description=INFO_VARS['LONG_DESCRIPTION'],
url=INFO_VARS['URL'],
download_url=INFO_VARS['DOWNLOAD_URL'],
license=INFO_VARS['LICENSE'],
classifiers=INFO_VARS['CLASSIFIERS'],
author=INFO_VARS['AUTHOR'],
author_email=INFO_VARS['AUTHOR_EMAIL'],
platforms=INFO_VARS['PLATFORMS'],
# version set by config.get_version() above
requires=INFO_VARS['REQUIRES'],
configuration = configuration,
cmdclass = cmdclass,
scripts = glob('scripts/*'),
**extra_args)
if __name__ == "__main__":
main(**extra_setuptools_args)