Skip to content

Commit

Permalink
squishy: in an attempt to reduce the NIH-ness, added platformsdirs
Browse files Browse the repository at this point in the history
…as a dep to use for resolving Squishy's cache, config, and data directories
  • Loading branch information
lethalbit committed May 3, 2024
1 parent 3e736a6 commit 1160535
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 39 deletions.
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
45 changes: 6 additions & 39 deletions squishy/config.py
Original file line number Diff line number Diff line change
@@ -1,55 +1,22 @@
# 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')

SQUISHY_BUILD_DIR = (SQUISHY_CACHE / 'build')

# File path constants
SQUISHY_HISTORY_FILE = (SQUISHY_CACHE / '.repl-history')

# Hardware Metadata, etc
USB_VID = 0x1209
Expand Down

0 comments on commit 1160535

Please sign in to comment.