From 116053564f3a3bb10f2ce7467698c6115172e34b Mon Sep 17 00:00:00 2001 From: Aki Van Ness Date: Thu, 2 May 2024 20:01:13 -0700 Subject: [PATCH] squishy: in an attempt to reduce the NIH-ness, added `platformsdirs` as a dep to use for resolving Squishy's cache, config, and data directories --- setup.py | 1 + squishy/config.py | 45 ++++++--------------------------------------- 2 files changed, 7 insertions(+), 39 deletions(-) diff --git a/setup.py b/setup.py index aef0bd8e..ebb9d592 100755 --- a/setup.py +++ b/setup.py @@ -65,6 +65,7 @@ def doc_ver() -> str: 'torii>=0.5.0,<1.0', 'usb-construct<1.0', 'sol-usb>=0.3.0,<1.0', + 'platformdirs~=4.2.1' ], packages = find_packages( diff --git a/squishy/config.py b/squishy/config.py index d8aea3b6..2a173ab8 100644 --- a/squishy/config.py +++ b/squishy/config.py @@ -1,47 +1,15 @@ # SPDX-License-Identifier: BSD-3-Clause -import platform -from pathlib import Path -from os import environ +from pathlib import Path +from platformdirs import user_data_path, user_config_path, user_cache_path SQUISHY_NAME = 'squishy' -_os = platform.system() - -if _os == 'Linux': - def _get_xdg_dir(name: str, default: Path) -> Path: - if name in environ: - return Path(environ[name]) - return default - - HOME_DIR = _get_xdg_dir('XDG_HOME', Path.home() ) - CACHE_DIR = _get_xdg_dir('XDG_CACHE_HOME', (HOME_DIR / '.cache') ) - DATA_DIR = _get_xdg_dir('XDG_DATA_HOME', (HOME_DIR / '.local/share')) - CONFIG_DIR = _get_xdg_dir('XDG_CONFIG_HOME', (HOME_DIR / '.config') ) - - del _get_xdg_dir -elif _os == 'Windows': - HOME_DIR = Path.home() - CACHE_DIR = (HOME_DIR / r'AppData\Local\Temp') - DATA_DIR = (HOME_DIR / r'AppData\Roaming' ) - CONFIG_DIR = DATA_DIR -elif _os == 'Darwin': - HOME_DIR = Path.home() - CACHE_DIR = (HOME_DIR / 'Library/Caches' ) - DATA_DIR = (HOME_DIR / 'Library/Application Support') - CONFIG_DIR = DATA_DIR -else: - HOME_DIR = Path.home() - CACHE_DIR = (HOME_DIR / '.cache' ) - DATA_DIR = (HOME_DIR / '.local/share') - CONFIG_DIR = (HOME_DIR / '.config' ) - -del _os - # Squishy-specific sub dirs -SQUISHY_CACHE = (CACHE_DIR / SQUISHY_NAME) -SQUISHY_DATA = (DATA_DIR / SQUISHY_NAME) -SQUISHY_CONFIG = (CONFIG_DIR / SQUISHY_NAME) +SQUISHY_CACHE = user_cache_path(SQUISHY_NAME, False) +SQUISHY_DATA = user_data_path(SQUISHY_NAME, False) +SQUISHY_CONFIG = user_config_path(SQUISHY_NAME, False) + SQUISHY_APPLETS = (SQUISHY_DATA / 'applets') SQUISHY_APPLET_CACHE = (SQUISHY_CACHE / 'applets') @@ -49,7 +17,6 @@ def _get_xdg_dir(name: str, default: Path) -> Path: SQUISHY_BUILD_DIR = (SQUISHY_CACHE / 'build') # File path constants -SQUISHY_HISTORY_FILE = (SQUISHY_CACHE / '.repl-history') # Hardware Metadata, etc USB_VID = 0x1209