Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion engine
Submodule engine updated 1 files
+15 −2 app_logging.py
19 changes: 18 additions & 1 deletion runtime_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,21 @@
import sys


def setup_log_path(root: Path) -> Path:
"""Return the log path shared by setup and launcher diagnostics."""
configured = os.environ.get("DRUNKENBOT_RUNTIME_SETUP_LOG")
if configured:
return Path(configured)
system = platform.system()
if system == "Windows":
base = Path(os.environ.get("LOCALAPPDATA", Path.home() / "AppData" / "Local"))
elif system == "Darwin":
base = Path.home() / "Library" / "Logs"
else:
base = Path(os.environ.get("XDG_STATE_HOME", Path.home() / ".local" / "state"))
return base / "DrunkenBot-IDE" / "runtime_setup.log"


def private_python(root: Path) -> Path:
if platform.system() == "Windows":
return root / "runtime" / "Scripts" / "python.exe"
Expand All @@ -28,6 +43,9 @@ def launch(root: Path) -> int:
raise RuntimeError(f"Runtime setup is missing: {setup_script}")
environment = os.environ.copy()
environment["DRUNKENBOT_APP_ROOT"] = str(root)
log_path = setup_log_path(root)
log_path.parent.mkdir(parents=True, exist_ok=True)
environment["DRUNKENBOT_RUNTIME_SETUP_LOG"] = str(log_path)
setup_kwargs: dict[str, object] = {
"cwd": root,
"env": environment,
Expand All @@ -40,7 +58,6 @@ def launch(root: Path) -> int:
**setup_kwargs,
)
if setup_result.returncode != 0:
log_path = root / "runtime_setup.log"
verification = subprocess.run(
[str(interpreter), "-c", "import torch; print(torch.__version__)"],
cwd=root,
Expand Down
29 changes: 28 additions & 1 deletion runtime_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,30 @@ def choose_runtime(system: str | None = None, driver_major: int | None = None) -
_SETUP_LOG = None


def _log_path(root: Path) -> Path:
"""Choose a writable setup-log location on installed systems."""
system = platform.system()
if system == "Windows":
platform_log = Path(os.environ.get("LOCALAPPDATA", Path.home() / "AppData" / "Local"))
elif system == "Darwin":
platform_log = Path.home() / "Library" / "Logs"
else:
platform_log = Path(os.environ.get("XDG_STATE_HOME", Path.home() / ".local" / "state"))
candidates = [
platform_log / "DrunkenBot-IDE" / "runtime_setup.log",
root / "runtime_setup.log",
]
for candidate in candidates:
try:
candidate.parent.mkdir(parents=True, exist_ok=True)
with candidate.open("a", encoding="utf-8"):
pass
return candidate
except OSError:
continue
raise OSError("Could not create a writable runtime setup log.")


def install_runtime(python_executable: str, choice: RuntimeChoice) -> None:
environment = os.environ.copy()
environment["PATH"] = os.pathsep.join(
Expand Down Expand Up @@ -124,7 +148,10 @@ def main() -> int:
parser.add_argument("--dry-run", action="store_true")
parser.add_argument("--ensure", action="store_true")
args = parser.parse_args()
log_path = Path(__file__).resolve().parent / "runtime_setup.log"
configured_log = os.environ.get("DRUNKENBOT_RUNTIME_SETUP_LOG")
log_path = Path(configured_log) if configured_log else _log_path(Path(__file__).resolve().parent)
log_path.parent.mkdir(parents=True, exist_ok=True)
os.environ["DRUNKENBOT_RUNTIME_SETUP_LOG"] = str(log_path)
with log_path.open("w", encoding="utf-8") as log:
global _SETUP_LOG
_SETUP_LOG = log
Expand Down
Loading