Skip to content

Commit

Permalink
Upgrade platformdirs to 4.3.6
Browse files Browse the repository at this point in the history
  • Loading branch information
ichard26 committed Dec 7, 2024
1 parent c0900b8 commit 0904ed7
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 20 deletions.
1 change: 1 addition & 0 deletions news/platformdirs.vendor.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Upgrade platformdirs to 4.3.6
24 changes: 14 additions & 10 deletions src/pip/_vendor/platformdirs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@
from pathlib import Path
from typing import Literal

if sys.platform == "win32":
from pip._vendor.platformdirs.windows import Windows as _Result
elif sys.platform == "darwin":
from pip._vendor.platformdirs.macos import MacOS as _Result
else:
from pip._vendor.platformdirs.unix import Unix as _Result

def _set_platform_dir_class() -> type[PlatformDirsABC]:
if sys.platform == "win32":
from pip._vendor.platformdirs.windows import Windows as Result # noqa: PLC0415
elif sys.platform == "darwin":
from pip._vendor.platformdirs.macos import MacOS as Result # noqa: PLC0415
else:
from pip._vendor.platformdirs.unix import Unix as Result # noqa: PLC0415

def _set_platform_dir_class() -> type[PlatformDirsABC]:
if os.getenv("ANDROID_DATA") == "/data" and os.getenv("ANDROID_ROOT") == "/system":
if os.getenv("SHELL") or os.getenv("PREFIX"):
return Result
return _Result

from pip._vendor.platformdirs.android import _android_folder # noqa: PLC0415

Expand All @@ -39,10 +39,14 @@ def _set_platform_dir_class() -> type[PlatformDirsABC]:

return Android # return to avoid redefinition of a result

return Result
return _Result


PlatformDirs = _set_platform_dir_class() #: Currently active platform
if TYPE_CHECKING:
# Work around mypy issue: https://github.com/python/mypy/issues/10962
PlatformDirs = _Result
else:
PlatformDirs = _set_platform_dir_class() #: Currently active platform
AppDirs = PlatformDirs #: Backwards compatibility with appdirs


Expand Down
2 changes: 1 addition & 1 deletion src/pip/_vendor/platformdirs/android.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def site_runtime_dir(self) -> str:


@lru_cache(maxsize=1)
def _android_folder() -> str | None: # noqa: C901, PLR0912
def _android_folder() -> str | None: # noqa: C901
""":return: base folder for the Android OS or None if it cannot be found"""
result: str | None = None
# type checker isn't happy with our "import android", just don't do this when type checking see
Expand Down
6 changes: 6 additions & 0 deletions src/pip/_vendor/platformdirs/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ def _optionally_create_directory(self, path: str) -> None:
if self.ensure_exists:
Path(path).mkdir(parents=True, exist_ok=True)

def _first_item_as_path_if_multipath(self, directory: str) -> Path:
if self.multipath:
# If multipath is True, the first path is returned.
directory = directory.split(os.pathsep)[0]
return Path(directory)

@property
@abstractmethod
def user_data_dir(self) -> str:
Expand Down
14 changes: 14 additions & 0 deletions src/pip/_vendor/platformdirs/macos.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@

import os.path
import sys
from typing import TYPE_CHECKING

from .api import PlatformDirsABC

if TYPE_CHECKING:
from pathlib import Path


class MacOS(PlatformDirsABC):
"""
Expand Down Expand Up @@ -42,6 +46,11 @@ def site_data_dir(self) -> str:
return os.pathsep.join(path_list)
return path_list[0]

@property
def site_data_path(self) -> Path:
""":return: data path shared by users. Only return the first item, even if ``multipath`` is set to ``True``"""
return self._first_item_as_path_if_multipath(self.site_data_dir)

@property
def user_config_dir(self) -> str:
""":return: config directory tied to the user, same as `user_data_dir`"""
Expand Down Expand Up @@ -74,6 +83,11 @@ def site_cache_dir(self) -> str:
return os.pathsep.join(path_list)
return path_list[0]

@property
def site_cache_path(self) -> Path:
""":return: cache path shared by users. Only return the first item, even if ``multipath`` is set to ``True``"""
return self._first_item_as_path_if_multipath(self.site_cache_dir)

@property
def user_state_dir(self) -> str:
""":return: state directory tied to the user, same as `user_data_dir`"""
Expand Down
6 changes: 0 additions & 6 deletions src/pip/_vendor/platformdirs/unix.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,12 +218,6 @@ def site_cache_path(self) -> Path:
""":return: cache path shared by users. Only return the first item, even if ``multipath`` is set to ``True``"""
return self._first_item_as_path_if_multipath(self.site_cache_dir)

def _first_item_as_path_if_multipath(self, directory: str) -> Path:
if self.multipath:
# If multipath is True, the first path is returned.
directory = directory.split(os.pathsep)[0]
return Path(directory)

def iter_config_dirs(self) -> Iterator[str]:
""":yield: all user and site configuration directories."""
yield self.user_config_dir
Expand Down
4 changes: 2 additions & 2 deletions src/pip/_vendor/platformdirs/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
__version_tuple__: VERSION_TUPLE
version_tuple: VERSION_TUPLE

__version__ = version = '4.2.2'
__version_tuple__ = version_tuple = (4, 2, 2)
__version__ = version = '4.3.6'
__version_tuple__ = version_tuple = (4, 3, 6)
2 changes: 1 addition & 1 deletion src/pip/_vendor/vendor.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ distlib==0.3.9
distro==1.9.0
msgpack==1.1.0
packaging==24.1
platformdirs==4.2.2
platformdirs==4.3.6
pyproject-hooks==1.0.0
requests==2.32.3
certifi==2024.8.30
Expand Down

0 comments on commit 0904ed7

Please sign in to comment.