-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathsetup.py
More file actions
209 lines (182 loc) · 6.13 KB
/
setup.py
File metadata and controls
209 lines (182 loc) · 6.13 KB
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# Copyright 2019 Gradient Health Inc. All Rights Reserved.
# Author: Marcelo Lerendegui <marcelo@gradienthealth.io>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ============================================================================
"""Setup for pip package."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from setuptools import find_packages
from setuptools import setup
from setuptools.command.build_ext import build_ext
from setuptools.dist import Distribution
import os
import sysconfig
import re
import sys
import platform
import subprocess
from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext
from distutils.version import LooseVersion
import tensorflow as tf
tf_L = tf.sysconfig.get_link_flags()[0][2::]
tf_l = tf.sysconfig.get_link_flags()[1][2::]
tf_I = tf.sysconfig.get_compile_flags()[0][2::]
tf_D = tf.sysconfig.get_compile_flags()[1][2::]
tf_decode_dicom_ext = Extension(
'gradient_decode_dicom.python.ops._decode_dicom_ops',
define_macros=[
('HAVE_CONFIG_H', None),
('USE_STD_CXX_INCLUDES', None),
('HAVE_CXX11', None),
(tf_D, None),
],
include_dirs=['/usr/local/include', tf_I],
libraries=[
tf_l,
'dcmjpeg',
'dcmjpls',
'dcmdata',
'dcmimgle',
'dcmimage',
'oflog',
'ofstd',
'z',
'm',
'rt',
'pthread',
],
library_dirs=['/usr/local/lib', tf_L, ],
extra_compile_args=['-fPIC', '-w', '-O2'],
language='c++11',
sources=[
'gradient_decode_dicom/cc/kernels/decode_dicom_data.cc',
'gradient_decode_dicom/cc/ops/decode_dicom_data_op.cc',
'gradient_decode_dicom/cc/kernels/decode_dicom_image.cc',
'gradient_decode_dicom/cc/ops/decode_dicom_image_op.cc'
]
)
deps = [
'-ldcmjpeg',
'-ldcmjpls',
'-ldcmdata',
'-ldcmimgle',
'-ldcmimage',
'-loflog',
'-lofstd',
'-lz',
'-lpthread',
]
deps_fix = [
'DCMTK-DEV',
'DCMTK-DEV',
'DCMTK-DEV',
'DCMTK-DEV',
'DCMTK-DEV',
'DCMTK-DEV',
'DCMTK-DEV',
'ZLIB',
'PTHREAD',
]
def get_ext_filename_without_platform_suffix(filename):
print(filename)
name, ext = os.path.splitext(filename)
ext_suffix = sysconfig.get_config_var('SO')
if ext_suffix == ext:
return filename
ext_suffix = ext_suffix.replace(ext, '')
idx = name.find(ext_suffix)
if idx == -1:
return filename
else:
return name[:idx] + ext
class BuildExtWithoutPlatformSuffix(build_ext, object):
def get_ext_filename(self, ext_name):
filename = super(BuildExtWithoutPlatformSuffix,
self).get_ext_filename(ext_name)
return get_ext_filename_without_platform_suffix(filename)
def CheckDeps():
with open(os.devnull, 'w') as devnull:
print("Checking OS Compatibility")
print("{} ........".format(platform.system()), end=" ")
if platform.system() == "Windows":
raise RuntimeError("ERROR: Windows not supported")
print(" OK")
print("Checking Library Dependencies")
for lib, lib_fix in zip(deps, deps_fix):
print("Library lib{} installed ........".format(lib[2::]), end=" ")
try:
s = subprocess.check_output(
['g++ test.cc {}'.format(lib)],
stderr=devnull,
shell=True
)
except:
print(
"ERROR: Missing required library: {}\n TO FIX THIS, INSTALL DCMTK-DEV".format(
lib_fix)
)
raise RuntimeError(
"ERROR: Missing required library: {}\n TO FIX THIS, INSTALL DCMTK-DEV".format(
lib_fix)
)
print("OK")
class BinaryDistribution(Distribution):
"""This class is needed in order to create OS specific wheels."""
def has_ext_modules(self):
return True
this_directory = os.path.abspath(os.path.dirname(__file__))
with open(os.path.join(this_directory, 'README.md')) as f:
LONG_DESCRIPTION = f.read()
CheckDeps()
setup(
name='gradient_decode_dicom',
version='0.0.5',
description=(
'Gradient Decode DICOM is a dicom image and tag reader op for TensorFlow'),
long_description=LONG_DESCRIPTION,
long_description_content_type='text/markdown',
url='https://github.com/gradienthealth/gradient_decode_dicom',
author='Marcelo Lerendegui',
author_email='marcelo@gradienthealth.io',
# Contained modules and scripts.
packages=find_packages(),
install_requires=[
'tensorflow >= 1.12.0',
],
# Add in any packaged data.
include_package_data=True,
zip_safe=False,
distclass=BinaryDistribution,
# PyPI package information.
classifiers=[
'Development Status :: 4 - Beta',
'Intended Audience :: Developers',
'Intended Audience :: Education',
'Intended Audience :: Science/Research',
'License :: OSI Approved :: Apache Software License',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Topic :: Scientific/Engineering :: Mathematics',
'Topic :: Software Development :: Libraries :: Python Modules',
'Topic :: Software Development :: Libraries',
],
license='Apache 2.0',
keywords='tensorflow dicom custom op machine learning',
cmdclass={'build_ext': BuildExtWithoutPlatformSuffix},
ext_modules=[tf_decode_dicom_ext],
)