forked from pyhrf/pyhrf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
executable file
·174 lines (138 loc) · 6.25 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
166
167
168
169
170
171
172
173
174
#!/usr/bin/env python2
"""Setup script for PyHRF"""
from __future__ import print_function
from setuptools import setup
import sys
# The current version of PyHRF works with python 2.7.X
if sys.version_info[:2] < (2, 7) or (3, 0) <= sys.version_info[:2]:
raise RuntimeError("Python version 2.7 required.")
def parse_setuppy_commands():
"""Check the commands and respond appropriately. Disable broken commands.
Returns:
bool: Return a boolean value for whether or not to run the build (avoid installing numpy and other dependencies)
"""
if len(sys.argv) < 2:
# User forgot to give an argument probably, let setuptools handle that.
return True
good_commands = ('develop', 'install', 'sdist', 'build', 'build_ext',
'build_py', 'build_clib', 'build_scripts', 'bdist_wheel',
'bdist_rpm', 'bdist_wininst', 'bdist_msi', 'bdist_mpkg',
'build_sphinx')
for command in good_commands:
if command in sys.argv[1:]:
return False
return True
def setup_package():
"""Configuration of the setup"""
if parse_setuppy_commands():
extra_setuptools_args = dict()
else:
from setuptools import find_packages, Extension
from glob import glob
try: # for pip >= 10
from pip._internal.req import parse_requirements
except ImportError: # for pip <= 9.0.3
from pip.req import parse_requirements
import pip
# Dependencies for building C Extensions
try:
dependencies = list(parse_requirements('requirements.txt', session=False))
except TypeError:
# new versions of pip requires a session
dependencies = list(parse_requirements('requirements.txt', session=pip.download.PipSession()))
dependencies = [str(package.req) for package in dependencies]
# Installing the required packages to build C extensions
for package in dependencies:
pip.main(['install', package])
import numpy
c_extensions = [Extension(ext_name, sources=['src/pyhrf/' + filepath])
for (ext_name, filepath) in
[('pyhrf.jde.intensivecalc', 'jde/intensivecalc.c'),
('pyhrf.boldsynth.pottsfield.pottsfield_c', 'boldsynth/pottsfield/pottsField.c'),
('pyhrf.vbjde.UtilsC', 'vbjde/utilsmodule.c'),
('pyhrf.cparcellation', 'cparcellation.c')]]
extra_setuptools_args = dict(
package_dir={'': 'python'},
packages=find_packages("python"),
include_package_data=True,
scripts=glob('./bin/*'),
zip_safe=False, # pyhrf has C/C++ extensions, so it's not zip safe.
ext_modules=c_extensions,
include_dirs=[numpy.get_include()],
setup_requires=dependencies,
install_requires=dependencies,
extras_require={"cluster": ["soma-workflow"],
"simulation": ["Pillow>=2.3"],
"parcellation": ["munkres>=1.0"],
"pipelines": ["pygraphviz>=1.1"],
"graph": ["python-graph-core>=1.8"]})
# Get the long description from the README file
with open('README.rst') as readme_file:
long_description = readme_file.read()
metadata = dict(
name='pyhrf',
version='0.5.0',
description='Analysis of fMRI data based on the study of hemodynamics',
long_description=long_description,
maintainer='Jaime Arias',
maintainer_email='[email protected]',
url='http://pyhrf.org',
license='CeCILLv2',
download_url='https://github.com/pyhrf/pyhrf',
classifiers=[
"Development Status :: 3 - Alpha",
"Environment :: Console",
"Intended Audience :: Science/Research",
"License :: OSI Approved",
"Programming Language :: Python :: 2",
"Programming Language :: Python :: 2.7",
"Programming Language :: C",
"Programming Language :: Python :: Implementation :: CPython",
"Topic :: Scientific/Engineering",
"Topic :: Scientific/Engineering :: Mathematics",
"Topic :: Scientific/Engineering :: Medical Science Apps.",
],
**extra_setuptools_args
)
setup(**metadata)
if __name__ == '__main__':
setup_package()
if 'install' in sys.argv[1]:
import colorama
colorama.init(autoreset=True)
def red(text):
"""Return a red terminal text"""
return "{}{}".format(colorama.Fore.RED, text)
def green(text):
"""Return a green terminal text"""
return "{}{}".format(colorama.Fore.GREEN, text)
def yellow(text):
"""Return a yellow terminal text"""
return "{}{}".format(colorama.Fore.YELLOW, text)
def check_opt_dep(dep_name, dep_descrip):
"""
Return a message telling if dependency *dep_name* is available
with an import
"""
try:
__import__(dep_name)
except ImportError:
return red(
"{} is *NOT IMPORTABLE*, {} will *NOT* be available".format(
dep_name,
dep_descrip))
return green(
"{} is importable, {} will be available".format(dep_name,
dep_descrip))
# Optional deps and description of associated feature:
OPTIONAL_DEPS = {
"soma_workflow": 'cluster parallel feature (eg pyhrf_jde_estim -x cluster)',
'PIL': "loading of image file as simulation maps",
'munkres': 'computation of distance between parcellations',
'pygraph': '(python-graph-core) -- save plot of simulation pipelines',
'pygraphviz': 'optimized graph operations and outputs',
}
print(yellow('\nOptional dependencies:'))
print('\n'.join(
['- ' + check_opt_dep(dn, dd) for dn, dd in OPTIONAL_DEPS.items()]))
print(yellow('\nExecute pyhrf_maketests to run package tests.\n'))