Skip to content

Commit f756086

Browse files
committed
Upgrade platformdirs to 4.2.0
1 parent 4716a4e commit f756086

File tree

10 files changed

+277
-41
lines changed

10 files changed

+277
-41
lines changed

news/platformdirs.vendor.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Upgrade platformdirs to 4.2.0

src/pip/_vendor/platformdirs/__init__.py

Lines changed: 64 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Utilities for determining application-specific dirs. See <https://github.com/platformdirs/platformdirs> for details and
33
usage.
44
"""
5+
56
from __future__ import annotations
67

78
import os
@@ -14,11 +15,7 @@
1415

1516
if TYPE_CHECKING:
1617
from pathlib import Path
17-
18-
if sys.version_info >= (3, 8): # pragma: no cover (py38+)
19-
from typing import Literal
20-
else: # pragma: no cover (py38+)
21-
from pip._vendor.typing_extensions import Literal
18+
from typing import Literal
2219

2320

2421
def _set_platform_dir_class() -> type[PlatformDirsABC]:
@@ -264,6 +261,11 @@ def user_music_dir() -> str:
264261
return PlatformDirs().user_music_dir
265262

266263

264+
def user_desktop_dir() -> str:
265+
""":returns: desktop directory tied to the user"""
266+
return PlatformDirs().user_desktop_dir
267+
268+
267269
def user_runtime_dir(
268270
appname: str | None = None,
269271
appauthor: str | None | Literal[False] = None,
@@ -288,6 +290,30 @@ def user_runtime_dir(
288290
).user_runtime_dir
289291

290292

293+
def site_runtime_dir(
294+
appname: str | None = None,
295+
appauthor: str | None | Literal[False] = None,
296+
version: str | None = None,
297+
opinion: bool = True, # noqa: FBT001, FBT002
298+
ensure_exists: bool = False, # noqa: FBT001, FBT002
299+
) -> str:
300+
"""
301+
:param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
302+
:param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
303+
:param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
304+
:param opinion: See `opinion <platformdirs.api.PlatformDirsABC.opinion>`.
305+
:param ensure_exists: See `ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.
306+
:returns: runtime directory shared by users
307+
"""
308+
return PlatformDirs(
309+
appname=appname,
310+
appauthor=appauthor,
311+
version=version,
312+
opinion=opinion,
313+
ensure_exists=ensure_exists,
314+
).site_runtime_dir
315+
316+
291317
def user_data_path(
292318
appname: str | None = None,
293319
appauthor: str | None | Literal[False] = None,
@@ -505,6 +531,11 @@ def user_music_path() -> Path:
505531
return PlatformDirs().user_music_path
506532

507533

534+
def user_desktop_path() -> Path:
535+
""":returns: desktop path tied to the user"""
536+
return PlatformDirs().user_desktop_path
537+
538+
508539
def user_runtime_path(
509540
appname: str | None = None,
510541
appauthor: str | None | Literal[False] = None,
@@ -529,6 +560,30 @@ def user_runtime_path(
529560
).user_runtime_path
530561

531562

563+
def site_runtime_path(
564+
appname: str | None = None,
565+
appauthor: str | None | Literal[False] = None,
566+
version: str | None = None,
567+
opinion: bool = True, # noqa: FBT001, FBT002
568+
ensure_exists: bool = False, # noqa: FBT001, FBT002
569+
) -> Path:
570+
"""
571+
:param appname: See `appname <platformdirs.api.PlatformDirsABC.appname>`.
572+
:param appauthor: See `appauthor <platformdirs.api.PlatformDirsABC.appauthor>`.
573+
:param version: See `version <platformdirs.api.PlatformDirsABC.version>`.
574+
:param opinion: See `opinion <platformdirs.api.PlatformDirsABC.opinion>`.
575+
:param ensure_exists: See `ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.
576+
:returns: runtime path shared by users
577+
"""
578+
return PlatformDirs(
579+
appname=appname,
580+
appauthor=appauthor,
581+
version=version,
582+
opinion=opinion,
583+
ensure_exists=ensure_exists,
584+
).site_runtime_path
585+
586+
532587
__all__ = [
533588
"__version__",
534589
"__version_info__",
@@ -545,10 +600,12 @@ def user_runtime_path(
545600
"user_pictures_dir",
546601
"user_videos_dir",
547602
"user_music_dir",
603+
"user_desktop_dir",
548604
"user_runtime_dir",
549605
"site_data_dir",
550606
"site_config_dir",
551607
"site_cache_dir",
608+
"site_runtime_dir",
552609
"user_data_path",
553610
"user_config_path",
554611
"user_cache_path",
@@ -559,8 +616,10 @@ def user_runtime_path(
559616
"user_pictures_path",
560617
"user_videos_path",
561618
"user_music_path",
619+
"user_desktop_path",
562620
"user_runtime_path",
563621
"site_data_path",
564622
"site_config_path",
565623
"site_cache_path",
624+
"site_runtime_path",
566625
]

src/pip/_vendor/platformdirs/__main__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Main entry point."""
2+
23
from __future__ import annotations
34

45
from pip._vendor.platformdirs import PlatformDirs, __version__
@@ -18,6 +19,7 @@
1819
"site_data_dir",
1920
"site_config_dir",
2021
"site_cache_dir",
22+
"site_runtime_dir",
2123
)
2224

2325

src/pip/_vendor/platformdirs/android.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Android."""
2+
23
from __future__ import annotations
34

45
import os
@@ -92,6 +93,11 @@ def user_music_dir(self) -> str:
9293
""":return: music directory tied to the user e.g. ``/storage/emulated/0/Music``"""
9394
return _android_music_folder()
9495

96+
@property
97+
def user_desktop_dir(self) -> str:
98+
""":return: desktop directory tied to the user e.g. ``/storage/emulated/0/Desktop``"""
99+
return "/storage/emulated/0/Desktop"
100+
95101
@property
96102
def user_runtime_dir(self) -> str:
97103
"""
@@ -103,6 +109,11 @@ def user_runtime_dir(self) -> str:
103109
path = os.path.join(path, "tmp") # noqa: PTH118
104110
return path
105111

112+
@property
113+
def site_runtime_dir(self) -> str:
114+
""":return: runtime directory shared by users, same as `user_runtime_dir`"""
115+
return self.user_runtime_dir
116+
106117

107118
@lru_cache(maxsize=1)
108119
def _android_folder() -> str | None:

src/pip/_vendor/platformdirs/api.py

Lines changed: 64 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Base API."""
2+
23
from __future__ import annotations
34

45
import os
@@ -7,12 +8,7 @@
78
from typing import TYPE_CHECKING
89

910
if TYPE_CHECKING:
10-
import sys
11-
12-
if sys.version_info >= (3, 8): # pragma: no cover (py38+)
13-
from typing import Literal
14-
else: # pragma: no cover (py38+)
15-
from pip._vendor.typing_extensions import Literal
11+
from typing import Iterator, Literal
1612

1713

1814
class PlatformDirsABC(ABC):
@@ -58,8 +54,8 @@ def __init__( # noqa: PLR0913
5854
"""
5955
self.multipath = multipath
6056
"""
61-
An optional parameter only applicable to Unix/Linux which indicates that the entire list of data dirs should be
62-
returned. By default, the first item would only be returned.
57+
An optional parameter which indicates that the entire list of data dirs should be returned.
58+
By default, the first item would only be returned.
6359
"""
6460
self.opinion = opinion #: A flag to indicating to use opinionated values.
6561
self.ensure_exists = ensure_exists
@@ -147,11 +143,21 @@ def user_videos_dir(self) -> str:
147143
def user_music_dir(self) -> str:
148144
""":return: music directory tied to the user"""
149145

146+
@property
147+
@abstractmethod
148+
def user_desktop_dir(self) -> str:
149+
""":return: desktop directory tied to the user"""
150+
150151
@property
151152
@abstractmethod
152153
def user_runtime_dir(self) -> str:
153154
""":return: runtime directory tied to the user"""
154155

156+
@property
157+
@abstractmethod
158+
def site_runtime_dir(self) -> str:
159+
""":return: runtime directory shared by users"""
160+
155161
@property
156162
def user_data_path(self) -> Path:
157163
""":return: data path tied to the user"""
@@ -217,7 +223,57 @@ def user_music_path(self) -> Path:
217223
""":return: music path tied to the user"""
218224
return Path(self.user_music_dir)
219225

226+
@property
227+
def user_desktop_path(self) -> Path:
228+
""":return: desktop path tied to the user"""
229+
return Path(self.user_desktop_dir)
230+
220231
@property
221232
def user_runtime_path(self) -> Path:
222233
""":return: runtime path tied to the user"""
223234
return Path(self.user_runtime_dir)
235+
236+
@property
237+
def site_runtime_path(self) -> Path:
238+
""":return: runtime path shared by users"""
239+
return Path(self.site_runtime_dir)
240+
241+
def iter_config_dirs(self) -> Iterator[str]:
242+
""":yield: all user and site configuration directories."""
243+
yield self.user_config_dir
244+
yield self.site_config_dir
245+
246+
def iter_data_dirs(self) -> Iterator[str]:
247+
""":yield: all user and site data directories."""
248+
yield self.user_data_dir
249+
yield self.site_data_dir
250+
251+
def iter_cache_dirs(self) -> Iterator[str]:
252+
""":yield: all user and site cache directories."""
253+
yield self.user_cache_dir
254+
yield self.site_cache_dir
255+
256+
def iter_runtime_dirs(self) -> Iterator[str]:
257+
""":yield: all user and site runtime directories."""
258+
yield self.user_runtime_dir
259+
yield self.site_runtime_dir
260+
261+
def iter_config_paths(self) -> Iterator[Path]:
262+
""":yield: all user and site configuration paths."""
263+
for path in self.iter_config_dirs():
264+
yield Path(path)
265+
266+
def iter_data_paths(self) -> Iterator[Path]:
267+
""":yield: all user and site data paths."""
268+
for path in self.iter_data_dirs():
269+
yield Path(path)
270+
271+
def iter_cache_paths(self) -> Iterator[Path]:
272+
""":yield: all user and site cache paths."""
273+
for path in self.iter_cache_dirs():
274+
yield Path(path)
275+
276+
def iter_runtime_paths(self) -> Iterator[Path]:
277+
""":yield: all user and site runtime paths."""
278+
for path in self.iter_runtime_dirs():
279+
yield Path(path)

src/pip/_vendor/platformdirs/macos.py

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
"""macOS."""
2+
23
from __future__ import annotations
34

45
import os.path
6+
import sys
57

68
from .api import PlatformDirsABC
79

@@ -22,8 +24,20 @@ def user_data_dir(self) -> str:
2224

2325
@property
2426
def site_data_dir(self) -> str:
25-
""":return: data directory shared by users, e.g. ``/Library/Application Support/$appname/$version``"""
26-
return self._append_app_name_and_version("/Library/Application Support")
27+
"""
28+
:return: data directory shared by users, e.g. ``/Library/Application Support/$appname/$version``.
29+
If we're using a Python binary managed by `Homebrew <https://brew.sh>`_, the directory
30+
will be under the Homebrew prefix, e.g. ``/opt/homebrew/share/$appname/$version``.
31+
If `multipath <platformdirs.api.PlatformDirsABC.multipath>` is enabled and we're in Homebrew,
32+
the response is a multi-path string separated by ":", e.g.
33+
``/opt/homebrew/share/$appname/$version:/Library/Application Support/$appname/$version``
34+
"""
35+
is_homebrew = sys.prefix.startswith("/opt/homebrew")
36+
path_list = [self._append_app_name_and_version("/opt/homebrew/share")] if is_homebrew else []
37+
path_list.append(self._append_app_name_and_version("/Library/Application Support"))
38+
if self.multipath:
39+
return os.pathsep.join(path_list)
40+
return path_list[0]
2741

2842
@property
2943
def user_config_dir(self) -> str:
@@ -42,8 +56,20 @@ def user_cache_dir(self) -> str:
4256

4357
@property
4458
def site_cache_dir(self) -> str:
45-
""":return: cache directory shared by users, e.g. ``/Library/Caches/$appname/$version``"""
46-
return self._append_app_name_and_version("/Library/Caches")
59+
"""
60+
:return: cache directory shared by users, e.g. ``/Library/Caches/$appname/$version``.
61+
If we're using a Python binary managed by `Homebrew <https://brew.sh>`_, the directory
62+
will be under the Homebrew prefix, e.g. ``/opt/homebrew/var/cache/$appname/$version``.
63+
If `multipath <platformdirs.api.PlatformDirsABC.multipath>` is enabled and we're in Homebrew,
64+
the response is a multi-path string separated by ":", e.g.
65+
``/opt/homebrew/var/cache/$appname/$version:/Library/Caches/$appname/$version``
66+
"""
67+
is_homebrew = sys.prefix.startswith("/opt/homebrew")
68+
path_list = [self._append_app_name_and_version("/opt/homebrew/var/cache")] if is_homebrew else []
69+
path_list.append(self._append_app_name_and_version("/Library/Caches"))
70+
if self.multipath:
71+
return os.pathsep.join(path_list)
72+
return path_list[0]
4773

4874
@property
4975
def user_state_dir(self) -> str:
@@ -80,11 +106,21 @@ def user_music_dir(self) -> str:
80106
""":return: music directory tied to the user, e.g. ``~/Music``"""
81107
return os.path.expanduser("~/Music") # noqa: PTH111
82108

109+
@property
110+
def user_desktop_dir(self) -> str:
111+
""":return: desktop directory tied to the user, e.g. ``~/Desktop``"""
112+
return os.path.expanduser("~/Desktop") # noqa: PTH111
113+
83114
@property
84115
def user_runtime_dir(self) -> str:
85116
""":return: runtime directory tied to the user, e.g. ``~/Library/Caches/TemporaryItems/$appname/$version``"""
86117
return self._append_app_name_and_version(os.path.expanduser("~/Library/Caches/TemporaryItems")) # noqa: PTH111
87118

119+
@property
120+
def site_runtime_dir(self) -> str:
121+
""":return: runtime directory shared by users, same as `user_runtime_dir`"""
122+
return self.user_runtime_dir
123+
88124

89125
__all__ = [
90126
"MacOS",

0 commit comments

Comments
 (0)