Repository navigation
Expand file tree
/
Copy pathrun_debug.py
More file actions
65 lines (51 loc) · 1.66 KB
/
Copy pathrun_debug.py
File metadata and controls
65 lines (51 loc) · 1.66 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
# run_debug.py
"""
Convenience runner for the lipid_analysis pipeline from an IDE (e.g., Spyder).
Place this file NEXT TO the 'lipid_analysis/' package folder, then run it.
It safely amends sys.path, temporarily patches sys.argv to simulate CLI flags,
and invokes lipid_analysis.cli.main().
"""
from __future__ import annotations
import contextlib
import sys
from pathlib import Path
from typing import Iterator, List
@contextlib.contextmanager
def _patched_argv(new_argv: List[str]) -> Iterator[None]:
"""Temporarily replace sys.argv for argparse-based entrypoints."""
old = sys.argv[:]
sys.argv = list(new_argv)
try:
yield
finally:
sys.argv = old
def _project_root() -> Path:
"""
Best-effort project root resolution:
- Prefer the directory of this script if __file__ exists.
- Fall back to the current working directory (IDE-safe).
"""
try:
return Path(__file__).resolve().parent
except NameError:
# __file__ may be missing in some IDE run modes
return Path.cwd()
def main() -> None:
root = _project_root()
if str(root) not in sys.path:
sys.path.insert(0, str(root))
# Import after sys.path is set so the adjacent package is resolvable.
from lipid_analysis.cli import main as cli_main
# ---- Simulate CLI args (edit these paths/flags as needed) ----
args = [
"run_debug.py",
"--config",
r"D:\OneDrive - Stanford\Research Documents\Python Scripts\config_files\config_AD4a.py",
"--root",
r"D:\OneDrive - Stanford",
"--verbose",
]
with _patched_argv(args):
cli_main()
if __name__ == "__main__":
main()