|
2 | 2 |
|
3 | 3 | import re |
4 | 4 | import pathlib |
| 5 | +import platform |
| 6 | +import sys |
5 | 7 |
|
6 | 8 | from setuptools import setup |
7 | 9 | from setuptools import dist |
8 | 10 | from setuptools.extension import Extension |
| 11 | +from wheel.bdist_wheel import bdist_wheel |
| 12 | + |
| 13 | + |
| 14 | +# https://github.com/joerick/python-abi3-package-sample/blob/main/setup.py |
| 15 | +class bdist_wheel_abi3(bdist_wheel): # noqa: D101 |
| 16 | + def get_tag(self): # noqa: D102 |
| 17 | + python, abi, plat = super().get_tag() |
| 18 | + |
| 19 | + if python.startswith("cp"): |
| 20 | + return "cp311", "abi3", plat |
| 21 | + |
| 22 | + return python, abi, plat |
9 | 23 |
|
10 | 24 |
|
11 | 25 | requirements = [ |
|
30 | 44 | base_dir = pathlib.Path(__file__).parent.resolve() |
31 | 45 |
|
32 | 46 | # configure c extensions |
33 | | -ext_opts = dict(extra_compile_args=['-O3', '-std=c99']) |
| 47 | +ext_opts = dict( |
| 48 | + extra_compile_args=['-O3', '-std=c99'], |
| 49 | + define_macros=[('NPY_NO_DEPRECATED_API', 'NPY_1_7_API_VERSION')], |
| 50 | +) |
| 51 | +macros = [] |
| 52 | +setup_opts = {} |
| 53 | +if sys.version_info.minor >= 11 and platform.python_implementation() == "CPython": |
| 54 | + # Can create an abi3 wheel (typed memoryviews first available in 3.11)! |
| 55 | + ext_opts["define_macros"].append(("Py_LIMITED_API", "0x030B0000")) |
| 56 | + ext_opts["py_limited_api"] = True |
| 57 | + setup_opts["cmdclass"] = {"bdist_wheel": bdist_wheel_abi3} |
34 | 58 | extensions = [ |
35 | 59 | Extension('surfa.image.interp', [f'surfa/image/interp.pyx'], **ext_opts), |
36 | 60 | Extension('surfa.mesh.intersection', [f'surfa/mesh/intersection.pyx'], **ext_opts), |
37 | 61 | ] |
38 | 62 |
|
39 | | -from Cython.Build import cythonize |
40 | | -extensions = cythonize(extensions, compiler_directives={'language_level' : '3'}) |
41 | | - |
42 | 63 | # since we interface the c stuff with numpy, it's another hard |
43 | 64 | # requirement at build-time |
44 | 65 | import numpy as np |
|
72 | 93 | author='Andrew Hoopes', |
73 | 94 | author_email='freesurfer@nmr.mgh.harvard.edu', |
74 | 95 | url='https://github.com/freesurfer/surfa', |
75 | | - python_requires='>=3.6', |
| 96 | + python_requires='>=3.8', |
76 | 97 | packages=packages, |
77 | 98 | ext_modules=extensions, |
78 | 99 | include_dirs=include_dirs, |
|
84 | 105 | 'Natural Language :: English', |
85 | 106 | 'Topic :: Scientific/Engineering', |
86 | 107 | ], |
| 108 | + **setup_opts, |
87 | 109 | ) |
0 commit comments