-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathsetup.py
131 lines (106 loc) · 4.02 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
# SPDX-FileCopyrightText: 2022 Division of Intelligent Medical Systems, DKFZ
# SPDX-License-Identifier: MIT
import os
import re
from pathlib import Path
from setuptools import find_namespace_packages, setup
from torch.utils import cpp_extension
def read_file(path: Path) -> str:
"""
Reads the content of a file into a string.
Args:
path: Path to the file to read.
Returns:
The content of the file.
"""
with path.open() as f:
content = f.read()
return content
def parse_requirements(requirements_file: Path) -> list[str]:
"""
Parses an requirements file into a list of dependencies.
Args:
requirements_file: Path to the requirements file.
Returns: List of dependencies with version information (e.g. ==1.12.1) but without extra specifications (e.g. +cu116).
"""
req = []
for line in read_file(requirements_file).splitlines():
match = re.search(r"^\w+[^+@]*", line)
if match is not None:
lib = match.group(0)
req.append(lib)
return req
def parse_readme(readme_file: Path) -> str:
"""
Reads and adjusts a readme file so that it can be used for PyPi.
Args:
readme_file: Path to the readme file.
Returns: Readme as string with adjusted links.
"""
readme = read_file(readme_file)
# Make local anchors and links to files absolute since they don't work on PyPi
readme = re.sub(r"\(\./([^)]+)\)", r"(https://github.com/IMSY-DKFZ/htc/tree/main/\1)", readme)
readme = re.sub(r"\(#([^)]+)\)", r"(https://github.com/IMSY-DKFZ/htc/#\1)", readme)
return readme
repo_root = Path(__file__).parent
source_files = sorted(repo_root.rglob("htc/cpp/*.cpp"))
source_files = [str(f.relative_to(repo_root)) for f in source_files]
if os.name == "nt":
compiler_flags = ["/O2", "/std:c++20"]
else:
compiler_flags = ["-O3", "-std=c++2a"]
setup(
name="imsy-htc",
version="0.0.18",
# We are using find_namespace_packages() instead of find_packages() to resolve this deprecation warning: https://github.com/pypa/setuptools/issues/3340
packages=find_namespace_packages(include=["htc*"]),
author="Division of Intelligent Medical Systems, DKFZ",
license="MIT",
url="https://github.com/imsy-dkfz/htc",
description="Framework for automatic classification and segmentation of hyperspectral images.",
keywords=[
"surgical data science",
"open surgery",
"hyperspectral imaging",
"organ segmentation",
"semantic scene segmentation",
"deep learning",
],
classifiers=[
"Intended Audience :: Developers",
"Intended Audience :: Science/Research",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"License :: OSI Approved :: MIT License",
"Operating System :: POSIX :: Linux",
"Operating System :: Microsoft :: Windows",
"Operating System :: MacOS",
"Topic :: Scientific/Engineering",
"Topic :: Scientific/Engineering :: Artificial Intelligence",
"Topic :: Scientific/Engineering :: Image Processing",
"Topic :: Software Development",
"Topic :: Software Development :: Libraries",
"Topic :: Software Development :: Libraries :: Python Modules",
],
long_description=parse_readme(repo_root / "README.md"),
long_description_content_type="text/markdown",
python_requires=">=3.10",
install_requires=parse_requirements(repo_root / "requirements.txt"),
extras_require={
"extra": parse_requirements(repo_root / "requirements-extra.txt"),
},
include_package_data=True,
entry_points={
"console_scripts": ["htc=htc.cli:main"],
},
ext_modules=[
cpp_extension.CppExtension(
name="htc._cpp",
sources=source_files,
extra_compile_args=compiler_flags,
)
],
cmdclass={"build_ext": cpp_extension.BuildExtension},
)