forked from yvchao/tphenotype
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
41 lines (33 loc) · 1.34 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
import os
import re
from Cython.Build import cythonize
from setuptools import Extension, setup
if __name__ == "__main__":
try:
PKG = "tphenotype"
# Configure Cython lexsort extension.
cython_config = {
"compiler_directives": {"language_level": "3"},
}
sources = [f"src/{PKG}/utils/lexsort.pyx"]
extension = Extension("lexsort", sources=sources, extra_compile_args=["-std=c++11"])
extensions = [extension]
# Configure version.
def find_version() -> str:
def read(fname: str) -> str:
return open(os.path.realpath(os.path.join(os.path.dirname(__file__), fname)), encoding="utf8").read()
version_file = read(f"src/{PKG}/version.py").split("\n")[0]
version_re = r"__version__ = \"(?P<version>.+)\""
version_raw = re.match(version_re, version_file)
if version_raw is None:
raise RuntimeError(f"__version__ value not found, check src/{PKG}/version.py")
version = version_raw.group("version")
return version
setup(
version=find_version(),
ext_package=f"{PKG}.utils",
ext_modules=cythonize(extensions, **cython_config),
)
except: # noqa
print("\n\nAn error occurred while building the project")
raise