-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathsetup.py
executable file
·146 lines (127 loc) · 4.28 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
import sys
import os
import re
import glob
import setuptools
with open("dbdreader/__init__.py", "r") as fh:
while fh:
line = fh.readline().strip()
if '__version__' in line:
break
version_match = re.match(r'^__version__\s*=\s*(.*)$', line)
if not version_match:
raise ValueError("Could not determine version")
VERSION = version_match.group(1).replace('"', '').replace("'", "")
with open("README.rst", "r") as fh:
long_description = fh.read()
with open('requirements.txt') as fh:
install_requires = [line.strip() for line in fh]
# Now determine what we need to build ourselves.
sources = ["extension/py_dbdreader.c",
"extension/dbdreader.c",
"extension/decompress.c"]
include_dirs = ['extension/include']
library_dirs = []
def check_header_file_version(p):
version = dict(MAJOR=0, MINOR=0, RELEASE=0)
counter = 0
with open(p) as fp:
for line in fp:
if line.startswith("#define LZ4_VERSION"):
fields = line.strip().split()
for k in version.keys():
if k in fields[1]:
version[k] = fields[2]
counter += 1
if counter == 3:
break
if counter == 3:
v = ".".join((version["MAJOR"],
version["MINOR"],
version["RELEASE"]))
else:
v = ""
return v
def version_as_int(s):
major, minor, release = map(int, s.split('.'))
return release + minor*1000 + major*1000000
def has_header_file(header_file='lz4.h', required_version=None):
include_dirs = ['/usr/include',
'/usr/local/include']
found = False
for d in include_dirs:
p = os.path.join(d, header_file)
if os.path.exists(p):
found = True
break
if found:
version = check_header_file_version(p)
if version and required_version is None:
return True
else:
V = version_as_int(version)
Vreq = version_as_int(required_version)
return V >= Vreq
else:
return False
if sys.platform.startswith('linux'):
# we're on linux, so check for a system-wide installed library of
# lz4 and use that if available.
import ctypes
try:
# Try to load the lz4 library
ctypes.CDLL("liblz4.so.1")
except OSError:
liblz4_found = False
else:
# Library found, what about the include file?
if has_header_file('lz4.h', required_version='1.7.5'):
liblz4_found = True
else:
liblz4_found = False
elif sys.platform.startswith("win"):
liblz4_found = False
else:
liblz4_found = False
if liblz4_found:
# We are on a linux platform, and have access to system-wide
# installed library of lz4.
libraries = ['lz4']
else:
# we need to integrate the lz4 code in our build.
sources += ["lz4/lz4.c"]
libraries = []
include_dirs += ['lz4/include']
setuptools.setup(
name="dbdreader",
version=VERSION,
author="Lucas Merckelbach",
author_email="[email protected]",
description="A python module to access binary data files generated by Teledyne WebbResearch gliders",
long_description=long_description,
long_description_content_type="text/x-rst",
url='https://dbdreader.readthedocs.io/en/latest/',
packages=['dbdreader'],
package_data={'dbdreader': glob.glob("dbdreader/data/*")},
include_package_data=True,
py_modules=[],
entry_points={'console_scripts': ['dbdrename=dbdreader.scripts:dbdrename',
'cac_gen=dbdreader.scripts:cac_gen'],
'gui_scripts': []
},
scripts=[],
install_requires=install_requires,
ext_modules=[
setuptools.Extension("_dbdreader",
sources=sources,
libraries=libraries,
include_dirs=include_dirs,
library_dirs=library_dirs)
],
classifiers=[
"Programming Language :: Python :: 3",
'Intended Audience :: Science/Research',
'License :: OSI Approved :: GNU General Public License v3 (GPLv3)',
"Operating System :: POSIX",
],
)