Skip to content

Commit 3ec2312

Browse files
Merge pull request #44 from drunkenbot-ai/ncj-dneg-update-trial-ui-limits
Use platform-specific runtime log paths
2 parents 8adfb07 + 6cf603a commit 3ec2312

3 files changed

Lines changed: 47 additions & 3 deletions

File tree

engine

runtime_launcher.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,21 @@
1010
import sys
1111

1212

13+
def setup_log_path(root: Path) -> Path:
14+
"""Return the log path shared by setup and launcher diagnostics."""
15+
configured = os.environ.get("DRUNKENBOT_RUNTIME_SETUP_LOG")
16+
if configured:
17+
return Path(configured)
18+
system = platform.system()
19+
if system == "Windows":
20+
base = Path(os.environ.get("LOCALAPPDATA", Path.home() / "AppData" / "Local"))
21+
elif system == "Darwin":
22+
base = Path.home() / "Library" / "Logs"
23+
else:
24+
base = Path(os.environ.get("XDG_STATE_HOME", Path.home() / ".local" / "state"))
25+
return base / "DrunkenBot-IDE" / "runtime_setup.log"
26+
27+
1328
def private_python(root: Path) -> Path:
1429
if platform.system() == "Windows":
1530
return root / "runtime" / "Scripts" / "python.exe"
@@ -28,6 +43,9 @@ def launch(root: Path) -> int:
2843
raise RuntimeError(f"Runtime setup is missing: {setup_script}")
2944
environment = os.environ.copy()
3045
environment["DRUNKENBOT_APP_ROOT"] = str(root)
46+
log_path = setup_log_path(root)
47+
log_path.parent.mkdir(parents=True, exist_ok=True)
48+
environment["DRUNKENBOT_RUNTIME_SETUP_LOG"] = str(log_path)
3149
setup_kwargs: dict[str, object] = {
3250
"cwd": root,
3351
"env": environment,
@@ -40,7 +58,6 @@ def launch(root: Path) -> int:
4058
**setup_kwargs,
4159
)
4260
if setup_result.returncode != 0:
43-
log_path = root / "runtime_setup.log"
4461
verification = subprocess.run(
4562
[str(interpreter), "-c", "import torch; print(torch.__version__)"],
4663
cwd=root,

runtime_setup.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,30 @@ def choose_runtime(system: str | None = None, driver_major: int | None = None) -
6262
_SETUP_LOG = None
6363

6464

65+
def _log_path(root: Path) -> Path:
66+
"""Choose a writable setup-log location on installed systems."""
67+
system = platform.system()
68+
if system == "Windows":
69+
platform_log = Path(os.environ.get("LOCALAPPDATA", Path.home() / "AppData" / "Local"))
70+
elif system == "Darwin":
71+
platform_log = Path.home() / "Library" / "Logs"
72+
else:
73+
platform_log = Path(os.environ.get("XDG_STATE_HOME", Path.home() / ".local" / "state"))
74+
candidates = [
75+
platform_log / "DrunkenBot-IDE" / "runtime_setup.log",
76+
root / "runtime_setup.log",
77+
]
78+
for candidate in candidates:
79+
try:
80+
candidate.parent.mkdir(parents=True, exist_ok=True)
81+
with candidate.open("a", encoding="utf-8"):
82+
pass
83+
return candidate
84+
except OSError:
85+
continue
86+
raise OSError("Could not create a writable runtime setup log.")
87+
88+
6589
def install_runtime(python_executable: str, choice: RuntimeChoice) -> None:
6690
environment = os.environ.copy()
6791
environment["PATH"] = os.pathsep.join(
@@ -124,7 +148,10 @@ def main() -> int:
124148
parser.add_argument("--dry-run", action="store_true")
125149
parser.add_argument("--ensure", action="store_true")
126150
args = parser.parse_args()
127-
log_path = Path(__file__).resolve().parent / "runtime_setup.log"
151+
configured_log = os.environ.get("DRUNKENBOT_RUNTIME_SETUP_LOG")
152+
log_path = Path(configured_log) if configured_log else _log_path(Path(__file__).resolve().parent)
153+
log_path.parent.mkdir(parents=True, exist_ok=True)
154+
os.environ["DRUNKENBOT_RUNTIME_SETUP_LOG"] = str(log_path)
128155
with log_path.open("w", encoding="utf-8") as log:
129156
global _SETUP_LOG
130157
_SETUP_LOG = log

0 commit comments

Comments
 (0)