-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsetup.py
168 lines (142 loc) · 5.09 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
from __future__ import annotations, print_function
import sys
if sys.version_info < (3,):
print("Python 2 has reached end-of-life and is not supported by setriq.")
sys.exit(-1)
if sys.platform == "win32" and sys.maxsize.bit_length() == 31:
print(
"32-bit Windows Python runtime is not supported. Please switch to 64-bit Python."
)
sys.exit(-1)
import logging
import pathlib
import platform
import re
import shutil
import subprocess
import traceback
from glob import glob
from typing import List
from pybind11.setup_helpers import ParallelCompile, Pybind11Extension
from setuptools import find_packages, setup
python_min_version = (3, 7, 2)
python_min_version_str = ".".join(map(str, python_min_version))
if sys.version_info < python_min_version:
logging.error(
"Minimum Python version required is {}. Current version is {}".format(
python_min_version_str, platform.python_version()
)
)
sys.exit(-1)
logging.basicConfig(
level=logging.DEBUG,
format="%(name)s - %(asctime)s.%(msecs)03d - %(levelname)s - %(module)s.%(funcName)s: %(message)s",
datefmt="%Y-%m-%d %H:%M:%S",
)
# find the sem-rel version
DIR = pathlib.Path(__file__).parent
SOURCE_DIR = "src"
PROJECT_NAME = "setriq"
EXTENSION_NAME = "_C"
ParallelCompile("NPY_NUM_BUILD_JOBS").install()
class BuildFlags:
_tools_formulae = {
"Darwin": ("brew", "libomp"),
}
_args = {
"Darwin": {"compiler": ["-Xpreprocessor", "-fopenmp"], "linker": ["-lomp"]}
}
_default_args = {"compiler": ["-fopenmp"], "linker": ["-fopenmp"]}
compiler: list
linker: list
def __init__(self):
self._system = platform.system()
tool, formula = self._tools_formulae.get(self._system, ("apt", "libomp-dev"))
args = self._args.get(self._system, self._default_args)
not_found = self._libomp_check(tool, formula)
if not_found is not None:
logging.warning(
f"{repr(not_found)} not found -- cannot compile parallelized code"
)
logging.info(
"for information on how to enable CPU parallelization, "
"please see https://github.com/BenTenmann/setriq#requirements"
)
for key in args:
args[key] = []
for key, val in args.items():
self.__setattr__(key, val)
@staticmethod
def _libomp_check(tool, formula) -> None:
if shutil.which(tool) is None:
return tool
formulae = subprocess.check_output([tool, "list"]).decode()
if formula not in formulae:
return formula
return None
def get_requirements() -> List[str]:
return (
(pathlib.Path(".") / "requirements.txt").read_text().splitlines(keepends=False)
)
def main():
long_description = (DIR / "README.md").read_text()
try:
changelog = (DIR / "CHANGELOG.md").read_text()
__version__, *_ = re.findall(r"\[([0-9.]+)]", changelog)
except (FileNotFoundError, ValueError) as ex:
__version__ = "0.1.0"
logging.error(ex)
logging.error(traceback.print_exc())
logging.warning(
f"Unable to get semantic release version. Setting version to {__version__}."
)
flags = BuildFlags()
extensions = [
Pybind11Extension(
f"{PROJECT_NAME}.{EXTENSION_NAME}",
sources=sorted(
glob(
f"{SOURCE_DIR}/{PROJECT_NAME}/{EXTENSION_NAME}/**/*.cpp",
recursive=True,
)
),
cxx_std=14,
define_macros=[
("VERSION_INFO", __version__),
("EXTENSION_NAME", EXTENSION_NAME),
],
include_dirs=["include/setriq"],
extra_compile_args=flags.compiler,
extra_link_args=flags.linker,
),
]
setup(
name=PROJECT_NAME,
version=__version__,
description="Python package written in C++ for pairwise distance computation for sequences.",
long_description=long_description,
long_description_content_type="text/markdown",
author="benjamin-tenmann",
author_email="[email protected]",
url="https://github.com/BenTenmann/setriq",
ext_modules=extensions,
license="MIT",
python_requires=">=3.7,<3.10",
install_requires=get_requirements(),
package_dir={f"{PROJECT_NAME}": f"{SOURCE_DIR}/{PROJECT_NAME}"},
packages=find_packages(where=f"{SOURCE_DIR}", exclude=["tests", "scripts"]),
package_data={f"{PROJECT_NAME}": ["data/*.json"]},
include_package_data=True,
classifiers=[
"Development Status :: 3 - Alpha",
"Intended Audience :: Developers",
"Topic :: Software Development :: Build Tools",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
],
)
if __name__ == "__main__":
main()