Coverage for scripts/run_lean_cli_windows.py: 100%
14 statements
« prev ^ index » next coverage.py v7.17.3, created at 2026-11-22 12:55 +0000
« prev ^ index » next coverage.py v7.17.3, created at 2026-11-22 12:55 +0000
1"""Run QuantConnect's Lean CLI with Docker-readable Windows temp folders.
3Docker Desktop can read ordinary files created by PowerShell, but on some
4Windows setups it cannot read files in directories created by Python's
5``tempfile.mkdtemp``. Lean CLI uses those directories for config files,
6startup scripts, and dependency manifests. Granting inherited read/execute
7access on each generated directory fixes all of those mounts without
8changing the user's global TEMP permissions.
9"""
11from __future__ import annotations
13import os
14import subprocess
15import tempfile
17_real_mkdtemp = tempfile.mkdtemp
20def _docker_readable_mkdtemp(*args, **kwargs) -> str:
21 path = str(_real_mkdtemp(*args, **kwargs))
22 if os.name == "nt":
23 # S-1-5-11 is Authenticated Users. RX is sufficient for Docker's
24 # read-only bind mounts; the current user retains the directory's
25 # normal owner permissions for Lean's own writes.
26 subprocess.run(
27 [
28 "icacls",
29 path,
30 "/inheritance:e",
31 "/grant",
32 "*S-1-5-11:(OI)(CI)RX",
33 ],
34 stdout=subprocess.DEVNULL,
35 stderr=subprocess.DEVNULL,
36 check=False,
37 )
38 return path
41tempfile.mkdtemp = _docker_readable_mkdtemp
43from lean.main import main # noqa: E402 (patch must happen before import)
45if __name__ == "__main__":
46 main()