forked from Liang-Team/Sequenzo
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__init__.py
More file actions
87 lines (73 loc) · 3.11 KB
/
__init__.py
File metadata and controls
87 lines (73 loc) · 3.11 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
"""
@Author : Yuqi Liang 梁彧祺
@File : __init__.py
@Time : 11/02/2025 16:42
@Desc : Sequenzo Package Initialization
"""
# sequenzo/__init__.py (Top-level)
import importlib.util
import platform
import sys
from pathlib import Path
__version__ = "0.1.4"
# Construct the expected path to the extension module.
_lib_path = Path(__file__).parent / "sequenzo" / ("_rust_fast_cluster" + {
"Windows": ".pyd",
"Darwin": ".so", # Might need .cpython-39-darwin.so, see note below
"Linux": ".so"
}[platform.system()])
from sequenzo import datasets, visualization, clustering, dissimilarity_measures, define_sequence_data, big_data
def __getattr__(name):
try:
if name == "datasets":
from sequenzo import datasets
return datasets
elif name == "visualization":
from sequenzo import visualization
return visualization
elif name == "clustering":
from sequenzo import clustering
return clustering
elif name == "dissimilarity_measures":
from sequenzo import dissimilarity_measures
return dissimilarity_measures
elif name == "SequenceData":
from sequenzo.define_sequence_data import SequenceData
return SequenceData
elif name == "big_data":
from sequenzo.big_data import clara
return clara
elif name == "_rust_fast_cluster" and _extension_loaded:
return sys.modules["sequenzo._rust_fast_cluster"]
# Provide a helpful error message.
if name == "clustering" and not _extension_loaded:
raise ImportError(
"The Rust extension failed to load, so fast clustering is unavailable. "
"The 'clustering' module is not available without the extension. "
"Please ensure you have built the package correctly using `maturin develop` or `python -m build`."
)
elif not _extension_loaded:
raise ImportError(
f"The Rust extension failed to load. Please ensure you have "
"built the package correctly using `maturin develop` or `python -m build`."
)
except ImportError as e:
raise AttributeError(f"Could not import {name}: {e}")
raise AttributeError(f"module 'sequenzo' has no attribute '{name}'")
SequenceData = sequenzo.define_sequence_data.SequenceData
# But *don't* directly import clustering here. It's handled by __getattr__.
# These are the public APIs of the package, but use __getattr__ for lazy imports
__all__ = [
'datasets',
'visualization',
'clustering', # Included, but it is lazy-loaded via __getattr__
'dissimilarity_measures',
'SequenceData',
'big_data',
]
# NOTE: You *could* choose to make _rust_fast_cluster directly accessible
# via __all__ as well, *if* you want users to be able to directly interact
# with the Rust functions. If you do, add "_rust_fast_cluster" to __all__.
# If you *don't* add it, it will still be accessible via
# `sequenzo._rust_fast_cluster`, but it won't be considered part of the
# "public" API. This is a design choice.