Skip to content

Commit 2b9effb

Browse files
committed
Upgrade platformdirs to 3.2.0
1 parent e0b89b8 commit 2b9effb

File tree

10 files changed

+277
-39
lines changed

10 files changed

+277
-39
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 3.2.0

src/pip/_vendor/platformdirs/__init__.py

Lines changed: 200 additions & 23 deletions
Large diffs are not rendered by default.

src/pip/_vendor/platformdirs/__main__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"user_runtime_dir",
1313
"site_data_dir",
1414
"site_config_dir",
15+
"site_cache_dir",
1516
)
1617

1718

src/pip/_vendor/platformdirs/android.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
class Android(PlatformDirsABC):
1313
"""
1414
Follows the guidance `from here <https://android.stackexchange.com/a/216132>`_. Makes use of the
15-
`appname <platformdirs.api.PlatformDirsABC.appname>` and
16-
`version <platformdirs.api.PlatformDirsABC.version>`.
15+
`appname <platformdirs.api.PlatformDirsABC.appname>`,
16+
`version <platformdirs.api.PlatformDirsABC.version>`,
17+
`ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.
1718
"""
1819

1920
@property
@@ -43,6 +44,11 @@ def user_cache_dir(self) -> str:
4344
""":return: cache directory tied to the user, e.g. e.g. ``/data/user/<userid>/<packagename>/cache/<AppName>``"""
4445
return self._append_app_name_and_version(cast(str, _android_folder()), "cache")
4546

47+
@property
48+
def site_cache_dir(self) -> str:
49+
""":return: cache directory shared by users, same as `user_cache_dir`"""
50+
return self.user_cache_dir
51+
4652
@property
4753
def user_state_dir(self) -> str:
4854
""":return: state directory tied to the user, same as `user_data_dir`"""

src/pip/_vendor/platformdirs/api.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ def __init__(
2222
roaming: bool = False,
2323
multipath: bool = False,
2424
opinion: bool = True,
25+
ensure_exists: bool = False,
2526
):
2627
"""
2728
Create a new platform directory.
@@ -32,6 +33,7 @@ def __init__(
3233
:param roaming: See `roaming`.
3334
:param multipath: See `multipath`.
3435
:param opinion: See `opinion`.
36+
:param ensure_exists: See `ensure_exists`.
3537
"""
3638
self.appname = appname #: The name of application.
3739
self.appauthor = appauthor
@@ -56,14 +58,25 @@ def __init__(
5658
returned. By default, the first item would only be returned.
5759
"""
5860
self.opinion = opinion #: A flag to indicating to use opinionated values.
61+
self.ensure_exists = ensure_exists
62+
"""
63+
Optionally create the directory (and any missing parents) upon access if it does not exist.
64+
By default, no directories are created.
65+
"""
5966

6067
def _append_app_name_and_version(self, *base: str) -> str:
6168
params = list(base[1:])
6269
if self.appname:
6370
params.append(self.appname)
6471
if self.version:
6572
params.append(self.version)
66-
return os.path.join(base[0], *params)
73+
path = os.path.join(base[0], *params)
74+
self._optionally_create_directory(path)
75+
return path
76+
77+
def _optionally_create_directory(self, path: str) -> None:
78+
if self.ensure_exists:
79+
Path(path).mkdir(parents=True, exist_ok=True)
6780

6881
@property
6982
@abstractmethod
@@ -90,6 +103,11 @@ def site_config_dir(self) -> str:
90103
def user_cache_dir(self) -> str:
91104
""":return: cache directory tied to the user"""
92105

106+
@property
107+
@abstractmethod
108+
def site_cache_dir(self) -> str:
109+
""":return: cache directory shared by users"""
110+
93111
@property
94112
@abstractmethod
95113
def user_state_dir(self) -> str:
@@ -135,6 +153,11 @@ def user_cache_path(self) -> Path:
135153
""":return: cache path tied to the user"""
136154
return Path(self.user_cache_dir)
137155

156+
@property
157+
def site_cache_path(self) -> Path:
158+
""":return: cache path shared by users"""
159+
return Path(self.site_cache_dir)
160+
138161
@property
139162
def user_state_path(self) -> Path:
140163
""":return: state path tied to the user"""

src/pip/_vendor/platformdirs/macos.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@ class MacOS(PlatformDirsABC):
99
"""
1010
Platform directories for the macOS operating system. Follows the guidance from `Apple documentation
1111
<https://developer.apple.com/library/archive/documentation/FileManagement/Conceptual/FileSystemProgrammingGuide/MacOSXDirectories/MacOSXDirectories.html>`_.
12-
Makes use of the `appname <platformdirs.api.PlatformDirsABC.appname>` and
13-
`version <platformdirs.api.PlatformDirsABC.version>`.
12+
Makes use of the `appname <platformdirs.api.PlatformDirsABC.appname>`,
13+
`version <platformdirs.api.PlatformDirsABC.version>`,
14+
`ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.
1415
"""
1516

1617
@property
1718
def user_data_dir(self) -> str:
1819
""":return: data directory tied to the user, e.g. ``~/Library/Application Support/$appname/$version``"""
19-
return self._append_app_name_and_version(os.path.expanduser("~/Library/Application Support/"))
20+
return self._append_app_name_and_version(os.path.expanduser("~/Library/Application Support"))
2021

2122
@property
2223
def site_data_dir(self) -> str:
@@ -25,19 +26,24 @@ def site_data_dir(self) -> str:
2526

2627
@property
2728
def user_config_dir(self) -> str:
28-
""":return: config directory tied to the user, e.g. ``~/Library/Preferences/$appname/$version``"""
29-
return self._append_app_name_and_version(os.path.expanduser("~/Library/Preferences/"))
29+
""":return: config directory tied to the user, same as `user_data_dir`"""
30+
return self.user_data_dir
3031

3132
@property
3233
def site_config_dir(self) -> str:
33-
""":return: config directory shared by the users, e.g. ``/Library/Preferences/$appname``"""
34-
return self._append_app_name_and_version("/Library/Preferences")
34+
""":return: config directory shared by the users, same as `site_data_dir`"""
35+
return self.site_data_dir
3536

3637
@property
3738
def user_cache_dir(self) -> str:
3839
""":return: cache directory tied to the user, e.g. ``~/Library/Caches/$appname/$version``"""
3940
return self._append_app_name_and_version(os.path.expanduser("~/Library/Caches"))
4041

42+
@property
43+
def site_cache_dir(self) -> str:
44+
""":return: cache directory shared by users, e.g. ``/Library/Caches/$appname/$version``"""
45+
return self._append_app_name_and_version("/Library/Caches")
46+
4147
@property
4248
def user_state_dir(self) -> str:
4349
""":return: state directory tied to the user, same as `user_data_dir`"""

src/pip/_vendor/platformdirs/unix.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ class Unix(PlatformDirsABC):
2424
`appname <platformdirs.api.PlatformDirsABC.appname>`,
2525
`version <platformdirs.api.PlatformDirsABC.version>`,
2626
`multipath <platformdirs.api.PlatformDirsABC.multipath>`,
27-
`opinion <platformdirs.api.PlatformDirsABC.opinion>`.
27+
`opinion <platformdirs.api.PlatformDirsABC.opinion>`,
28+
`ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.
2829
"""
2930

3031
@property
@@ -93,6 +94,13 @@ def user_cache_dir(self) -> str:
9394
path = os.path.expanduser("~/.cache")
9495
return self._append_app_name_and_version(path)
9596

97+
@property
98+
def site_cache_dir(self) -> str:
99+
"""
100+
:return: cache directory shared by users, e.g. ``/var/tmp/$appname/$version``
101+
"""
102+
return self._append_app_name_and_version("/var/tmp")
103+
96104
@property
97105
def user_state_dir(self) -> str:
98106
"""
@@ -148,6 +156,11 @@ def site_config_path(self) -> Path:
148156
""":return: config path shared by the users. Only return first item, even if ``multipath`` is set to ``True``"""
149157
return self._first_item_as_path_if_multipath(self.site_config_dir)
150158

159+
@property
160+
def site_cache_path(self) -> Path:
161+
""":return: cache path shared by users. Only return first item, even if ``multipath`` is set to ``True``"""
162+
return self._first_item_as_path_if_multipath(self.site_cache_dir)
163+
151164
def _first_item_as_path_if_multipath(self, directory: str) -> Path:
152165
if self.multipath:
153166
# If multipath is True, the first path is returned.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# file generated by setuptools_scm
22
# don't change, don't track in version control
3-
__version__ = version = '2.6.2'
4-
__version_tuple__ = version_tuple = (2, 6, 2)
3+
__version__ = version = '3.2.0'
4+
__version_tuple__ = version_tuple = (3, 2, 0)

src/pip/_vendor/platformdirs/windows.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ class Windows(PlatformDirsABC):
1717
`appauthor <platformdirs.api.PlatformDirsABC.appauthor>`,
1818
`version <platformdirs.api.PlatformDirsABC.version>`,
1919
`roaming <platformdirs.api.PlatformDirsABC.roaming>`,
20-
`opinion <platformdirs.api.PlatformDirsABC.opinion>`."""
20+
`opinion <platformdirs.api.PlatformDirsABC.opinion>`,
21+
`ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.
22+
"""
2123

2224
@property
2325
def user_data_dir(self) -> str:
@@ -41,7 +43,9 @@ def _append_parts(self, path: str, *, opinion_value: str | None = None) -> str:
4143
params.append(opinion_value)
4244
if self.version:
4345
params.append(self.version)
44-
return os.path.join(path, *params)
46+
path = os.path.join(path, *params)
47+
self._optionally_create_directory(path)
48+
return path
4549

4650
@property
4751
def site_data_dir(self) -> str:
@@ -68,6 +72,12 @@ def user_cache_dir(self) -> str:
6872
path = os.path.normpath(get_win_folder("CSIDL_LOCAL_APPDATA"))
6973
return self._append_parts(path, opinion_value="Cache")
7074

75+
@property
76+
def site_cache_dir(self) -> str:
77+
""":return: cache directory shared by users, e.g. ``C:\\ProgramData\\$appauthor\\$appname\\Cache\\$version``"""
78+
path = os.path.normpath(get_win_folder("CSIDL_COMMON_APPDATA"))
79+
return self._append_parts(path, opinion_value="Cache")
80+
7181
@property
7282
def user_state_dir(self) -> str:
7383
""":return: state directory tied to the user, same as `user_data_dir`"""
@@ -81,6 +91,7 @@ def user_log_dir(self) -> str:
8191
path = self.user_data_dir
8292
if self.opinion:
8393
path = os.path.join(path, "Logs")
94+
self._optionally_create_directory(path)
8495
return path
8596

8697
@property

src/pip/_vendor/vendor.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ distlib==0.3.6
44
distro==1.8.0
55
msgpack==1.0.5
66
packaging==21.3
7-
platformdirs==2.6.2
7+
platformdirs==3.2.0
88
pyparsing==3.0.9
99
pyproject-hooks==1.0.0
1010
requests==2.28.2

0 commit comments

Comments
 (0)