From f473fc34b0de4f6e933c85cb24626d85b247d278 Mon Sep 17 00:00:00 2001 From: MaXFeeD Date: Sun, 18 May 2025 10:40:26 +0300 Subject: [PATCH] Implemented get_config/temporary_directory + typo fix --- src/icmtoolchain/__init__.py | 4 +-- src/icmtoolchain/output_directory.py | 41 ++++++++++++++++++++-------- 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/src/icmtoolchain/__init__.py b/src/icmtoolchain/__init__.py index 459256b..b213246 100644 --- a/src/icmtoolchain/__init__.py +++ b/src/icmtoolchain/__init__.py @@ -14,7 +14,7 @@ def find_configuration(path: str, filename: str): return config_path working_path.pop() -def request_make_config(toolchain_config): +def request_make_config(toolchain_config: FileConfig): selected_project = toolchain_config.get_value("currentProject") if selected_project: preffered_config = toolchain_config.get_path(join(selected_project, "make.json")) @@ -162,7 +162,7 @@ class Globals: self.parameter_signature = inspect.Signature(parameters, return_annotation=int) return self.parameter_signature - def is_project_available(self, which_project: Optional[str] = None) -> bool: + def is_project_available(self, which_project: Optional[str] = None): from .make_config import MakeConfig if not isinstance(self.PREFERRED_CONFIG, MakeConfig): return False diff --git a/src/icmtoolchain/output_directory.py b/src/icmtoolchain/output_directory.py index 782bbc3..4c6c9d7 100644 --- a/src/icmtoolchain/output_directory.py +++ b/src/icmtoolchain/output_directory.py @@ -28,7 +28,7 @@ def expand_paths(file_or_directory: str, filter: Optional[Callable[[str], bool]] locations.append(file_or_directory) return locations -def get_windows_appdata(csidl: int = 26, env_variable: str = "APPDATA", shell_name: str = "AppData") -> str: +def get_windows_appdata(csidl: int, env_variable: str, shell_name: str) -> str: try: import ctypes except ImportError: @@ -59,15 +59,34 @@ def get_windows_appdata(csidl: int = 26, env_variable: str = "APPDATA", shell_na directory, _ = winreg.QueryValueEx(key, shell_name) return str(directory) -@lru_cache -def get_local_share_directory() -> str: +@lru_cache(maxsize=2048) +def get_user_config_directory(*components: str) -> str: if platform.system() == "Windows": - return normpath(get_windows_appdata()) + appdata_path = get_windows_appdata(26, "APPDATA", "AppData") + return join(normpath(appdata_path), *components) path = environ.get("XDG_DATA_HOME", "") - if ensure_not_whitespace(path): - return path - if platform.system() == "Darwin": - path = expanduser("~/Library/Application Support") - else: - path = expanduser("~/.local/share") - return path + if not ensure_not_whitespace(path): + if platform.system() == "Darwin": + path = expanduser("~/Library/Application Support") + else: + path = expanduser("~/.config") + return join(path, *components) + +def get_config_directory() -> str: + return get_user_config_directory("icmtoolchain") + +@lru_cache(maxsize=2048) +def get_user_temporary_directory(*components: str) -> str: + if platform.system() == "Windows": + appdata_path = get_windows_appdata(28, "LOCALAPPDATA", "Local AppData") + return join(normpath(appdata_path), *components, "Cache") + path = environ.get("XDG_CACHE_HOME", "") + if not ensure_not_whitespace(path): + if platform.system() == "Darwin": + path = expanduser("~/Library/Caches") + else: + path = expanduser("~/.cache") + return join(path, *components) + +def get_temporary_directory() -> str: + return get_user_temporary_directory("icmtoolchain")