123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331 |
- """
- Utilities for determining application-specific dirs. See <https://github.com/platformdirs/platformdirs> for details and
- usage.
- """
- from __future__ import annotations
- import importlib
- import os
- import sys
- from pathlib import Path
- from typing import TYPE_CHECKING
- if TYPE_CHECKING:
- from typing_extensions import Literal # pragma: no cover
- from .api import PlatformDirsABC
- from .version import __version__, __version_info__
- def _set_platform_dir_class() -> type[PlatformDirsABC]:
- if os.getenv("ANDROID_DATA") == "/data" and os.getenv("ANDROID_ROOT") == "/system":
- module, name = "platformdirs.android", "Android"
- elif sys.platform == "win32":
- module, name = "platformdirs.windows", "Windows"
- elif sys.platform == "darwin":
- module, name = "platformdirs.macos", "MacOS"
- else:
- module, name = "platformdirs.unix", "Unix"
- result: type[PlatformDirsABC] = getattr(importlib.import_module(module), name)
- return result
- PlatformDirs = _set_platform_dir_class() #: Currently active platform
- AppDirs = PlatformDirs #: Backwards compatibility with appdirs
- def user_data_dir(
- appname: str | None = None,
- appauthor: str | None | Literal[False] = None,
- version: str | None = None,
- roaming: bool = False,
- ) -> str:
- """
- :param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
- :param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
- :param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
- :param roaming: See `roaming <platformdirs.api.PlatformDirsABC.version>`.
- :returns: data directory tied to the user
- """
- return PlatformDirs(appname=appname, appauthor=appauthor, version=version, roaming=roaming).user_data_dir
- def site_data_dir(
- appname: str | None = None,
- appauthor: str | None | Literal[False] = None,
- version: str | None = None,
- multipath: bool = False,
- ) -> str:
- """
- :param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
- :param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
- :param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
- :param multipath: See `roaming <platformdirs.api.PlatformDirsABC.multipath>`.
- :returns: data directory shared by users
- """
- return PlatformDirs(appname=appname, appauthor=appauthor, version=version, multipath=multipath).site_data_dir
- def user_config_dir(
- appname: str | None = None,
- appauthor: str | None | Literal[False] = None,
- version: str | None = None,
- roaming: bool = False,
- ) -> str:
- """
- :param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
- :param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
- :param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
- :param roaming: See `roaming <platformdirs.api.PlatformDirsABC.version>`.
- :returns: config directory tied to the user
- """
- return PlatformDirs(appname=appname, appauthor=appauthor, version=version, roaming=roaming).user_config_dir
- def site_config_dir(
- appname: str | None = None,
- appauthor: str | None | Literal[False] = None,
- version: str | None = None,
- multipath: bool = False,
- ) -> str:
- """
- :param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
- :param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
- :param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
- :param multipath: See `roaming <platformdirs.api.PlatformDirsABC.multipath>`.
- :returns: config directory shared by the users
- """
- return PlatformDirs(appname=appname, appauthor=appauthor, version=version, multipath=multipath).site_config_dir
- def user_cache_dir(
- appname: str | None = None,
- appauthor: str | None | Literal[False] = None,
- version: str | None = None,
- opinion: bool = True,
- ) -> str:
- """
- :param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
- :param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
- :param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
- :param opinion: See `roaming <platformdirs.api.PlatformDirsABC.opinion>`.
- :returns: cache directory tied to the user
- """
- return PlatformDirs(appname=appname, appauthor=appauthor, version=version, opinion=opinion).user_cache_dir
- def user_state_dir(
- appname: str | None = None,
- appauthor: str | None | Literal[False] = None,
- version: str | None = None,
- roaming: bool = False,
- ) -> str:
- """
- :param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
- :param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
- :param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
- :param roaming: See `roaming <platformdirs.api.PlatformDirsABC.version>`.
- :returns: state directory tied to the user
- """
- return PlatformDirs(appname=appname, appauthor=appauthor, version=version, roaming=roaming).user_state_dir
- def user_log_dir(
- appname: str | None = None,
- appauthor: str | None | Literal[False] = None,
- version: str | None = None,
- opinion: bool = True,
- ) -> str:
- """
- :param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
- :param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
- :param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
- :param opinion: See `roaming <platformdirs.api.PlatformDirsABC.opinion>`.
- :returns: log directory tied to the user
- """
- return PlatformDirs(appname=appname, appauthor=appauthor, version=version, opinion=opinion).user_log_dir
- def user_documents_dir() -> str:
- """
- :returns: documents directory tied to the user
- """
- return PlatformDirs().user_documents_dir
- def user_runtime_dir(
- appname: str | None = None,
- appauthor: str | None | Literal[False] = None,
- version: str | None = None,
- opinion: bool = True,
- ) -> str:
- """
- :param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
- :param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
- :param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
- :param opinion: See `opinion <platformdirs.api.PlatformDirsABC.opinion>`.
- :returns: runtime directory tied to the user
- """
- return PlatformDirs(appname=appname, appauthor=appauthor, version=version, opinion=opinion).user_runtime_dir
- def user_data_path(
- appname: str | None = None,
- appauthor: str | None | Literal[False] = None,
- version: str | None = None,
- roaming: bool = False,
- ) -> Path:
- """
- :param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
- :param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
- :param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
- :param roaming: See `roaming <platformdirs.api.PlatformDirsABC.version>`.
- :returns: data path tied to the user
- """
- return PlatformDirs(appname=appname, appauthor=appauthor, version=version, roaming=roaming).user_data_path
- def site_data_path(
- appname: str | None = None,
- appauthor: str | None | Literal[False] = None,
- version: str | None = None,
- multipath: bool = False,
- ) -> Path:
- """
- :param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
- :param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
- :param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
- :param multipath: See `multipath <platformdirs.api.PlatformDirsABC.multipath>`.
- :returns: data path shared by users
- """
- return PlatformDirs(appname=appname, appauthor=appauthor, version=version, multipath=multipath).site_data_path
- def user_config_path(
- appname: str | None = None,
- appauthor: str | None | Literal[False] = None,
- version: str | None = None,
- roaming: bool = False,
- ) -> Path:
- """
- :param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
- :param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
- :param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
- :param roaming: See `roaming <platformdirs.api.PlatformDirsABC.version>`.
- :returns: config path tied to the user
- """
- return PlatformDirs(appname=appname, appauthor=appauthor, version=version, roaming=roaming).user_config_path
- def site_config_path(
- appname: str | None = None,
- appauthor: str | None | Literal[False] = None,
- version: str | None = None,
- multipath: bool = False,
- ) -> Path:
- """
- :param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
- :param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
- :param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
- :param multipath: See `roaming <platformdirs.api.PlatformDirsABC.multipath>`.
- :returns: config path shared by the users
- """
- return PlatformDirs(appname=appname, appauthor=appauthor, version=version, multipath=multipath).site_config_path
- def user_cache_path(
- appname: str | None = None,
- appauthor: str | None | Literal[False] = None,
- version: str | None = None,
- opinion: bool = True,
- ) -> Path:
- """
- :param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
- :param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
- :param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
- :param opinion: See `roaming <platformdirs.api.PlatformDirsABC.opinion>`.
- :returns: cache path tied to the user
- """
- return PlatformDirs(appname=appname, appauthor=appauthor, version=version, opinion=opinion).user_cache_path
- def user_state_path(
- appname: str | None = None,
- appauthor: str | None | Literal[False] = None,
- version: str | None = None,
- roaming: bool = False,
- ) -> Path:
- """
- :param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
- :param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
- :param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
- :param roaming: See `roaming <platformdirs.api.PlatformDirsABC.version>`.
- :returns: state path tied to the user
- """
- return PlatformDirs(appname=appname, appauthor=appauthor, version=version, roaming=roaming).user_state_path
- def user_log_path(
- appname: str | None = None,
- appauthor: str | None | Literal[False] = None,
- version: str | None = None,
- opinion: bool = True,
- ) -> Path:
- """
- :param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
- :param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
- :param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
- :param opinion: See `roaming <platformdirs.api.PlatformDirsABC.opinion>`.
- :returns: log path tied to the user
- """
- return PlatformDirs(appname=appname, appauthor=appauthor, version=version, opinion=opinion).user_log_path
- def user_documents_path() -> Path:
- """
- :returns: documents path tied to the user
- """
- return PlatformDirs().user_documents_path
- def user_runtime_path(
- appname: str | None = None,
- appauthor: str | None | Literal[False] = None,
- version: str | None = None,
- opinion: bool = True,
- ) -> Path:
- """
- :param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
- :param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
- :param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
- :param opinion: See `opinion <platformdirs.api.PlatformDirsABC.opinion>`.
- :returns: runtime path tied to the user
- """
- return PlatformDirs(appname=appname, appauthor=appauthor, version=version, opinion=opinion).user_runtime_path
- __all__ = [
- "__version__",
- "__version_info__",
- "PlatformDirs",
- "AppDirs",
- "PlatformDirsABC",
- "user_data_dir",
- "user_config_dir",
- "user_cache_dir",
- "user_state_dir",
- "user_log_dir",
- "user_documents_dir",
- "user_runtime_dir",
- "site_data_dir",
- "site_config_dir",
- "user_data_path",
- "user_config_path",
- "user_cache_path",
- "user_state_path",
- "user_log_path",
- "user_documents_path",
- "user_runtime_path",
- "site_data_path",
- "site_config_path",
- ]
|