forked from fhs/pyhdf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
147 lines (130 loc) · 4.83 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
from __future__ import print_function
# Allows bdist_egg to work if you have setuptools installed.
# This import must be before the numpy.distutils import of setup.
# Otherwise, no harm.
try:
import setuptools
except:
pass
from numpy.distutils.core import setup, Extension
import sys
import os
import os.path as path
def _find_args(pat, env):
val = os.environ.get(env, [])
if val:
val = val.split(os.pathsep)
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
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 = os.environ.get('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)
if sys.platform == 'win32':
try:
k = sys.argv.index('--hdf4')
baseloc = sys.argv[k+1]
del sys.argv[k]
del sys.argv[k]
except (ValueError, IndexError):
baseloc = None
if not baseloc:
baseloc = os.environ.get('HDF4', None)
if baseloc:
# fix include_dirs and library_dirs
# based on fixed set of paths
if not path.exists(baseloc):
print("\n******\n%s not found\n******\n\n" % baseloc)
raise RuntimeError(msg)
if not path.isdir(baseloc):
print("\n******\n%s not a directory \n******\n\n" % baseloc)
raise RuntimeError(msg)
alldirs = os.listdir(baseloc)
include_dirs = []
library_dirs = []
for adir in alldirs:
if not path.isdir(path.sep.join([baseloc, adir])):
continue
if adir.startswith('42'):
include_dirs.append(path.sep.join([baseloc, adir, 'include']))
library_dirs.append(path.sep.join([baseloc, adir, 'dll']))
library_dirs.append(path.sep.join([baseloc, adir, 'lib']))
print("Using include_dirs = ", include_dirs)
print("Using library_dirs = ", library_dirs)
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':
# Find DLL path
dll_path = ''
for p in library_dirs:
if path.exists(p + os.path.sep + "HM423M.DLL"):
dll_path = p + os.path.sep
break
if dll_path == '':
raise RuntimeError("Cannot find required HDF4 DLLs -- check LIBRARY_DIRS")
if sys.platform == 'win32':
libraries = ["hm423m", "hd423m", "xdr_for_dll" ]
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"]
_hdfext = Extension('pyhdf._hdfext',
sources = ["pyhdf/hdfext_wrap.c"],
include_dirs = include_dirs,
extra_compile_args = extra_compile_args,
library_dirs = library_dirs,
extra_link_args=[extra_link_args],
libraries = libraries,
)
if sys.platform == 'win32':
data_files = [("pyhdf", [dll_path + x for x in ["HM423M.DLL", "HD423M.DLL"]])]
else:
data_files = []
setup(name = 'python-hdf4',
author = 'python-hdf4 authors',
description = 'Python interface to the NCSA HDF4 library',
keywords = ['hdf4', 'netcdf', 'numpy', 'python', 'pyhdf'],
license = 'public',
long_description = 'The pyhdf package wraps the functionality\n '
'of the NCSA HDF version 4 library inside a Python OOP\n '
'framework. The SD (scientific dataset), VS\n '
'(Vdata) and V (Vgroup) APIs are currently implemented.\n '
'SD datasets are read/written\n '
'through numpy arrays. netCDF files can also\n '
'be read and modified with pyhdf.',
url = 'http://www.sourceforge.net/projects/pysclint',
version = '0.8.3',
packages = ['pyhdf'],
ext_modules = [_hdfext],
data_files = data_files
)