Return the cache directory for CLI binaries. Args: version: CLI version string. If None, returns the root cache dir.
(version: str | None = None)
| 51 | |
| 52 | |
| 53 | def get_cache_dir(version: str | None = None) -> Path: |
| 54 | """Return the cache directory for CLI binaries. |
| 55 | |
| 56 | Args: |
| 57 | version: CLI version string. If None, returns the root cache dir. |
| 58 | """ |
| 59 | # COPILOT_CLI_EXTRACT_DIR overrides the entire version-specific directory |
| 60 | # (binary lives directly at $dir/<binary>, no version subdir). Matches Rust SDK. |
| 61 | extract_override = os.environ.get("COPILOT_CLI_EXTRACT_DIR") |
| 62 | if extract_override: |
| 63 | return Path(extract_override) |
| 64 | |
| 65 | if sys.platform == "darwin": |
| 66 | root = Path.home() / "Library" / "Caches" / _CACHE_DIR_NAME |
| 67 | elif sys.platform == "win32": |
| 68 | local_app_data = os.environ.get("LOCALAPPDATA") |
| 69 | if local_app_data: |
| 70 | root = Path(local_app_data) / _CACHE_DIR_NAME |
| 71 | else: |
| 72 | root = Path.home() / "AppData" / "Local" / _CACHE_DIR_NAME |
| 73 | else: |
| 74 | xdg = os.environ.get("XDG_CACHE_HOME") |
| 75 | if xdg: |
| 76 | root = Path(xdg) / _CACHE_DIR_NAME |
| 77 | else: |
| 78 | root = Path.home() / ".cache" / _CACHE_DIR_NAME |
| 79 | |
| 80 | if version: |
| 81 | return root / "cli" / _sanitize_version(version) |
| 82 | return root / "cli" |
| 83 | |
| 84 | |
| 85 | def get_cached_cli_path(version: str | None = None) -> str | None: |
no test coverage detected
searching dependent graphs…