|
a |
|
b/setup.py |
|
|
1 |
#!/usr/bin/env python |
|
|
2 |
# Copyright 2019 Division of Medical Image Computing, German Cancer Research Center (DKFZ). |
|
|
3 |
# |
|
|
4 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
5 |
# you may not use this file except in compliance with the License. |
|
|
6 |
# You may obtain a copy of the License at |
|
|
7 |
# |
|
|
8 |
# http://www.apache.org/licenses/LICENSE-2.0 |
|
|
9 |
# |
|
|
10 |
# Unless required by applicable law or agreed to in writing, software |
|
|
11 |
# distributed under the License is distributed on an "AS IS" BASIS, |
|
|
12 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
|
13 |
# See the License for the specific language governing permissions and |
|
|
14 |
# limitations under the License. |
|
|
15 |
# ============================================================================== |
|
|
16 |
|
|
|
17 |
from setuptools import find_packages, setup |
|
|
18 |
import os, sys, subprocess |
|
|
19 |
|
|
|
20 |
|
|
|
21 |
def parse_requirements(filename, exclude=[]): |
|
|
22 |
lineiter = (line.strip() for line in open(filename)) |
|
|
23 |
return [line for line in lineiter if line and not line.startswith("#") and not line.split("==")[0] in exclude] |
|
|
24 |
|
|
|
25 |
def pip_install(item): |
|
|
26 |
subprocess.check_call([sys.executable, "-m", "pip", "install", item]) |
|
|
27 |
|
|
|
28 |
def install_custom_ext(setup_path): |
|
|
29 |
try: |
|
|
30 |
pip_install(setup_path) |
|
|
31 |
except Exception as e: |
|
|
32 |
print("Could not install custom extension {} from source due to Error:\n{}\n".format(path, e) + |
|
|
33 |
"Trying to install from pre-compiled wheel.") |
|
|
34 |
dist_path = setup_path+"/dist" |
|
|
35 |
wheel_file = [fn for fn in os.listdir(dist_path) if fn.endswith(".whl")][0] |
|
|
36 |
pip_install(os.path.join(dist_path, wheel_file)) |
|
|
37 |
|
|
|
38 |
def clean(): |
|
|
39 |
"""Custom clean command to tidy up the project root.""" |
|
|
40 |
os.system('rm -vrf ./build ./dist ./*.pyc ./*.tgz ./*.egg-info') |
|
|
41 |
|
|
|
42 |
|
|
|
43 |
|
|
|
44 |
|
|
|
45 |
if __name__ == "__main__": |
|
|
46 |
|
|
|
47 |
req_file = "requirements.txt" |
|
|
48 |
custom_exts = ["nms-extension", "RoIAlign-extension-2D", "RoIAlign-extension-3D"] |
|
|
49 |
install_reqs = parse_requirements(req_file, exclude=custom_exts) |
|
|
50 |
|
|
|
51 |
setup(name='medicaldetectiontoolkit', |
|
|
52 |
version='0.1.0', |
|
|
53 |
url="https://github.com/MIC-DKFZ/medicaldetectiontoolkit", |
|
|
54 |
author='P. Jaeger, G. Ramien, MIC at DKFZ Heidelberg', |
|
|
55 |
license="Apache 2.0", |
|
|
56 |
description="Medical Object-Detection Toolkit.", |
|
|
57 |
classifiers=[ |
|
|
58 |
"Development Status :: 4 - Beta", |
|
|
59 |
"Intended Audience :: Developers", |
|
|
60 |
"Programming Language :: Python :: 3.7" |
|
|
61 |
], |
|
|
62 |
packages=find_packages(exclude=['test', 'test.*']), |
|
|
63 |
install_requires=install_reqs, |
|
|
64 |
python_requires=">=3.7" |
|
|
65 |
) |
|
|
66 |
|
|
|
67 |
custom_exts = ["custom_extensions/nms", "custom_extensions/roi_align/2D", "custom_extensions/roi_align/3D"] |
|
|
68 |
for path in custom_exts: |
|
|
69 |
try: |
|
|
70 |
install_custom_ext(path) |
|
|
71 |
except Exception as e: |
|
|
72 |
print("FAILED to install custom extension {} due to Error:\n{}".format(path, e)) |
|
|
73 |
|
|
|
74 |
clean() |