-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathsetup.py
More file actions
109 lines (94 loc) · 3.14 KB
/
setup.py
File metadata and controls
109 lines (94 loc) · 3.14 KB
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
#!/usr/bin/env python
import re
import pathlib
import platform
import sys
from setuptools import setup
from setuptools import dist
from setuptools.extension import Extension
from wheel.bdist_wheel import bdist_wheel
# https://github.com/joerick/python-abi3-package-sample/blob/main/setup.py
class bdist_wheel_abi3(bdist_wheel): # noqa: D101
def get_tag(self): # noqa: D102
python, abi, plat = super().get_tag()
if python.startswith("cp"):
return "cp311", "abi3", plat
return python, abi, plat
requirements = [
'numpy',
'scipy',
'nibabel>=2.1',
'Pillow',
'xxhash',
]
packages = [
'surfa',
'surfa.core',
'surfa.transform',
'surfa.image',
'surfa.mesh',
'surfa.io',
'surfa.vis',
]
# base source directory
base_dir = pathlib.Path(__file__).parent.resolve()
# configure c extensions
ext_opts = dict(
extra_compile_args=['-O3', '-std=c99'],
define_macros=[('NPY_NO_DEPRECATED_API', 'NPY_1_7_API_VERSION')],
)
macros = []
setup_opts = {}
if sys.version_info.minor >= 11 and platform.python_implementation() == "CPython":
# Can create an abi3 wheel (typed memoryviews first available in 3.11)!
ext_opts["define_macros"].append(("Py_LIMITED_API", "0x030B0000"))
ext_opts["py_limited_api"] = True
setup_opts["cmdclass"] = {"bdist_wheel": bdist_wheel_abi3}
extensions = [
Extension('surfa.image.interp', [f'surfa/image/interp.pyx'], **ext_opts),
Extension('surfa.mesh.intersection', [f'surfa/mesh/intersection.pyx'], **ext_opts),
]
# since we interface the c stuff with numpy, it's another hard
# requirement at build-time
import numpy as np
include_dirs = [np.get_include()]
# extract the current version
init_file = base_dir.joinpath('surfa/__init__.py')
init_text = open(init_file, 'rt').read()
pattern = r"^__version__ = ['\"]([^'\"]*)['\"]"
match = re.search(pattern, init_text, re.M)
if not match:
raise RuntimeError(f'Unable to find __version__ in {init_file}.')
version = match.group(1)
long_description = '''Surfa is a collection of Python utilities for medical image
analysis and mesh-based surface processing. It provides tools that operate on 3D image
arrays and triangular meshes with consideration of their representation in a world (or
scanner) coordinate system. While broad in scope, surfa is developed with particular
emphasis on neuroimaging applications.
'''
# run setup
setup(
name='surfa',
version=version,
license='MIT',
license_files = ('LICENSE.txt',),
description='Utilities for medical image and surface processing.',
long_description=long_description,
long_description_content_type='text/x-rst',
author='Andrew Hoopes',
author_email='freesurfer@nmr.mgh.harvard.edu',
url='https://github.com/freesurfer/surfa',
python_requires='>=3.8',
packages=packages,
ext_modules=extensions,
include_dirs=include_dirs,
package_data={'': ['*.pyx'], '': ['*.h']},
install_requires=requirements,
classifiers=[
'Development Status :: 3 - Alpha',
'Programming Language :: Python :: 3',
'Natural Language :: English',
'Topic :: Scientific/Engineering',
],
**setup_opts,
)