diff --git a/lib/hub/hub_entry_plan_lib.py b/lib/hub/hub_entry_plan_lib.py index feb5147..90c70cb 100644 --- a/lib/hub/hub_entry_plan_lib.py +++ b/lib/hub/hub_entry_plan_lib.py @@ -36,9 +36,9 @@ def default_db_path() -> Path: raw = (os.getenv("HUB_ENTRY_PLAN_DB_PATH") or "").strip() if raw: return Path(raw) - hub_dir = Path(__file__).resolve().parent / "manual_trading_hub" / "data" - hub_dir.mkdir(parents=True, exist_ok=True) - return hub_dir / "hub_entry_plans.db" + from lib.paths import hub_data_dir + + return hub_data_dir() / "hub_entry_plans.db" def _now_ms() -> int: diff --git a/lib/hub/hub_fund_history_lib.py b/lib/hub/hub_fund_history_lib.py index 0b1023a..78cb95f 100644 --- a/lib/hub/hub_fund_history_lib.py +++ b/lib/hub/hub_fund_history_lib.py @@ -9,7 +9,9 @@ from typing import Any, Optional from lib.hub.hub_trades_lib import current_trading_day -HUB_DIR = Path(__file__).resolve().parent / "manual_trading_hub" +from lib.paths import manual_trading_hub_dir + +HUB_DIR = manual_trading_hub_dir() FUND_HISTORY_PATH = HUB_DIR / "hub_fund_history.json" LEGACY_FUND_HISTORY_PATH = HUB_DIR / "hub_ai_fund_history.json" diff --git a/lib/hub/hub_kline_store.py b/lib/hub/hub_kline_store.py index 4dd736e..52b1a80 100644 --- a/lib/hub/hub_kline_store.py +++ b/lib/hub/hub_kline_store.py @@ -44,9 +44,9 @@ def default_db_path() -> Path: raw = (os.getenv("HUB_KLINE_DB_PATH") or "").strip() if raw: return Path(raw) - hub_dir = Path(__file__).resolve().parent / "manual_trading_hub" / "data" - hub_dir.mkdir(parents=True, exist_ok=True) - return hub_dir / "hub_kline.db" + from lib.paths import hub_data_dir + + return hub_data_dir() / "hub_kline.db" def _connect(db_path: Path | None = None) -> sqlite3.Connection: diff --git a/lib/hub/hub_macro_calendar_lib.py b/lib/hub/hub_macro_calendar_lib.py index 10ed915..fcd40d3 100644 --- a/lib/hub/hub_macro_calendar_lib.py +++ b/lib/hub/hub_macro_calendar_lib.py @@ -32,9 +32,9 @@ def default_db_path() -> Path: raw = (os.getenv("HUB_MACRO_CALENDAR_DB_PATH") or "").strip() if raw: return Path(raw) - hub_dir = Path(__file__).resolve().parent / "manual_trading_hub" / "data" - hub_dir.mkdir(parents=True, exist_ok=True) - return hub_dir / "hub_macro_calendar.db" + from lib.paths import hub_data_dir + + return hub_data_dir() / "hub_macro_calendar.db" def _connect(db_path: Path | None = None) -> sqlite3.Connection: diff --git a/lib/hub/hub_symbol_archive_lib.py b/lib/hub/hub_symbol_archive_lib.py index d911550..c7573e1 100644 --- a/lib/hub/hub_symbol_archive_lib.py +++ b/lib/hub/hub_symbol_archive_lib.py @@ -49,9 +49,9 @@ def default_db_path() -> Path: raw = (os.getenv("HUB_ARCHIVE_DB_PATH") or "").strip() if raw: return Path(raw) - hub_dir = Path(__file__).resolve().parent / "manual_trading_hub" / "data" - hub_dir.mkdir(parents=True, exist_ok=True) - return hub_dir / "hub_symbol_archive.db" + from lib.paths import hub_data_dir + + return hub_data_dir() / "hub_symbol_archive.db" def _connect(db_path: Path | None = None) -> sqlite3.Connection: diff --git a/lib/hub/hub_volume_rank_lib.py b/lib/hub/hub_volume_rank_lib.py index e4ba950..5ee3667 100644 --- a/lib/hub/hub_volume_rank_lib.py +++ b/lib/hub/hub_volume_rank_lib.py @@ -59,9 +59,9 @@ def default_cache_path() -> Path: raw = (os.getenv("HUB_VOLUME_RANK_CACHE_PATH") or "").strip() if raw: return Path(raw) - hub_dir = Path(__file__).resolve().parent / "manual_trading_hub" / "data" - hub_dir.mkdir(parents=True, exist_ok=True) - return hub_dir / "hub_volume_rank.json" + from lib.paths import hub_data_dir + + return hub_data_dir() / "hub_volume_rank.json" def _safe_float(v: Any) -> float | None: diff --git a/lib/paths.py b/lib/paths.py index 4493d57..b9f8ad9 100644 --- a/lib/paths.py +++ b/lib/paths.py @@ -20,3 +20,14 @@ def embed_templates_dir(repo_root: str | Path | None = None) -> str: def common_static_dir(repo_root: str | Path | None = None) -> str: root = Path(repo_root) if repo_root is not None else REPO_ROOT return str(root / "lib" / "common" / "static") + + +def manual_trading_hub_dir(repo_root: str | Path | None = None) -> Path: + root = Path(repo_root) if repo_root is not None else REPO_ROOT + return root / "manual_trading_hub" + + +def hub_data_dir(repo_root: str | Path | None = None) -> Path: + path = manual_trading_hub_dir(repo_root) / "data" + path.mkdir(parents=True, exist_ok=True) + return path