@@ -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+
6589def 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