17
17
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
18
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
19
# SOFTWARE.
20
-
21
20
import functools
22
21
import os
23
22
import shutil
24
23
import subprocess
25
24
import sys
26
25
import tempfile
26
+ from distutils .errors import CompileError
27
27
from pathlib import Path
28
28
29
29
from setuptools import Extension , find_packages , setup
@@ -39,15 +39,31 @@ class IsalExtension(Extension):
39
39
40
40
class BuildIsalExt (build_ext ):
41
41
def build_extension (self , ext ):
42
- if isinstance (ext , IsalExtension ):
43
- _add_extension_options (ext )
42
+ if not isinstance (ext , IsalExtension ):
43
+ super ().build_extension (ext )
44
+ return
44
45
# Import cython here because it should be installed by setup requires.
45
46
from Cython .Build import cythonize
46
47
cythonized_module = cythonize (ext )[0 ]
47
48
# _needs_stub is apparently not set elsewhere. It is not needed for
48
49
# a functional isal extension.
49
50
setattr (cythonized_module , "_needs_stub" , False )
50
- super ().build_extension (cythonized_module )
51
+ possible_prefixes = [sys .exec_prefix , sys .base_exec_prefix ]
52
+ for prefix in possible_prefixes :
53
+ if os .path .exists (os .path .join (prefix , "include" , "isa-l" )):
54
+ ext .include_dirs = [os .path .join (prefix , "include" )]
55
+ ext .libraries = ["isal" ]
56
+ try :
57
+ super ().build_extension (cythonized_module )
58
+ except CompileError : # Dynamic linking failed
59
+ ext .libraries = [] # Make sure libraries are empty
60
+ isa_l_prefix_dir = build_isa_l ()
61
+ ext .include_dirs = [os .path .join (isa_l_prefix_dir , "include" )]
62
+ # -fPIC needed for proper static linking
63
+ ext .extra_compile_args = ["-fPIC" ]
64
+ ext .extra_objects = [
65
+ os .path .join (isa_l_prefix_dir , "lib" , "libisal.a" )]
66
+ super ().build_extension (cythonized_module )
51
67
52
68
53
69
# Use a cache to prevent isa-l from being build twice. According to the
@@ -78,25 +94,6 @@ def build_isa_l():
78
94
return temp_prefix
79
95
80
96
81
- def _add_extension_options (ext : Extension ):
82
- # Check current environment (conda or venv first) or base system install
83
- # (in case of venv) for isa-l include directories. Link dynamically.
84
- possible_prefixes = [sys .exec_prefix , sys .base_exec_prefix , "/usr" ]
85
- for prefix in possible_prefixes :
86
- if os .path .exists (os .path .join (prefix , "include" , "isa-l" )):
87
- # Readthedocs uses a conda environment but does not activate it.
88
- ext .include_dirs = [os .path .join (prefix , "include" )]
89
- ext .libraries = ["isal" ]
90
- break
91
- else : # If not installed, build isa-l and link statically.
92
- isa_l_prefix_dir = build_isa_l ()
93
- ext .include_dirs = [os .path .join (isa_l_prefix_dir , "include" )]
94
- # -fPIC needed for proper static linking
95
- ext .extra_compile_args = ["-fPIC" ]
96
- ext .extra_objects = [os .path .join (isa_l_prefix_dir , "lib" , "libisal.a" )
97
- ]
98
-
99
-
100
97
setup (
101
98
name = "isal" ,
102
99
version = "0.3.0-dev" ,
0 commit comments