__init__.py 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857
  1. """Utilities for determining application-specific dirs.
  2. Provides convenience functions (e.g. :func:`user_data_dir`, :func:`user_config_path`), a :data:`PlatformDirs` class that
  3. auto-detects the current platform, and the :class:`~platformdirs.api.PlatformDirsABC` base class.
  4. See <https://github.com/platformdirs/platformdirs> for details and usage.
  5. """
  6. from __future__ import annotations
  7. import os
  8. import sys
  9. from typing import TYPE_CHECKING
  10. from .api import PlatformDirsABC
  11. from .version import __version__
  12. from .version import __version_tuple__ as __version_info__
  13. if TYPE_CHECKING:
  14. from pathlib import Path
  15. from typing import Literal
  16. if sys.platform == "win32":
  17. from platformdirs.windows import Windows as _Result
  18. elif sys.platform == "darwin":
  19. from platformdirs.macos import MacOS as _Result
  20. else:
  21. from platformdirs.unix import Unix as _Result
  22. def _set_platform_dir_class() -> type[PlatformDirsABC]:
  23. if os.getenv("ANDROID_DATA") == "/data" and os.getenv("ANDROID_ROOT") == "/system":
  24. if os.getenv("SHELL") or os.getenv("PREFIX"):
  25. return _Result
  26. from platformdirs.android import _android_folder # noqa: PLC0415
  27. if _android_folder() is not None:
  28. from platformdirs.android import Android # noqa: PLC0415
  29. return Android # return to avoid redefinition of a result
  30. return _Result
  31. if TYPE_CHECKING:
  32. # Work around mypy issue: https://github.com/python/mypy/issues/10962
  33. PlatformDirs = _Result
  34. else:
  35. PlatformDirs = _set_platform_dir_class() #: Currently active platform
  36. AppDirs = PlatformDirs #: Backwards compatibility with appdirs
  37. def user_data_dir( # noqa: PLR0913, PLR0917
  38. appname: str | None = None,
  39. appauthor: str | Literal[False] | None = None,
  40. version: str | None = None,
  41. roaming: bool = False, # noqa: FBT001, FBT002
  42. ensure_exists: bool = False, # noqa: FBT001, FBT002
  43. use_site_for_root: bool = False, # noqa: FBT001, FBT002
  44. ) -> str:
  45. """:param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
  46. :param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
  47. :param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
  48. :param roaming: See `roaming <platformdirs.api.PlatformDirsABC.roaming>`.
  49. :param ensure_exists: See `ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.
  50. :param use_site_for_root: See `use_site_for_root <platformdirs.api.PlatformDirsABC.use_site_for_root>`.
  51. :returns: data directory tied to the user
  52. """
  53. return PlatformDirs(
  54. appname=appname,
  55. appauthor=appauthor,
  56. version=version,
  57. roaming=roaming,
  58. ensure_exists=ensure_exists,
  59. use_site_for_root=use_site_for_root,
  60. ).user_data_dir
  61. def site_data_dir(
  62. appname: str | None = None,
  63. appauthor: str | Literal[False] | None = None,
  64. version: str | None = None,
  65. multipath: bool = False, # noqa: FBT001, FBT002
  66. ensure_exists: bool = False, # noqa: FBT001, FBT002
  67. ) -> str:
  68. """:param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
  69. :param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
  70. :param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
  71. :param multipath: See `multipath <platformdirs.api.PlatformDirsABC.multipath>`.
  72. :param ensure_exists: See `ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.
  73. :returns: data directory shared by users
  74. """
  75. return PlatformDirs(
  76. appname=appname,
  77. appauthor=appauthor,
  78. version=version,
  79. multipath=multipath,
  80. ensure_exists=ensure_exists,
  81. ).site_data_dir
  82. def user_config_dir( # noqa: PLR0913, PLR0917
  83. appname: str | None = None,
  84. appauthor: str | Literal[False] | None = None,
  85. version: str | None = None,
  86. roaming: bool = False, # noqa: FBT001, FBT002
  87. ensure_exists: bool = False, # noqa: FBT001, FBT002
  88. use_site_for_root: bool = False, # noqa: FBT001, FBT002
  89. ) -> str:
  90. """:param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
  91. :param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
  92. :param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
  93. :param roaming: See `roaming <platformdirs.api.PlatformDirsABC.roaming>`.
  94. :param ensure_exists: See `ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.
  95. :param use_site_for_root: See `use_site_for_root <platformdirs.api.PlatformDirsABC.use_site_for_root>`.
  96. :returns: config directory tied to the user
  97. """
  98. return PlatformDirs(
  99. appname=appname,
  100. appauthor=appauthor,
  101. version=version,
  102. roaming=roaming,
  103. ensure_exists=ensure_exists,
  104. use_site_for_root=use_site_for_root,
  105. ).user_config_dir
  106. def site_config_dir(
  107. appname: str | None = None,
  108. appauthor: str | Literal[False] | None = None,
  109. version: str | None = None,
  110. multipath: bool = False, # noqa: FBT001, FBT002
  111. ensure_exists: bool = False, # noqa: FBT001, FBT002
  112. ) -> str:
  113. """:param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
  114. :param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
  115. :param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
  116. :param multipath: See `multipath <platformdirs.api.PlatformDirsABC.multipath>`.
  117. :param ensure_exists: See `ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.
  118. :returns: config directory shared by users
  119. """
  120. return PlatformDirs(
  121. appname=appname,
  122. appauthor=appauthor,
  123. version=version,
  124. multipath=multipath,
  125. ensure_exists=ensure_exists,
  126. ).site_config_dir
  127. def user_cache_dir( # noqa: PLR0913, PLR0917
  128. appname: str | None = None,
  129. appauthor: str | Literal[False] | None = None,
  130. version: str | None = None,
  131. opinion: bool = True, # noqa: FBT001, FBT002
  132. ensure_exists: bool = False, # noqa: FBT001, FBT002
  133. use_site_for_root: bool = False, # noqa: FBT001, FBT002
  134. ) -> str:
  135. """:param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
  136. :param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
  137. :param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
  138. :param opinion: See `opinion <platformdirs.api.PlatformDirsABC.opinion>`.
  139. :param ensure_exists: See `ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.
  140. :param use_site_for_root: See `use_site_for_root <platformdirs.api.PlatformDirsABC.use_site_for_root>`.
  141. :returns: cache directory tied to the user
  142. """
  143. return PlatformDirs(
  144. appname=appname,
  145. appauthor=appauthor,
  146. version=version,
  147. opinion=opinion,
  148. ensure_exists=ensure_exists,
  149. use_site_for_root=use_site_for_root,
  150. ).user_cache_dir
  151. def site_cache_dir(
  152. appname: str | None = None,
  153. appauthor: str | Literal[False] | None = None,
  154. version: str | None = None,
  155. opinion: bool = True, # noqa: FBT001, FBT002
  156. ensure_exists: bool = False, # noqa: FBT001, FBT002
  157. ) -> str:
  158. """:param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
  159. :param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
  160. :param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
  161. :param opinion: See `opinion <platformdirs.api.PlatformDirsABC.opinion>`.
  162. :param ensure_exists: See `ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.
  163. :returns: cache directory shared by users
  164. """
  165. return PlatformDirs(
  166. appname=appname,
  167. appauthor=appauthor,
  168. version=version,
  169. opinion=opinion,
  170. ensure_exists=ensure_exists,
  171. ).site_cache_dir
  172. def user_state_dir( # noqa: PLR0913, PLR0917
  173. appname: str | None = None,
  174. appauthor: str | Literal[False] | None = None,
  175. version: str | None = None,
  176. roaming: bool = False, # noqa: FBT001, FBT002
  177. ensure_exists: bool = False, # noqa: FBT001, FBT002
  178. use_site_for_root: bool = False, # noqa: FBT001, FBT002
  179. ) -> str:
  180. """:param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
  181. :param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
  182. :param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
  183. :param roaming: See `roaming <platformdirs.api.PlatformDirsABC.roaming>`.
  184. :param ensure_exists: See `ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.
  185. :param use_site_for_root: See `use_site_for_root <platformdirs.api.PlatformDirsABC.use_site_for_root>`.
  186. :returns: state directory tied to the user
  187. """
  188. return PlatformDirs(
  189. appname=appname,
  190. appauthor=appauthor,
  191. version=version,
  192. roaming=roaming,
  193. ensure_exists=ensure_exists,
  194. use_site_for_root=use_site_for_root,
  195. ).user_state_dir
  196. def site_state_dir(
  197. appname: str | None = None,
  198. appauthor: str | Literal[False] | None = None,
  199. version: str | None = None,
  200. ensure_exists: bool = False, # noqa: FBT001, FBT002
  201. ) -> str:
  202. """:param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
  203. :param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
  204. :param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
  205. :param ensure_exists: See `ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.
  206. :returns: state directory shared by users
  207. """
  208. return PlatformDirs(
  209. appname=appname,
  210. appauthor=appauthor,
  211. version=version,
  212. ensure_exists=ensure_exists,
  213. ).site_state_dir
  214. def user_log_dir( # noqa: PLR0913, PLR0917
  215. appname: str | None = None,
  216. appauthor: str | Literal[False] | None = None,
  217. version: str | None = None,
  218. opinion: bool = True, # noqa: FBT001, FBT002
  219. ensure_exists: bool = False, # noqa: FBT001, FBT002
  220. use_site_for_root: bool = False, # noqa: FBT001, FBT002
  221. ) -> str:
  222. """:param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
  223. :param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
  224. :param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
  225. :param opinion: See `opinion <platformdirs.api.PlatformDirsABC.opinion>`.
  226. :param ensure_exists: See `ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.
  227. :param use_site_for_root: See `use_site_for_root <platformdirs.api.PlatformDirsABC.use_site_for_root>`.
  228. :returns: log directory tied to the user
  229. """
  230. return PlatformDirs(
  231. appname=appname,
  232. appauthor=appauthor,
  233. version=version,
  234. opinion=opinion,
  235. ensure_exists=ensure_exists,
  236. use_site_for_root=use_site_for_root,
  237. ).user_log_dir
  238. def site_log_dir(
  239. appname: str | None = None,
  240. appauthor: str | Literal[False] | None = None,
  241. version: str | None = None,
  242. opinion: bool = True, # noqa: FBT001, FBT002
  243. ensure_exists: bool = False, # noqa: FBT001, FBT002
  244. ) -> str:
  245. """:param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
  246. :param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
  247. :param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
  248. :param opinion: See `opinion <platformdirs.api.PlatformDirsABC.opinion>`.
  249. :param ensure_exists: See `ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.
  250. :returns: log directory shared by users
  251. """
  252. return PlatformDirs(
  253. appname=appname,
  254. appauthor=appauthor,
  255. version=version,
  256. opinion=opinion,
  257. ensure_exists=ensure_exists,
  258. ).site_log_dir
  259. def user_documents_dir() -> str:
  260. """:returns: documents directory tied to the user"""
  261. return PlatformDirs().user_documents_dir
  262. def user_downloads_dir() -> str:
  263. """:returns: downloads directory tied to the user"""
  264. return PlatformDirs().user_downloads_dir
  265. def user_pictures_dir() -> str:
  266. """:returns: pictures directory tied to the user"""
  267. return PlatformDirs().user_pictures_dir
  268. def user_videos_dir() -> str:
  269. """:returns: videos directory tied to the user"""
  270. return PlatformDirs().user_videos_dir
  271. def user_music_dir() -> str:
  272. """:returns: music directory tied to the user"""
  273. return PlatformDirs().user_music_dir
  274. def user_desktop_dir() -> str:
  275. """:returns: desktop directory tied to the user"""
  276. return PlatformDirs().user_desktop_dir
  277. def user_bin_dir() -> str:
  278. """:returns: bin directory tied to the user"""
  279. return PlatformDirs().user_bin_dir
  280. def site_bin_dir() -> str:
  281. """:returns: bin directory shared by users"""
  282. return PlatformDirs().site_bin_dir
  283. def user_applications_dir() -> str:
  284. """:returns: applications directory tied to the user"""
  285. return PlatformDirs().user_applications_dir
  286. def site_applications_dir(
  287. multipath: bool = False, # noqa: FBT001, FBT002
  288. ensure_exists: bool = False, # noqa: FBT001, FBT002
  289. ) -> str:
  290. """:param multipath: See `multipath <platformdirs.api.PlatformDirsABC.multipath>`.
  291. :param ensure_exists: See `ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.
  292. :returns: applications directory shared by users
  293. """
  294. return PlatformDirs(
  295. multipath=multipath,
  296. ensure_exists=ensure_exists,
  297. ).site_applications_dir
  298. def user_runtime_dir( # noqa: PLR0913, PLR0917
  299. appname: str | None = None,
  300. appauthor: str | Literal[False] | None = None,
  301. version: str | None = None,
  302. opinion: bool = True, # noqa: FBT001, FBT002
  303. ensure_exists: bool = False, # noqa: FBT001, FBT002
  304. use_site_for_root: bool = False, # noqa: FBT001, FBT002
  305. ) -> str:
  306. """:param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
  307. :param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
  308. :param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
  309. :param opinion: See `opinion <platformdirs.api.PlatformDirsABC.opinion>`.
  310. :param ensure_exists: See `ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.
  311. :param use_site_for_root: See `use_site_for_root <platformdirs.api.PlatformDirsABC.use_site_for_root>`.
  312. :returns: runtime directory tied to the user
  313. """
  314. return PlatformDirs(
  315. appname=appname,
  316. appauthor=appauthor,
  317. version=version,
  318. opinion=opinion,
  319. ensure_exists=ensure_exists,
  320. use_site_for_root=use_site_for_root,
  321. ).user_runtime_dir
  322. def site_runtime_dir(
  323. appname: str | None = None,
  324. appauthor: str | Literal[False] | None = None,
  325. version: str | None = None,
  326. opinion: bool = True, # noqa: FBT001, FBT002
  327. ensure_exists: bool = False, # noqa: FBT001, FBT002
  328. ) -> str:
  329. """:param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
  330. :param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
  331. :param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
  332. :param opinion: See `opinion <platformdirs.api.PlatformDirsABC.opinion>`.
  333. :param ensure_exists: See `ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.
  334. :returns: runtime directory shared by users
  335. """
  336. return PlatformDirs(
  337. appname=appname,
  338. appauthor=appauthor,
  339. version=version,
  340. opinion=opinion,
  341. ensure_exists=ensure_exists,
  342. ).site_runtime_dir
  343. def user_data_path( # noqa: PLR0913, PLR0917
  344. appname: str | None = None,
  345. appauthor: str | Literal[False] | None = None,
  346. version: str | None = None,
  347. roaming: bool = False, # noqa: FBT001, FBT002
  348. ensure_exists: bool = False, # noqa: FBT001, FBT002
  349. use_site_for_root: bool = False, # noqa: FBT001, FBT002
  350. ) -> Path:
  351. """:param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
  352. :param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
  353. :param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
  354. :param roaming: See `roaming <platformdirs.api.PlatformDirsABC.roaming>`.
  355. :param ensure_exists: See `ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.
  356. :param use_site_for_root: See `use_site_for_root <platformdirs.api.PlatformDirsABC.use_site_for_root>`.
  357. :returns: data path tied to the user
  358. """
  359. return PlatformDirs(
  360. appname=appname,
  361. appauthor=appauthor,
  362. version=version,
  363. roaming=roaming,
  364. ensure_exists=ensure_exists,
  365. use_site_for_root=use_site_for_root,
  366. ).user_data_path
  367. def site_data_path(
  368. appname: str | None = None,
  369. appauthor: str | Literal[False] | None = None,
  370. version: str | None = None,
  371. multipath: bool = False, # noqa: FBT001, FBT002
  372. ensure_exists: bool = False, # noqa: FBT001, FBT002
  373. ) -> Path:
  374. """:param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
  375. :param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
  376. :param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
  377. :param multipath: See `multipath <platformdirs.api.PlatformDirsABC.multipath>`.
  378. :param ensure_exists: See `ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.
  379. :returns: data path shared by users
  380. """
  381. return PlatformDirs(
  382. appname=appname,
  383. appauthor=appauthor,
  384. version=version,
  385. multipath=multipath,
  386. ensure_exists=ensure_exists,
  387. ).site_data_path
  388. def user_config_path( # noqa: PLR0913, PLR0917
  389. appname: str | None = None,
  390. appauthor: str | Literal[False] | None = None,
  391. version: str | None = None,
  392. roaming: bool = False, # noqa: FBT001, FBT002
  393. ensure_exists: bool = False, # noqa: FBT001, FBT002
  394. use_site_for_root: bool = False, # noqa: FBT001, FBT002
  395. ) -> Path:
  396. """:param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
  397. :param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
  398. :param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
  399. :param roaming: See `roaming <platformdirs.api.PlatformDirsABC.roaming>`.
  400. :param ensure_exists: See `ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.
  401. :param use_site_for_root: See `use_site_for_root <platformdirs.api.PlatformDirsABC.use_site_for_root>`.
  402. :returns: config path tied to the user
  403. """
  404. return PlatformDirs(
  405. appname=appname,
  406. appauthor=appauthor,
  407. version=version,
  408. roaming=roaming,
  409. ensure_exists=ensure_exists,
  410. use_site_for_root=use_site_for_root,
  411. ).user_config_path
  412. def site_config_path(
  413. appname: str | None = None,
  414. appauthor: str | Literal[False] | None = None,
  415. version: str | None = None,
  416. multipath: bool = False, # noqa: FBT001, FBT002
  417. ensure_exists: bool = False, # noqa: FBT001, FBT002
  418. ) -> Path:
  419. """:param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
  420. :param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
  421. :param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
  422. :param multipath: See `multipath <platformdirs.api.PlatformDirsABC.multipath>`.
  423. :param ensure_exists: See `ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.
  424. :returns: config path shared by users
  425. """
  426. return PlatformDirs(
  427. appname=appname,
  428. appauthor=appauthor,
  429. version=version,
  430. multipath=multipath,
  431. ensure_exists=ensure_exists,
  432. ).site_config_path
  433. def site_cache_path(
  434. appname: str | None = None,
  435. appauthor: str | Literal[False] | None = None,
  436. version: str | None = None,
  437. opinion: bool = True, # noqa: FBT001, FBT002
  438. ensure_exists: bool = False, # noqa: FBT001, FBT002
  439. ) -> Path:
  440. """:param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
  441. :param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
  442. :param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
  443. :param opinion: See `opinion <platformdirs.api.PlatformDirsABC.opinion>`.
  444. :param ensure_exists: See `ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.
  445. :returns: cache path shared by users
  446. """
  447. return PlatformDirs(
  448. appname=appname,
  449. appauthor=appauthor,
  450. version=version,
  451. opinion=opinion,
  452. ensure_exists=ensure_exists,
  453. ).site_cache_path
  454. def user_cache_path( # noqa: PLR0913, PLR0917
  455. appname: str | None = None,
  456. appauthor: str | Literal[False] | None = None,
  457. version: str | None = None,
  458. opinion: bool = True, # noqa: FBT001, FBT002
  459. ensure_exists: bool = False, # noqa: FBT001, FBT002
  460. use_site_for_root: bool = False, # noqa: FBT001, FBT002
  461. ) -> Path:
  462. """:param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
  463. :param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
  464. :param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
  465. :param opinion: See `opinion <platformdirs.api.PlatformDirsABC.opinion>`.
  466. :param ensure_exists: See `ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.
  467. :param use_site_for_root: See `use_site_for_root <platformdirs.api.PlatformDirsABC.use_site_for_root>`.
  468. :returns: cache path tied to the user
  469. """
  470. return PlatformDirs(
  471. appname=appname,
  472. appauthor=appauthor,
  473. version=version,
  474. opinion=opinion,
  475. ensure_exists=ensure_exists,
  476. use_site_for_root=use_site_for_root,
  477. ).user_cache_path
  478. def user_state_path( # noqa: PLR0913, PLR0917
  479. appname: str | None = None,
  480. appauthor: str | Literal[False] | None = None,
  481. version: str | None = None,
  482. roaming: bool = False, # noqa: FBT001, FBT002
  483. ensure_exists: bool = False, # noqa: FBT001, FBT002
  484. use_site_for_root: bool = False, # noqa: FBT001, FBT002
  485. ) -> Path:
  486. """:param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
  487. :param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
  488. :param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
  489. :param roaming: See `roaming <platformdirs.api.PlatformDirsABC.roaming>`.
  490. :param ensure_exists: See `ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.
  491. :param use_site_for_root: See `use_site_for_root <platformdirs.api.PlatformDirsABC.use_site_for_root>`.
  492. :returns: state path tied to the user
  493. """
  494. return PlatformDirs(
  495. appname=appname,
  496. appauthor=appauthor,
  497. version=version,
  498. roaming=roaming,
  499. ensure_exists=ensure_exists,
  500. use_site_for_root=use_site_for_root,
  501. ).user_state_path
  502. def site_state_path(
  503. appname: str | None = None,
  504. appauthor: str | Literal[False] | None = None,
  505. version: str | None = None,
  506. ensure_exists: bool = False, # noqa: FBT001, FBT002
  507. ) -> Path:
  508. """:param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
  509. :param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
  510. :param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
  511. :param ensure_exists: See `ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.
  512. :returns: state path shared by users
  513. """
  514. return PlatformDirs(
  515. appname=appname,
  516. appauthor=appauthor,
  517. version=version,
  518. ensure_exists=ensure_exists,
  519. ).site_state_path
  520. def user_log_path( # noqa: PLR0913, PLR0917
  521. appname: str | None = None,
  522. appauthor: str | Literal[False] | None = None,
  523. version: str | None = None,
  524. opinion: bool = True, # noqa: FBT001, FBT002
  525. ensure_exists: bool = False, # noqa: FBT001, FBT002
  526. use_site_for_root: bool = False, # noqa: FBT001, FBT002
  527. ) -> Path:
  528. """:param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
  529. :param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
  530. :param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
  531. :param opinion: See `opinion <platformdirs.api.PlatformDirsABC.opinion>`.
  532. :param ensure_exists: See `ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.
  533. :param use_site_for_root: See `use_site_for_root <platformdirs.api.PlatformDirsABC.use_site_for_root>`.
  534. :returns: log path tied to the user
  535. """
  536. return PlatformDirs(
  537. appname=appname,
  538. appauthor=appauthor,
  539. version=version,
  540. opinion=opinion,
  541. ensure_exists=ensure_exists,
  542. use_site_for_root=use_site_for_root,
  543. ).user_log_path
  544. def site_log_path(
  545. appname: str | None = None,
  546. appauthor: str | Literal[False] | None = None,
  547. version: str | None = None,
  548. opinion: bool = True, # noqa: FBT001, FBT002
  549. ensure_exists: bool = False, # noqa: FBT001, FBT002
  550. ) -> Path:
  551. """:param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
  552. :param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
  553. :param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
  554. :param opinion: See `opinion <platformdirs.api.PlatformDirsABC.opinion>`.
  555. :param ensure_exists: See `ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.
  556. :returns: log path shared by users
  557. """
  558. return PlatformDirs(
  559. appname=appname,
  560. appauthor=appauthor,
  561. version=version,
  562. opinion=opinion,
  563. ensure_exists=ensure_exists,
  564. ).site_log_path
  565. def user_documents_path() -> Path:
  566. """:returns: documents path tied to the user"""
  567. return PlatformDirs().user_documents_path
  568. def user_downloads_path() -> Path:
  569. """:returns: downloads path tied to the user"""
  570. return PlatformDirs().user_downloads_path
  571. def user_pictures_path() -> Path:
  572. """:returns: pictures path tied to the user"""
  573. return PlatformDirs().user_pictures_path
  574. def user_videos_path() -> Path:
  575. """:returns: videos path tied to the user"""
  576. return PlatformDirs().user_videos_path
  577. def user_music_path() -> Path:
  578. """:returns: music path tied to the user"""
  579. return PlatformDirs().user_music_path
  580. def user_desktop_path() -> Path:
  581. """:returns: desktop path tied to the user"""
  582. return PlatformDirs().user_desktop_path
  583. def user_bin_path() -> Path:
  584. """:returns: bin path tied to the user"""
  585. return PlatformDirs().user_bin_path
  586. def site_bin_path() -> Path:
  587. """:returns: bin path shared by users"""
  588. return PlatformDirs().site_bin_path
  589. def user_applications_path() -> Path:
  590. """:returns: applications path tied to the user"""
  591. return PlatformDirs().user_applications_path
  592. def site_applications_path(
  593. multipath: bool = False, # noqa: FBT001, FBT002
  594. ensure_exists: bool = False, # noqa: FBT001, FBT002
  595. ) -> Path:
  596. """:param multipath: See `multipath <platformdirs.api.PlatformDirsABC.multipath>`.
  597. :param ensure_exists: See `ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.
  598. :returns: applications path shared by users
  599. """
  600. return PlatformDirs(
  601. multipath=multipath,
  602. ensure_exists=ensure_exists,
  603. ).site_applications_path
  604. def user_runtime_path( # noqa: PLR0913, PLR0917
  605. appname: str | None = None,
  606. appauthor: str | Literal[False] | None = None,
  607. version: str | None = None,
  608. opinion: bool = True, # noqa: FBT001, FBT002
  609. ensure_exists: bool = False, # noqa: FBT001, FBT002
  610. use_site_for_root: bool = False, # noqa: FBT001, FBT002
  611. ) -> Path:
  612. """:param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
  613. :param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
  614. :param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
  615. :param opinion: See `opinion <platformdirs.api.PlatformDirsABC.opinion>`.
  616. :param ensure_exists: See `ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.
  617. :param use_site_for_root: See `use_site_for_root <platformdirs.api.PlatformDirsABC.use_site_for_root>`.
  618. :returns: runtime path tied to the user
  619. """
  620. return PlatformDirs(
  621. appname=appname,
  622. appauthor=appauthor,
  623. version=version,
  624. opinion=opinion,
  625. ensure_exists=ensure_exists,
  626. use_site_for_root=use_site_for_root,
  627. ).user_runtime_path
  628. def site_runtime_path(
  629. appname: str | None = None,
  630. appauthor: str | Literal[False] | None = None,
  631. version: str | None = None,
  632. opinion: bool = True, # noqa: FBT001, FBT002
  633. ensure_exists: bool = False, # noqa: FBT001, FBT002
  634. ) -> Path:
  635. """:param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
  636. :param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
  637. :param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
  638. :param opinion: See `opinion <platformdirs.api.PlatformDirsABC.opinion>`.
  639. :param ensure_exists: See `ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.
  640. :returns: runtime path shared by users
  641. """
  642. return PlatformDirs(
  643. appname=appname,
  644. appauthor=appauthor,
  645. version=version,
  646. opinion=opinion,
  647. ensure_exists=ensure_exists,
  648. ).site_runtime_path
  649. __all__ = [
  650. "AppDirs",
  651. "PlatformDirs",
  652. "PlatformDirsABC",
  653. "__version__",
  654. "__version_info__",
  655. "site_applications_dir",
  656. "site_applications_path",
  657. "site_bin_dir",
  658. "site_bin_path",
  659. "site_cache_dir",
  660. "site_cache_path",
  661. "site_config_dir",
  662. "site_config_path",
  663. "site_data_dir",
  664. "site_data_path",
  665. "site_log_dir",
  666. "site_log_path",
  667. "site_runtime_dir",
  668. "site_runtime_path",
  669. "site_state_dir",
  670. "site_state_path",
  671. "user_applications_dir",
  672. "user_applications_path",
  673. "user_bin_dir",
  674. "user_bin_path",
  675. "user_cache_dir",
  676. "user_cache_path",
  677. "user_config_dir",
  678. "user_config_path",
  679. "user_data_dir",
  680. "user_data_path",
  681. "user_desktop_dir",
  682. "user_desktop_path",
  683. "user_documents_dir",
  684. "user_documents_path",
  685. "user_downloads_dir",
  686. "user_downloads_path",
  687. "user_log_dir",
  688. "user_log_path",
  689. "user_music_dir",
  690. "user_music_path",
  691. "user_pictures_dir",
  692. "user_pictures_path",
  693. "user_runtime_dir",
  694. "user_runtime_path",
  695. "user_state_dir",
  696. "user_state_path",
  697. "user_videos_dir",
  698. "user_videos_path",
  699. ]