-
Notifications
You must be signed in to change notification settings - Fork 53
/
setup.py
113 lines (90 loc) · 3.21 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
"""A setuptools based setup module.
See:
https://packaging.python.org/en/latest/distributing.html
https://github.com/pypa/sampleproject
"""
# Always prefer setuptools over distutils
from setuptools import setup, find_packages
# To use a consistent encoding
from codecs import open
from Cython.Build import cythonize
import os
import shutil
import tempfile
import subprocess
import numpy
here = os.path.abspath(os.path.dirname(__file__))
def make_ext(modname, pyxfilename):
from setuptools.extension import Extension
omp_test = \
r"""
#include <omp.h>
#include <stdio.h>
int main() {
#pragma omp parallel
printf("Hello from thread %d, nthreads %d\n", omp_get_thread_num(), omp_get_num_threads());
}
"""
def check_for_openmp():
tmpdir = tempfile.mkdtemp()
curdir = os.getcwd()
os.chdir(tmpdir)
filename = r'test.c'
with open(filename, 'w') as file:
file.write(omp_test)
with open(os.devnull, 'w') as fnull:
result = subprocess.call(['cc', '-fopenmp', filename],
stdout=fnull, stderr=fnull)
os.chdir(curdir)
# clean up
shutil.rmtree(tmpdir)
# zero error code means everything was fine
return result == 0
extra_compile_args = ['-O3', '-march=x86-64']
extra_link_args = []
if check_for_openmp():
print("Building with OpenMP support!")
extra_compile_args.append('-fopenmp')
extra_link_args.append('-fopenmp')
else:
print("NO OpenMP support!")
return Extension(name=modname, sources=[pyxfilename],
extra_compile_args=extra_compile_args,
extra_link_args=extra_link_args,
include_dirs=[numpy.get_include()],
)
# Get the long description from the relevant file
# with open(os.path.join(here, 'DESCRIPTION.rst'), encoding='utf-8') as f:
# long_description = f.read()
# Extension
extensions = [make_ext(modname="qsm_tgv_cython_helper", pyxfilename="TGV_QSM/qsm_tgv_cython_helper.pyx")]
setup(
name='TGV_QSM',
version='0.1',
description='A sample Python project',
long_description='TGVQSM',
# The project's main homepage.
# url='https://github.com/pypa/sampleproject',
# Author details
author='Christian Langkammer',
author_email='christian@neuroimaging.at',
# Choose your license
license='',
# What does your project relate to?
keywords='MRI QSM TGV',
# You can just specify the packages manually here if your project is
# simple. Or you can use find_packages().
packages=find_packages(),
# List run-time dependencies here. These will be installed by pip when
# your project is installed. For an analysis of "install_requires" vs pip's
# requirements files see:
# https://packaging.python.org/en/latest/requirements.html
# We explicitly do not list nipype as a dependency here! Should be installable without nipype
install_requires=['numpy', 'cython', 'nibabel'],
ext_modules = cythonize(extensions),
entry_points={
'console_scripts': [
'tgv_qsm=TGV_QSM.qsm_tgv_main:main',
]
}
)