Skip to content

Commit da10797

Browse files
committed
Upgrade platformdirs to 4.2.2
1 parent 3228d76 commit da10797

File tree

4 files changed

+41
-13
lines changed

4 files changed

+41
-13
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.2

src/pip/_vendor/platformdirs/android.py

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import re
77
import sys
88
from functools import lru_cache
9-
from typing import cast
9+
from typing import TYPE_CHECKING, cast
1010

1111
from .api import PlatformDirsABC
1212

@@ -117,23 +117,50 @@ def site_runtime_dir(self) -> str:
117117

118118

119119
@lru_cache(maxsize=1)
120-
def _android_folder() -> str | None:
120+
def _android_folder() -> str | None: # noqa: C901, PLR0912
121121
""":return: base folder for the Android OS or None if it cannot be found"""
122-
try:
123-
# First try to get a path to android app via pyjnius
124-
from jnius import autoclass # noqa: PLC0415
125-
126-
context = autoclass("android.content.Context")
127-
result: str | None = context.getFilesDir().getParentFile().getAbsolutePath()
128-
except Exception: # noqa: BLE001
129-
# if fails find an android folder looking a path on the sys.path
122+
result: str | None = None
123+
# type checker isn't happy with our "import android", just don't do this when type checking see
124+
# https://stackoverflow.com/a/61394121
125+
if not TYPE_CHECKING:
126+
try:
127+
# First try to get a path to android app using python4android (if available)...
128+
from android import mActivity # noqa: PLC0415
129+
130+
context = cast("android.content.Context", mActivity.getApplicationContext()) # noqa: F821
131+
result = context.getFilesDir().getParentFile().getAbsolutePath()
132+
except Exception: # noqa: BLE001
133+
result = None
134+
if result is None:
135+
try:
136+
# ...and fall back to using plain pyjnius, if python4android isn't available or doesn't deliver any useful
137+
# result...
138+
from jnius import autoclass # noqa: PLC0415
139+
140+
context = autoclass("android.content.Context")
141+
result = context.getFilesDir().getParentFile().getAbsolutePath()
142+
except Exception: # noqa: BLE001
143+
result = None
144+
if result is None:
145+
# and if that fails, too, find an android folder looking at path on the sys.path
146+
# warning: only works for apps installed under /data, not adopted storage etc.
130147
pattern = re.compile(r"/data/(data|user/\d+)/(.+)/files")
131148
for path in sys.path:
132149
if pattern.match(path):
133150
result = path.split("/files")[0]
134151
break
135152
else:
136153
result = None
154+
if result is None:
155+
# one last try: find an android folder looking at path on the sys.path taking adopted storage paths into
156+
# account
157+
pattern = re.compile(r"/mnt/expand/[a-fA-F0-9-]{36}/(data|user/\d+)/(.+)/files")
158+
for path in sys.path:
159+
if pattern.match(path):
160+
result = path.split("/files")[0]
161+
break
162+
else:
163+
result = None
137164
return result
138165

139166

src/pip/_vendor/platformdirs/version.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@
1212
__version_tuple__: VERSION_TUPLE
1313
version_tuple: VERSION_TUPLE
1414

15-
__version__ = version = '4.2.1'
16-
__version_tuple__ = version_tuple = (4, 2, 1)
15+
__version__ = version = '4.2.2'
16+
__version_tuple__ = version_tuple = (4, 2, 2)

src/pip/_vendor/vendor.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ distlib==0.3.8
33
distro==1.9.0
44
msgpack==1.0.8
55
packaging==24.1
6-
platformdirs==4.2.1
6+
platformdirs==4.2.2
77
pyproject-hooks==1.0.0
88
requests==2.32.3
99
certifi==2024.2.2

0 commit comments

Comments
 (0)