将根目录引擎迁入 chanlun/ 并保留兼容 shim;拆分 TF_DF 与 web 服务; 前端模块化;strategies 改用 chanlun 导入;补充 ESS 文档与 golden 回归。 Co-authored-by: Cursor <cursoragent@cursor.com>
65 lines
2.7 KiB
Python
65 lines
2.7 KiB
Python
#!/usr/bin/env python3
|
|
"""将 strategies / web / tests 的根 shim 导入改为 chanlun 包导入。"""
|
|
from __future__ import annotations
|
|
|
|
import re
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
|
|
REPLACEMENTS = [
|
|
(r"from ChanLun import ", "from chanlun import "),
|
|
(r"from TF_DF import ", "from chanlun import "), # TF_DF also exported from chanlun
|
|
(r"from ChanEnum import ", "from chanlun.core.ChanEnum import "),
|
|
(r"from ChanLun_Classifier import ", "from chanlun.analysis.ChanLun_Classifier import "),
|
|
(r"from ChanPY import ", "from chanlun.analysis.ChanPY import "),
|
|
(r"from ChanKLU import ", "from chanlun.core.ChanKLU import "),
|
|
(r"from ChanKLC import ", "from chanlun.core.ChanKLC import "),
|
|
(r"from ChanBI import ", "from chanlun.core.ChanBI import "),
|
|
(r"from ChanCTime import ", "from chanlun.core.ChanCTime import "),
|
|
(r"from ChanMACD import ", "from chanlun.indicators.ChanMACD import "),
|
|
(r"from ChanZone import ", "from chanlun.analysis.ChanZone import "),
|
|
(r"from ChanBSP import ", "from chanlun.core.ChanBSP import "),
|
|
(r"from ChanSEG import ", "from chanlun.core.ChanSEG import "),
|
|
(r"from ChanZS import ", "from chanlun.core.ChanZS import "),
|
|
(r"from ChanBIZS import ", "from chanlun.core.ChanBIZS import "),
|
|
(r"from ChanSBI import ", "from chanlun.core.ChanSBI import "),
|
|
(r"from ChanPivotClassifier import ", "from chanlun.analysis.ChanPivotClassifier import "),
|
|
(r"from ChanPivotMonitor import ", "from chanlun.analysis.ChanPivotMonitor import "),
|
|
(r"from fx_strength_config import ", "from chanlun.analysis.fx_strength_config import "),
|
|
]
|
|
|
|
|
|
def rewrite_file(path: Path) -> bool:
|
|
text = path.read_text(encoding="utf-8")
|
|
orig = text
|
|
for pat, repl in REPLACEMENTS:
|
|
text = re.sub(pat, repl, text)
|
|
# Fix: from chanlun import TF_DF only cases that were `from TF_DF import TF_DF`
|
|
# and `from ChanLun import ChanLun, TF_DF` already becomes from chanlun import ChanLun, TF_DF — good
|
|
# Special: from chanlun import TF_DF when file only imported TF_DF — need TF_DF in chanlun.__init__
|
|
if text == orig:
|
|
return False
|
|
path.write_text(text, encoding="utf-8")
|
|
return True
|
|
|
|
|
|
def main():
|
|
changed = []
|
|
targets = []
|
|
targets += list((ROOT / "strategies").glob("*.py"))
|
|
targets += list((ROOT / "web").rglob("*.py"))
|
|
targets += list((ROOT / "tests").rglob("*.py"))
|
|
for p in targets:
|
|
if "charting_library" in str(p) or "__pycache__" in str(p):
|
|
continue
|
|
if rewrite_file(p):
|
|
changed.append(str(p.relative_to(ROOT)))
|
|
print(f"updated {len(changed)} files")
|
|
for c in changed:
|
|
print(" -", c)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|