File size: 1,296 Bytes
d5b7ee9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""HMR dev runner โ€” watches for .py changes and auto-restarts the trading CLI."""

from __future__ import annotations

import os
import sys

# CRITICAL: Set multiprocessing start method BEFORE any other imports
if sys.platform.startswith('linux'):
    try:
        import multiprocessing
        multiprocessing.set_start_method('spawn', force=True)
    except (RuntimeError, AttributeError):
        pass

import subprocess
from pathlib import Path

from watchfiles import watch


def main() -> None:
    project_root = Path(__file__).parent.resolve()
    target_dir = project_root / "trading_cli"

    print(f"๐Ÿ”„ Watching {target_dir} for changes (Ctrl+C to stop)\n")

    for changes in watch(target_dir, watch_filter=None):
        for change_type, path in changes:
            if not path.endswith((".py", ".pyc")):
                continue
            action = "Added" if change_type.name == "added" else \
                     "Modified" if change_type.name == "modified" else "Deleted"
            rel = Path(path).relative_to(project_root)
            print(f"\n๐Ÿ“ {action}: {rel}")
            print("โŸณ  Restarting...\n")
            break  # restart on first matching change
        subprocess.run([sys.executable, "-m", "trading_cli"])


if __name__ == "__main__":
    main()