From 0904ed737d8db7e1605f11be561c7c3da55d434e Mon Sep 17 00:00:00 2001 From: Richard Si Date: Sat, 9 Nov 2024 20:26:15 -0500 Subject: [PATCH] Upgrade platformdirs to 4.3.6 --- news/platformdirs.vendor.rst | 1 + src/pip/_vendor/platformdirs/__init__.py | 24 ++++++++++++++---------- src/pip/_vendor/platformdirs/android.py | 2 +- src/pip/_vendor/platformdirs/api.py | 6 ++++++ src/pip/_vendor/platformdirs/macos.py | 14 ++++++++++++++ src/pip/_vendor/platformdirs/unix.py | 6 ------ src/pip/_vendor/platformdirs/version.py | 4 ++-- src/pip/_vendor/vendor.txt | 2 +- 8 files changed, 39 insertions(+), 20 deletions(-) create mode 100644 news/platformdirs.vendor.rst diff --git a/news/platformdirs.vendor.rst b/news/platformdirs.vendor.rst new file mode 100644 index 00000000000..360a631e567 --- /dev/null +++ b/news/platformdirs.vendor.rst @@ -0,0 +1 @@ +Upgrade platformdirs to 4.3.6 diff --git a/src/pip/_vendor/platformdirs/__init__.py b/src/pip/_vendor/platformdirs/__init__.py index d58dd2b7dde..edc21fad2e9 100644 --- a/src/pip/_vendor/platformdirs/__init__.py +++ b/src/pip/_vendor/platformdirs/__init__.py @@ -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 @@ -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 diff --git a/src/pip/_vendor/platformdirs/android.py b/src/pip/_vendor/platformdirs/android.py index afd3141c725..7004a852422 100644 --- a/src/pip/_vendor/platformdirs/android.py +++ b/src/pip/_vendor/platformdirs/android.py @@ -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 diff --git a/src/pip/_vendor/platformdirs/api.py b/src/pip/_vendor/platformdirs/api.py index c50caa648a6..18d660e4f8c 100644 --- a/src/pip/_vendor/platformdirs/api.py +++ b/src/pip/_vendor/platformdirs/api.py @@ -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: diff --git a/src/pip/_vendor/platformdirs/macos.py b/src/pip/_vendor/platformdirs/macos.py index eb1ba5df1da..e4b0391abd7 100644 --- a/src/pip/_vendor/platformdirs/macos.py +++ b/src/pip/_vendor/platformdirs/macos.py @@ -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): """ @@ -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`""" @@ -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`""" diff --git a/src/pip/_vendor/platformdirs/unix.py b/src/pip/_vendor/platformdirs/unix.py index 9500ade614c..f1942e92ef4 100644 --- a/src/pip/_vendor/platformdirs/unix.py +++ b/src/pip/_vendor/platformdirs/unix.py @@ -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 diff --git a/src/pip/_vendor/platformdirs/version.py b/src/pip/_vendor/platformdirs/version.py index 6483ddce0bc..afb49243e3d 100644 --- a/src/pip/_vendor/platformdirs/version.py +++ b/src/pip/_vendor/platformdirs/version.py @@ -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) diff --git a/src/pip/_vendor/vendor.txt b/src/pip/_vendor/vendor.txt index 86876767ecc..dbcdf7135f0 100644 --- a/src/pip/_vendor/vendor.txt +++ b/src/pip/_vendor/vendor.txt @@ -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