Last active
November 2, 2023 13:48
-
-
Save mosquito/97235ec096bd91263a3090456e43f16b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import platform | |
from pathlib import Path | |
match platform.system(): | |
case 'Linux': | |
CACHE_PATH = Path(os.getenv("XDG_CACHE_HOME", '~/.cache')) | |
case 'Darwin': | |
CACHE_PATH = Path('~') / 'Library' / 'Caches' | |
case 'Windows': | |
CACHE_PATH = Path('~') / 'AppData' / 'Local' | |
case _: | |
CACHE_PATH = Path(tempfile.gettempdir()) / "cache" | |
def get_cache_dir(*suffix) -> Path: | |
cache_path = CACHE_PATH.expanduser().resolve() | |
if suffix: | |
cache_path = cache_path.joinpath(*suffix) | |
cache_path.mkdir(exist_ok=True, parents=True) | |
return cache_path |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment