Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/platformdirs/__init__.py: 54%
91 statements
« prev ^ index » next coverage.py v7.3.3, created at 2023-12-15 06:13 +0000
« prev ^ index » next coverage.py v7.3.3, created at 2023-12-15 06:13 +0000
1"""
2Utilities for determining application-specific dirs. See <https://github.com/platformdirs/platformdirs> for details and
3usage.
4"""
5from __future__ import annotations
7import os
8import sys
9from typing import TYPE_CHECKING
11from .api import PlatformDirsABC
12from .version import __version__
13from .version import __version_tuple__ as __version_info__
15if TYPE_CHECKING:
16 from pathlib import Path
17 from typing import Literal
20def _set_platform_dir_class() -> type[PlatformDirsABC]:
21 if sys.platform == "win32":
22 from platformdirs.windows import Windows as Result
23 elif sys.platform == "darwin":
24 from platformdirs.macos import MacOS as Result
25 else:
26 from platformdirs.unix import Unix as Result
28 if os.getenv("ANDROID_DATA") == "/data" and os.getenv("ANDROID_ROOT") == "/system":
29 if os.getenv("SHELL") or os.getenv("PREFIX"):
30 return Result
32 from platformdirs.android import _android_folder
34 if _android_folder() is not None:
35 from platformdirs.android import Android
37 return Android # return to avoid redefinition of result
39 return Result
42PlatformDirs = _set_platform_dir_class() #: Currently active platform
43AppDirs = PlatformDirs #: Backwards compatibility with appdirs
46def user_data_dir(
47 appname: str | None = None,
48 appauthor: str | None | Literal[False] = None,
49 version: str | None = None,
50 roaming: bool = False, # noqa: FBT001, FBT002
51 ensure_exists: bool = False, # noqa: FBT001, FBT002
52) -> str:
53 """
54 :param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
55 :param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
56 :param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
57 :param roaming: See `roaming <platformdirs.api.PlatformDirsABC.roaming>`.
58 :param ensure_exists: See `ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.
59 :returns: data directory tied to the user
60 """
61 return PlatformDirs(
62 appname=appname,
63 appauthor=appauthor,
64 version=version,
65 roaming=roaming,
66 ensure_exists=ensure_exists,
67 ).user_data_dir
70def site_data_dir(
71 appname: str | None = None,
72 appauthor: str | None | Literal[False] = None,
73 version: str | None = None,
74 multipath: bool = False, # noqa: FBT001, FBT002
75 ensure_exists: bool = False, # noqa: FBT001, FBT002
76) -> str:
77 """
78 :param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
79 :param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
80 :param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
81 :param multipath: See `roaming <platformdirs.api.PlatformDirsABC.multipath>`.
82 :param ensure_exists: See `ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.
83 :returns: data directory shared by users
84 """
85 return PlatformDirs(
86 appname=appname,
87 appauthor=appauthor,
88 version=version,
89 multipath=multipath,
90 ensure_exists=ensure_exists,
91 ).site_data_dir
94def user_config_dir(
95 appname: str | None = None,
96 appauthor: str | None | Literal[False] = None,
97 version: str | None = None,
98 roaming: bool = False, # noqa: FBT001, FBT002
99 ensure_exists: bool = False, # noqa: FBT001, FBT002
100) -> str:
101 """
102 :param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
103 :param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
104 :param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
105 :param roaming: See `roaming <platformdirs.api.PlatformDirsABC.roaming>`.
106 :param ensure_exists: See `ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.
107 :returns: config directory tied to the user
108 """
109 return PlatformDirs(
110 appname=appname,
111 appauthor=appauthor,
112 version=version,
113 roaming=roaming,
114 ensure_exists=ensure_exists,
115 ).user_config_dir
118def site_config_dir(
119 appname: str | None = None,
120 appauthor: str | None | Literal[False] = None,
121 version: str | None = None,
122 multipath: bool = False, # noqa: FBT001, FBT002
123 ensure_exists: bool = False, # noqa: FBT001, FBT002
124) -> str:
125 """
126 :param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
127 :param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
128 :param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
129 :param multipath: See `roaming <platformdirs.api.PlatformDirsABC.multipath>`.
130 :param ensure_exists: See `ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.
131 :returns: config directory shared by the users
132 """
133 return PlatformDirs(
134 appname=appname,
135 appauthor=appauthor,
136 version=version,
137 multipath=multipath,
138 ensure_exists=ensure_exists,
139 ).site_config_dir
142def user_cache_dir(
143 appname: str | None = None,
144 appauthor: str | None | Literal[False] = None,
145 version: str | None = None,
146 opinion: bool = True, # noqa: FBT001, FBT002
147 ensure_exists: bool = False, # noqa: FBT001, FBT002
148) -> str:
149 """
150 :param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
151 :param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
152 :param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
153 :param opinion: See `roaming <platformdirs.api.PlatformDirsABC.opinion>`.
154 :param ensure_exists: See `ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.
155 :returns: cache directory tied to the user
156 """
157 return PlatformDirs(
158 appname=appname,
159 appauthor=appauthor,
160 version=version,
161 opinion=opinion,
162 ensure_exists=ensure_exists,
163 ).user_cache_dir
166def site_cache_dir(
167 appname: str | None = None,
168 appauthor: str | None | Literal[False] = None,
169 version: str | None = None,
170 opinion: bool = True, # noqa: FBT001, FBT002
171 ensure_exists: bool = False, # noqa: FBT001, FBT002
172) -> str:
173 """
174 :param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
175 :param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
176 :param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
177 :param opinion: See `opinion <platformdirs.api.PlatformDirsABC.opinion>`.
178 :param ensure_exists: See `ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.
179 :returns: cache directory tied to the user
180 """
181 return PlatformDirs(
182 appname=appname,
183 appauthor=appauthor,
184 version=version,
185 opinion=opinion,
186 ensure_exists=ensure_exists,
187 ).site_cache_dir
190def user_state_dir(
191 appname: str | None = None,
192 appauthor: str | None | Literal[False] = None,
193 version: str | None = None,
194 roaming: bool = False, # noqa: FBT001, FBT002
195 ensure_exists: bool = False, # noqa: FBT001, FBT002
196) -> str:
197 """
198 :param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
199 :param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
200 :param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
201 :param roaming: See `roaming <platformdirs.api.PlatformDirsABC.roaming>`.
202 :param ensure_exists: See `ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.
203 :returns: state directory tied to the user
204 """
205 return PlatformDirs(
206 appname=appname,
207 appauthor=appauthor,
208 version=version,
209 roaming=roaming,
210 ensure_exists=ensure_exists,
211 ).user_state_dir
214def user_log_dir(
215 appname: str | None = None,
216 appauthor: str | None | Literal[False] = None,
217 version: str | None = None,
218 opinion: bool = True, # noqa: FBT001, FBT002
219 ensure_exists: bool = False, # noqa: FBT001, FBT002
220) -> str:
221 """
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 `roaming <platformdirs.api.PlatformDirsABC.opinion>`.
226 :param ensure_exists: See `ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.
227 :returns: log directory tied to the user
228 """
229 return PlatformDirs(
230 appname=appname,
231 appauthor=appauthor,
232 version=version,
233 opinion=opinion,
234 ensure_exists=ensure_exists,
235 ).user_log_dir
238def user_documents_dir() -> str:
239 """:returns: documents directory tied to the user"""
240 return PlatformDirs().user_documents_dir
243def user_downloads_dir() -> str:
244 """:returns: downloads directory tied to the user"""
245 return PlatformDirs().user_downloads_dir
248def user_pictures_dir() -> str:
249 """:returns: pictures directory tied to the user"""
250 return PlatformDirs().user_pictures_dir
253def user_videos_dir() -> str:
254 """:returns: videos directory tied to the user"""
255 return PlatformDirs().user_videos_dir
258def user_music_dir() -> str:
259 """:returns: music directory tied to the user"""
260 return PlatformDirs().user_music_dir
263def user_desktop_dir() -> str:
264 """:returns: desktop directory tied to the user"""
265 return PlatformDirs().user_desktop_dir
268def user_runtime_dir(
269 appname: str | None = None,
270 appauthor: str | None | Literal[False] = None,
271 version: str | None = None,
272 opinion: bool = True, # noqa: FBT001, FBT002
273 ensure_exists: bool = False, # noqa: FBT001, FBT002
274) -> str:
275 """
276 :param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
277 :param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
278 :param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
279 :param opinion: See `opinion <platformdirs.api.PlatformDirsABC.opinion>`.
280 :param ensure_exists: See `ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.
281 :returns: runtime directory tied to the user
282 """
283 return PlatformDirs(
284 appname=appname,
285 appauthor=appauthor,
286 version=version,
287 opinion=opinion,
288 ensure_exists=ensure_exists,
289 ).user_runtime_dir
292def site_runtime_dir(
293 appname: str | None = None,
294 appauthor: str | None | Literal[False] = None,
295 version: str | None = None,
296 opinion: bool = True, # noqa: FBT001, FBT002
297 ensure_exists: bool = False, # noqa: FBT001, FBT002
298) -> str:
299 """
300 :param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
301 :param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
302 :param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
303 :param opinion: See `opinion <platformdirs.api.PlatformDirsABC.opinion>`.
304 :param ensure_exists: See `ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.
305 :returns: runtime directory shared by users
306 """
307 return PlatformDirs(
308 appname=appname,
309 appauthor=appauthor,
310 version=version,
311 opinion=opinion,
312 ensure_exists=ensure_exists,
313 ).site_runtime_dir
316def user_data_path(
317 appname: str | None = None,
318 appauthor: str | None | Literal[False] = None,
319 version: str | None = None,
320 roaming: bool = False, # noqa: FBT001, FBT002
321 ensure_exists: bool = False, # noqa: FBT001, FBT002
322) -> Path:
323 """
324 :param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
325 :param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
326 :param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
327 :param roaming: See `roaming <platformdirs.api.PlatformDirsABC.roaming>`.
328 :param ensure_exists: See `ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.
329 :returns: data path tied to the user
330 """
331 return PlatformDirs(
332 appname=appname,
333 appauthor=appauthor,
334 version=version,
335 roaming=roaming,
336 ensure_exists=ensure_exists,
337 ).user_data_path
340def site_data_path(
341 appname: str | None = None,
342 appauthor: str | None | Literal[False] = None,
343 version: str | None = None,
344 multipath: bool = False, # noqa: FBT001, FBT002
345 ensure_exists: bool = False, # noqa: FBT001, FBT002
346) -> Path:
347 """
348 :param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
349 :param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
350 :param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
351 :param multipath: See `multipath <platformdirs.api.PlatformDirsABC.multipath>`.
352 :param ensure_exists: See `ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.
353 :returns: data path shared by users
354 """
355 return PlatformDirs(
356 appname=appname,
357 appauthor=appauthor,
358 version=version,
359 multipath=multipath,
360 ensure_exists=ensure_exists,
361 ).site_data_path
364def user_config_path(
365 appname: str | None = None,
366 appauthor: str | None | Literal[False] = None,
367 version: str | None = None,
368 roaming: bool = False, # noqa: FBT001, FBT002
369 ensure_exists: bool = False, # noqa: FBT001, FBT002
370) -> Path:
371 """
372 :param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
373 :param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
374 :param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
375 :param roaming: See `roaming <platformdirs.api.PlatformDirsABC.roaming>`.
376 :param ensure_exists: See `ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.
377 :returns: config path tied to the user
378 """
379 return PlatformDirs(
380 appname=appname,
381 appauthor=appauthor,
382 version=version,
383 roaming=roaming,
384 ensure_exists=ensure_exists,
385 ).user_config_path
388def site_config_path(
389 appname: str | None = None,
390 appauthor: str | None | Literal[False] = None,
391 version: str | None = None,
392 multipath: bool = False, # noqa: FBT001, FBT002
393 ensure_exists: bool = False, # noqa: FBT001, FBT002
394) -> Path:
395 """
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 multipath: See `roaming <platformdirs.api.PlatformDirsABC.multipath>`.
400 :param ensure_exists: See `ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.
401 :returns: config path shared by the users
402 """
403 return PlatformDirs(
404 appname=appname,
405 appauthor=appauthor,
406 version=version,
407 multipath=multipath,
408 ensure_exists=ensure_exists,
409 ).site_config_path
412def site_cache_path(
413 appname: str | None = None,
414 appauthor: str | None | Literal[False] = None,
415 version: str | None = None,
416 opinion: bool = True, # noqa: FBT001, FBT002
417 ensure_exists: bool = False, # noqa: FBT001, FBT002
418) -> Path:
419 """
420 :param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
421 :param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
422 :param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
423 :param opinion: See `opinion <platformdirs.api.PlatformDirsABC.opinion>`.
424 :param ensure_exists: See `ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.
425 :returns: cache directory tied to the user
426 """
427 return PlatformDirs(
428 appname=appname,
429 appauthor=appauthor,
430 version=version,
431 opinion=opinion,
432 ensure_exists=ensure_exists,
433 ).site_cache_path
436def user_cache_path(
437 appname: str | None = None,
438 appauthor: str | None | Literal[False] = None,
439 version: str | None = None,
440 opinion: bool = True, # noqa: FBT001, FBT002
441 ensure_exists: bool = False, # noqa: FBT001, FBT002
442) -> Path:
443 """
444 :param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
445 :param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
446 :param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
447 :param opinion: See `roaming <platformdirs.api.PlatformDirsABC.opinion>`.
448 :param ensure_exists: See `ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.
449 :returns: cache path tied to the user
450 """
451 return PlatformDirs(
452 appname=appname,
453 appauthor=appauthor,
454 version=version,
455 opinion=opinion,
456 ensure_exists=ensure_exists,
457 ).user_cache_path
460def user_state_path(
461 appname: str | None = None,
462 appauthor: str | None | Literal[False] = None,
463 version: str | None = None,
464 roaming: bool = False, # noqa: FBT001, FBT002
465 ensure_exists: bool = False, # noqa: FBT001, FBT002
466) -> Path:
467 """
468 :param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
469 :param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
470 :param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
471 :param roaming: See `roaming <platformdirs.api.PlatformDirsABC.roaming>`.
472 :param ensure_exists: See `ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.
473 :returns: state path tied to the user
474 """
475 return PlatformDirs(
476 appname=appname,
477 appauthor=appauthor,
478 version=version,
479 roaming=roaming,
480 ensure_exists=ensure_exists,
481 ).user_state_path
484def user_log_path(
485 appname: str | None = None,
486 appauthor: str | None | Literal[False] = None,
487 version: str | None = None,
488 opinion: bool = True, # noqa: FBT001, FBT002
489 ensure_exists: bool = False, # noqa: FBT001, FBT002
490) -> Path:
491 """
492 :param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
493 :param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
494 :param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
495 :param opinion: See `roaming <platformdirs.api.PlatformDirsABC.opinion>`.
496 :param ensure_exists: See `ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.
497 :returns: log path tied to the user
498 """
499 return PlatformDirs(
500 appname=appname,
501 appauthor=appauthor,
502 version=version,
503 opinion=opinion,
504 ensure_exists=ensure_exists,
505 ).user_log_path
508def user_documents_path() -> Path:
509 """:returns: documents path tied to the user"""
510 return PlatformDirs().user_documents_path
513def user_downloads_path() -> Path:
514 """:returns: downloads path tied to the user"""
515 return PlatformDirs().user_downloads_path
518def user_pictures_path() -> Path:
519 """:returns: pictures path tied to the user"""
520 return PlatformDirs().user_pictures_path
523def user_videos_path() -> Path:
524 """:returns: videos path tied to the user"""
525 return PlatformDirs().user_videos_path
528def user_music_path() -> Path:
529 """:returns: music path tied to the user"""
530 return PlatformDirs().user_music_path
533def user_desktop_path() -> Path:
534 """:returns: desktop path tied to the user"""
535 return PlatformDirs().user_desktop_path
538def user_runtime_path(
539 appname: str | None = None,
540 appauthor: str | None | Literal[False] = None,
541 version: str | None = None,
542 opinion: bool = True, # noqa: FBT001, FBT002
543 ensure_exists: bool = False, # noqa: FBT001, FBT002
544) -> Path:
545 """
546 :param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
547 :param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
548 :param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
549 :param opinion: See `opinion <platformdirs.api.PlatformDirsABC.opinion>`.
550 :param ensure_exists: See `ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.
551 :returns: runtime path tied to the user
552 """
553 return PlatformDirs(
554 appname=appname,
555 appauthor=appauthor,
556 version=version,
557 opinion=opinion,
558 ensure_exists=ensure_exists,
559 ).user_runtime_path
562def site_runtime_path(
563 appname: str | None = None,
564 appauthor: str | None | Literal[False] = None,
565 version: str | None = None,
566 opinion: bool = True, # noqa: FBT001, FBT002
567 ensure_exists: bool = False, # noqa: FBT001, FBT002
568) -> Path:
569 """
570 :param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
571 :param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
572 :param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
573 :param opinion: See `opinion <platformdirs.api.PlatformDirsABC.opinion>`.
574 :param ensure_exists: See `ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.
575 :returns: runtime path shared by users
576 """
577 return PlatformDirs(
578 appname=appname,
579 appauthor=appauthor,
580 version=version,
581 opinion=opinion,
582 ensure_exists=ensure_exists,
583 ).site_runtime_path
586__all__ = [
587 "__version__",
588 "__version_info__",
589 "PlatformDirs",
590 "AppDirs",
591 "PlatformDirsABC",
592 "user_data_dir",
593 "user_config_dir",
594 "user_cache_dir",
595 "user_state_dir",
596 "user_log_dir",
597 "user_documents_dir",
598 "user_downloads_dir",
599 "user_pictures_dir",
600 "user_videos_dir",
601 "user_music_dir",
602 "user_desktop_dir",
603 "user_runtime_dir",
604 "site_data_dir",
605 "site_config_dir",
606 "site_cache_dir",
607 "site_runtime_dir",
608 "user_data_path",
609 "user_config_path",
610 "user_cache_path",
611 "user_state_path",
612 "user_log_path",
613 "user_documents_path",
614 "user_downloads_path",
615 "user_pictures_path",
616 "user_videos_path",
617 "user_music_path",
618 "user_desktop_path",
619 "user_runtime_path",
620 "site_data_path",
621 "site_config_path",
622 "site_cache_path",
623 "site_runtime_path",
624]