Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/platformdirs/__init__.py: 55%
76 statements
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-07 07:11 +0000
« prev ^ index » next coverage.py v7.2.7, created at 2023-06-07 07:11 +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 pathlib import Path
11if sys.version_info >= (3, 8): # pragma: no cover (py38+)
12 from typing import Literal
13else: # pragma: no cover (py38+)
14 from typing_extensions import Literal
16from .api import PlatformDirsABC
17from .version import __version__
18from .version import __version_tuple__ as __version_info__
21def _set_platform_dir_class() -> type[PlatformDirsABC]:
22 if sys.platform == "win32":
23 from platformdirs.windows import Windows as Result
24 elif sys.platform == "darwin":
25 from platformdirs.macos import MacOS as Result
26 else:
27 from platformdirs.unix import Unix as Result
29 if os.getenv("ANDROID_DATA") == "/data" and os.getenv("ANDROID_ROOT") == "/system":
30 if os.getenv("SHELL") or os.getenv("PREFIX"):
31 return Result
33 from platformdirs.android import _android_folder
35 if _android_folder() is not None:
36 from platformdirs.android import Android
38 return Android # return to avoid redefinition of result
40 return Result
43PlatformDirs = _set_platform_dir_class() #: Currently active platform
44AppDirs = PlatformDirs #: Backwards compatibility with appdirs
47def user_data_dir(
48 appname: str | None = None,
49 appauthor: str | None | Literal[False] = None,
50 version: str | None = None,
51 roaming: bool = False,
52 ensure_exists: bool = False,
53) -> str:
54 """
55 :param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
56 :param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
57 :param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
58 :param roaming: See `roaming <platformdirs.api.PlatformDirsABC.roaming>`.
59 :param ensure_exists: See `ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.
60 :returns: data directory tied to the user
61 """
62 return PlatformDirs(
63 appname=appname,
64 appauthor=appauthor,
65 version=version,
66 roaming=roaming,
67 ensure_exists=ensure_exists,
68 ).user_data_dir
71def site_data_dir(
72 appname: str | None = None,
73 appauthor: str | None | Literal[False] = None,
74 version: str | None = None,
75 multipath: bool = False,
76 ensure_exists: bool = False,
77) -> str:
78 """
79 :param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
80 :param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
81 :param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
82 :param multipath: See `roaming <platformdirs.api.PlatformDirsABC.multipath>`.
83 :param ensure_exists: See `ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.
84 :returns: data directory shared by users
85 """
86 return PlatformDirs(
87 appname=appname,
88 appauthor=appauthor,
89 version=version,
90 multipath=multipath,
91 ensure_exists=ensure_exists,
92 ).site_data_dir
95def user_config_dir(
96 appname: str | None = None,
97 appauthor: str | None | Literal[False] = None,
98 version: str | None = None,
99 roaming: bool = False,
100 ensure_exists: bool = False,
101) -> str:
102 """
103 :param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
104 :param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
105 :param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
106 :param roaming: See `roaming <platformdirs.api.PlatformDirsABC.roaming>`.
107 :param ensure_exists: See `ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.
108 :returns: config directory tied to the user
109 """
110 return PlatformDirs(
111 appname=appname,
112 appauthor=appauthor,
113 version=version,
114 roaming=roaming,
115 ensure_exists=ensure_exists,
116 ).user_config_dir
119def site_config_dir(
120 appname: str | None = None,
121 appauthor: str | None | Literal[False] = None,
122 version: str | None = None,
123 multipath: bool = False,
124 ensure_exists: bool = False,
125) -> str:
126 """
127 :param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
128 :param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
129 :param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
130 :param multipath: See `roaming <platformdirs.api.PlatformDirsABC.multipath>`.
131 :param ensure_exists: See `ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.
132 :returns: config directory shared by the users
133 """
134 return PlatformDirs(
135 appname=appname,
136 appauthor=appauthor,
137 version=version,
138 multipath=multipath,
139 ensure_exists=ensure_exists,
140 ).site_config_dir
143def user_cache_dir(
144 appname: str | None = None,
145 appauthor: str | None | Literal[False] = None,
146 version: str | None = None,
147 opinion: bool = True,
148 ensure_exists: bool = False,
149) -> str:
150 """
151 :param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
152 :param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
153 :param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
154 :param opinion: See `roaming <platformdirs.api.PlatformDirsABC.opinion>`.
155 :param ensure_exists: See `ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.
156 :returns: cache directory tied to the user
157 """
158 return PlatformDirs(
159 appname=appname,
160 appauthor=appauthor,
161 version=version,
162 opinion=opinion,
163 ensure_exists=ensure_exists,
164 ).user_cache_dir
167def site_cache_dir(
168 appname: str | None = None,
169 appauthor: str | None | Literal[False] = None,
170 version: str | None = None,
171 opinion: bool = True,
172 ensure_exists: bool = False,
173) -> str:
174 """
175 :param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
176 :param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
177 :param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
178 :param opinion: See `opinion <platformdirs.api.PlatformDirsABC.opinion>`.
179 :param ensure_exists: See `ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.
180 :returns: cache directory tied to the user
181 """
182 return PlatformDirs(
183 appname=appname,
184 appauthor=appauthor,
185 version=version,
186 opinion=opinion,
187 ensure_exists=ensure_exists,
188 ).site_cache_dir
191def user_state_dir(
192 appname: str | None = None,
193 appauthor: str | None | Literal[False] = None,
194 version: str | None = None,
195 roaming: bool = False,
196 ensure_exists: bool = False,
197) -> str:
198 """
199 :param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
200 :param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
201 :param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
202 :param roaming: See `roaming <platformdirs.api.PlatformDirsABC.roaming>`.
203 :param ensure_exists: See `ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.
204 :returns: state directory tied to the user
205 """
206 return PlatformDirs(
207 appname=appname,
208 appauthor=appauthor,
209 version=version,
210 roaming=roaming,
211 ensure_exists=ensure_exists,
212 ).user_state_dir
215def user_log_dir(
216 appname: str | None = None,
217 appauthor: str | None | Literal[False] = None,
218 version: str | None = None,
219 opinion: bool = True,
220 ensure_exists: bool = False,
221) -> str:
222 """
223 :param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
224 :param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
225 :param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
226 :param opinion: See `roaming <platformdirs.api.PlatformDirsABC.opinion>`.
227 :param ensure_exists: See `ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.
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 ).user_log_dir
239def user_documents_dir() -> str:
240 """
241 :returns: documents directory tied to the user
242 """
243 return PlatformDirs().user_documents_dir
246def user_pictures_dir() -> str:
247 """
248 :returns: pictures directory tied to the user
249 """
250 return PlatformDirs().user_pictures_dir
253def user_videos_dir() -> str:
254 """
255 :returns: videos directory tied to the user
256 """
257 return PlatformDirs().user_videos_dir
260def user_music_dir() -> str:
261 """
262 :returns: music directory tied to the user
263 """
264 return PlatformDirs().user_music_dir
267def user_runtime_dir(
268 appname: str | None = None,
269 appauthor: str | None | Literal[False] = None,
270 version: str | None = None,
271 opinion: bool = True,
272 ensure_exists: bool = False,
273) -> str:
274 """
275 :param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
276 :param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
277 :param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
278 :param opinion: See `opinion <platformdirs.api.PlatformDirsABC.opinion>`.
279 :param ensure_exists: See `ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.
280 :returns: runtime directory tied to the user
281 """
282 return PlatformDirs(
283 appname=appname,
284 appauthor=appauthor,
285 version=version,
286 opinion=opinion,
287 ensure_exists=ensure_exists,
288 ).user_runtime_dir
291def user_data_path(
292 appname: str | None = None,
293 appauthor: str | None | Literal[False] = None,
294 version: str | None = None,
295 roaming: bool = False,
296 ensure_exists: bool = False,
297) -> Path:
298 """
299 :param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
300 :param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
301 :param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
302 :param roaming: See `roaming <platformdirs.api.PlatformDirsABC.roaming>`.
303 :param ensure_exists: See `ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.
304 :returns: data path tied to the user
305 """
306 return PlatformDirs(
307 appname=appname,
308 appauthor=appauthor,
309 version=version,
310 roaming=roaming,
311 ensure_exists=ensure_exists,
312 ).user_data_path
315def site_data_path(
316 appname: str | None = None,
317 appauthor: str | None | Literal[False] = None,
318 version: str | None = None,
319 multipath: bool = False,
320 ensure_exists: bool = False,
321) -> Path:
322 """
323 :param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
324 :param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
325 :param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
326 :param multipath: See `multipath <platformdirs.api.PlatformDirsABC.multipath>`.
327 :param ensure_exists: See `ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.
328 :returns: data path shared by users
329 """
330 return PlatformDirs(
331 appname=appname,
332 appauthor=appauthor,
333 version=version,
334 multipath=multipath,
335 ensure_exists=ensure_exists,
336 ).site_data_path
339def user_config_path(
340 appname: str | None = None,
341 appauthor: str | None | Literal[False] = None,
342 version: str | None = None,
343 roaming: bool = False,
344 ensure_exists: bool = False,
345) -> Path:
346 """
347 :param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
348 :param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
349 :param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
350 :param roaming: See `roaming <platformdirs.api.PlatformDirsABC.roaming>`.
351 :param ensure_exists: See `ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.
352 :returns: config path tied to the user
353 """
354 return PlatformDirs(
355 appname=appname,
356 appauthor=appauthor,
357 version=version,
358 roaming=roaming,
359 ensure_exists=ensure_exists,
360 ).user_config_path
363def site_config_path(
364 appname: str | None = None,
365 appauthor: str | None | Literal[False] = None,
366 version: str | None = None,
367 multipath: bool = False,
368 ensure_exists: bool = False,
369) -> Path:
370 """
371 :param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
372 :param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
373 :param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
374 :param multipath: See `roaming <platformdirs.api.PlatformDirsABC.multipath>`.
375 :param ensure_exists: See `ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.
376 :returns: config path shared by the users
377 """
378 return PlatformDirs(
379 appname=appname,
380 appauthor=appauthor,
381 version=version,
382 multipath=multipath,
383 ensure_exists=ensure_exists,
384 ).site_config_path
387def site_cache_path(
388 appname: str | None = None,
389 appauthor: str | None | Literal[False] = None,
390 version: str | None = None,
391 opinion: bool = True,
392 ensure_exists: bool = False,
393) -> Path:
394 """
395 :param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
396 :param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
397 :param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
398 :param opinion: See `opinion <platformdirs.api.PlatformDirsABC.opinion>`.
399 :param ensure_exists: See `ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.
400 :returns: cache directory tied to the user
401 """
402 return PlatformDirs(
403 appname=appname,
404 appauthor=appauthor,
405 version=version,
406 opinion=opinion,
407 ensure_exists=ensure_exists,
408 ).site_cache_path
411def user_cache_path(
412 appname: str | None = None,
413 appauthor: str | None | Literal[False] = None,
414 version: str | None = None,
415 opinion: bool = True,
416 ensure_exists: bool = False,
417) -> Path:
418 """
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 opinion: See `roaming <platformdirs.api.PlatformDirsABC.opinion>`.
423 :param ensure_exists: See `ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.
424 :returns: cache path tied to the user
425 """
426 return PlatformDirs(
427 appname=appname,
428 appauthor=appauthor,
429 version=version,
430 opinion=opinion,
431 ensure_exists=ensure_exists,
432 ).user_cache_path
435def user_state_path(
436 appname: str | None = None,
437 appauthor: str | None | Literal[False] = None,
438 version: str | None = None,
439 roaming: bool = False,
440 ensure_exists: bool = False,
441) -> Path:
442 """
443 :param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
444 :param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
445 :param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
446 :param roaming: See `roaming <platformdirs.api.PlatformDirsABC.roaming>`.
447 :param ensure_exists: See `ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.
448 :returns: state path tied to the user
449 """
450 return PlatformDirs(
451 appname=appname,
452 appauthor=appauthor,
453 version=version,
454 roaming=roaming,
455 ensure_exists=ensure_exists,
456 ).user_state_path
459def user_log_path(
460 appname: str | None = None,
461 appauthor: str | None | Literal[False] = None,
462 version: str | None = None,
463 opinion: bool = True,
464 ensure_exists: bool = False,
465) -> Path:
466 """
467 :param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
468 :param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
469 :param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
470 :param opinion: See `roaming <platformdirs.api.PlatformDirsABC.opinion>`.
471 :param ensure_exists: See `ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.
472 :returns: log path tied to the user
473 """
474 return PlatformDirs(
475 appname=appname,
476 appauthor=appauthor,
477 version=version,
478 opinion=opinion,
479 ensure_exists=ensure_exists,
480 ).user_log_path
483def user_documents_path() -> Path:
484 """
485 :returns: documents path tied to the user
486 """
487 return PlatformDirs().user_documents_path
490def user_pictures_path() -> Path:
491 """
492 :returns: pictures path tied to the user
493 """
494 return PlatformDirs().user_pictures_path
497def user_videos_path() -> Path:
498 """
499 :returns: videos path tied to the user
500 """
501 return PlatformDirs().user_videos_path
504def user_music_path() -> Path:
505 """
506 :returns: music path tied to the user
507 """
508 return PlatformDirs().user_music_path
511def user_runtime_path(
512 appname: str | None = None,
513 appauthor: str | None | Literal[False] = None,
514 version: str | None = None,
515 opinion: bool = True,
516 ensure_exists: bool = False,
517) -> Path:
518 """
519 :param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
520 :param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
521 :param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
522 :param opinion: See `opinion <platformdirs.api.PlatformDirsABC.opinion>`.
523 :param ensure_exists: See `ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.
524 :returns: runtime path tied to the user
525 """
526 return PlatformDirs(
527 appname=appname,
528 appauthor=appauthor,
529 version=version,
530 opinion=opinion,
531 ensure_exists=ensure_exists,
532 ).user_runtime_path
535__all__ = [
536 "__version__",
537 "__version_info__",
538 "PlatformDirs",
539 "AppDirs",
540 "PlatformDirsABC",
541 "user_data_dir",
542 "user_config_dir",
543 "user_cache_dir",
544 "user_state_dir",
545 "user_log_dir",
546 "user_documents_dir",
547 "user_pictures_dir",
548 "user_videos_dir",
549 "user_music_dir",
550 "user_runtime_dir",
551 "site_data_dir",
552 "site_config_dir",
553 "site_cache_dir",
554 "user_data_path",
555 "user_config_path",
556 "user_cache_path",
557 "user_state_path",
558 "user_log_path",
559 "user_documents_path",
560 "user_pictures_path",
561 "user_videos_path",
562 "user_music_path",
563 "user_runtime_path",
564 "site_data_path",
565 "site_config_path",
566 "site_cache_path",
567]