-
Notifications
You must be signed in to change notification settings - Fork 16
/
setup.py
110 lines (93 loc) · 2.94 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
from __future__ import print_function
import sys
import os
import os.path as path
import shlex
import sysconfig
from setuptools import Extension, setup
import numpy as np
def _find_args(pat, env):
try:
val = os.environ[env].split(os.pathsep)
except KeyError:
val = []
try:
k = sys.argv.index(pat)
val.extend(sys.argv[k + 1].split(os.pathsep))
del sys.argv[k]
del sys.argv[k]
except ValueError:
pass
return val
# A Debian based linux distribution might be using libhdf4 (contains netcdf
# routines) or libhdf4-alt (does not contain netcdf routines). This function
# tries to detect if the alt version should be used.
def _use_hdf4alt(libdirs):
if not sys.platform.startswith("linux"):
return False
libdirs.extend(os.environ.get("LD_LIBRARY_PATH", "").split(os.pathsep))
libdirs.append("/usr/lib/%s" % sysconfig.get_config_var('MULTIARCH'))
libdirs.append("/usr/lib")
libdirs.append("/usr/local/lib")
libdirs.append("/lib")
for d in libdirs:
if os.path.exists(os.path.join(d, "libdfalt.so")) and os.path.exists(
os.path.join(d, "libmfhdfalt.so")
):
return True
return False
include_dirs = _find_args("-i", "INCLUDE_DIRS")
library_dirs = _find_args("-l", "LIBRARY_DIRS")
szip_installed = "SZIP" in os.environ
compress = "NO_COMPRESS" not in os.environ
extra_link_args = None
if "LINK_ARGS" in os.environ:
extra_link_args = shlex.split(os.environ["LINK_ARGS"])
msg = (
"Cannot proceed without the HDF4 library. Please "
"export INCLUDE_DIRS and LIBRARY_DIRS as explained"
"in the INSTALL file."
)
if sys.platform.startswith("linux"):
# libhdf4 header files on most linux distributations
# (e.g. Debian/Ubuntu, CentOS) are stored in /usr/include/hdf
d = "/usr/include/hdf/"
if not include_dirs and os.path.exists(d):
include_dirs.append(d)
for p in include_dirs + library_dirs:
if not path.exists(p):
print("\n******\n%s not found\n******\n\n" % p)
raise RuntimeError(msg)
if sys.platform == "win32":
libraries = ["mfhdf", "hdf", "xdr"]
elif _use_hdf4alt(library_dirs):
libraries = ["mfhdfalt", "dfalt"]
else:
libraries = ["mfhdf", "df"]
if szip_installed:
extra_compile_args = []
if sys.platform == "win32":
libraries += ["szlib"]
else:
libraries += ["sz"]
else:
extra_compile_args = ["-DNOSZIP"]
if sys.platform == "win32":
libraries += ["libjpeg", "zlib", "ws2_32"]
else:
libraries += ["jpeg", "z"]
if not compress:
extra_compile_args += ["-DNOCOMPRESS"]
setup(
ext_modules=[
Extension(
name="pyhdf._hdfext",
sources=["pyhdf/hdfext_wrap.c"],
include_dirs=[np.get_include()] + include_dirs,
extra_compile_args=extra_compile_args,
library_dirs=library_dirs,
extra_link_args=extra_link_args,
libraries=libraries,
),
],
)