forked from Liang-Team/Sequenzo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
107 lines (92 loc) · 3.56 KB
/
setup.py
File metadata and controls
107 lines (92 loc) · 3.56 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
"""
@Author : Yuqi Liang 梁彧祺
@File : setup.py
@Time : 27/02/2025 12:13
@Desc : Sequenzo Package Setup Configuration
This file is maintained for backward compatibility and to handle C++ & Cython extension compilation.
Most configuration is now in pyproject.toml.
Suggested command lines for developers:
# 编译所有 Cython + C++
python setup.py build_ext --inplace
# 开发者模式安装
pip install -e .
"""
from pathlib import Path
from setuptools import setup, Extension
from pybind11.setup_helpers import Pybind11Extension, build_ext
from Cython.Build import cythonize
import pybind11
import numpy
import os
import sys
from glob import glob
def get_extra_compile_args():
if sys.platform == 'win32':
return ['/std:c++14', '/EHsc', '/bigobj', '/O2', '/Gy']
elif sys.platform == 'darwin':
os.environ['MACOSX_DEPLOYMENT_TARGET'] = '10.9'
return ['-std=c++11', '-Wall', '-Wextra']
else:
return ['-std=c++11', '-Wall', '-Wextra']
def get_cython_compile_args():
extra_compile_args = []
if sys.platform == "win32":
extra_compile_args.append("/O2")
return extra_compile_args
def configure_cpp_extension():
try:
ext_module = Pybind11Extension(
'sequenzo.dissimilarity_measures.c_code',
sources=glob('sequenzo/dissimilarity_measures/src/*.cpp'),
include_dirs=[
pybind11.get_include(),
pybind11.get_include(user=True),
'sequenzo/dissimilarity_measures/src/',
],
extra_compile_args=get_extra_compile_args(),
language='c++',
)
print("C++ extension configured successfully")
return [ext_module]
except Exception as e:
print(f"Warning: Unable to configure C++ extension: {e}")
print("The package will be installed with a Python fallback implementation.")
return []
def configure_cython_extensions():
"""
Currently, there are two places that use cython:
clustering/utils and dissimilarity_measures/utils.
To avoid calling many cython files manually, I set up this function here.
"""
# Search all the pyx files.
try:
pyx_paths = [
Path("sequenzo/clustering/utils/point_biserial.pyx").as_posix(),
Path("sequenzo/dissimilarity_measures/utils/get_sm_trate_substitution_cost_matrix.pyx").as_posix(),
Path("sequenzo/dissimilarity_measures/utils/seqconc.pyx").as_posix(),
Path("sequenzo/dissimilarity_measures/utils/seqdss.pyx").as_posix(),
Path("sequenzo/dissimilarity_measures/utils/seqdur.pyx").as_posix(),
Path("sequenzo/dissimilarity_measures/utils/seqlength.pyx").as_posix(),
]
extensions = [
Extension(
name=path.replace("/", ".").replace(".pyx", ""),
sources=[path],
include_dirs=[numpy.get_include()],
extra_compile_args=get_cython_compile_args(),
)
for path in pyx_paths
]
print(f"Found {len(extensions)} Cython modules.")
return cythonize(extensions, compiler_directives={"language_level": "3"})
except Exception as e:
print(f"Warning: Unable to configure Cython extensions: {e}")
return []
# 防止路径缺失导致安装报错
os.makedirs("sequenzo/dissimilarity_measures/src", exist_ok=True)
os.makedirs("sequenzo/clustering/utils", exist_ok=True)
# 正式调用
setup(
ext_modules=configure_cpp_extension() + configure_cython_extensions(),
cmdclass={"build_ext": build_ext},
)