Skip to content

Commit ebc3883

Browse files
committed
Vendor pip 23.3.1
1 parent 565bc44 commit ebc3883

File tree

4 files changed

+36
-7
lines changed

4 files changed

+36
-7
lines changed

pipenv/patched/patched.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
pip==23.3
1+
pip==23.3.1
22
safety==2.3.2

pipenv/patched/pip/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import List, Optional
22

3-
__version__ = "23.3"
3+
__version__ = "23.3.1"
44

55

66
def main(args: Optional[List[str]] = None) -> int:

pipenv/patched/pip/_internal/network/cache.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,18 @@ class SafeFileCache(SeparateBodyBaseCache):
3333
"""
3434
A file based cache which is safe to use even when the target directory may
3535
not be accessible or writable.
36+
37+
There is a race condition when two processes try to write and/or read the
38+
same entry at the same time, since each entry consists of two separate
39+
files (https://github.com/psf/cachecontrol/issues/324). We therefore have
40+
additional logic that makes sure that both files to be present before
41+
returning an entry; this fixes the read side of the race condition.
42+
43+
For the write side, we assume that the server will only ever return the
44+
same data for the same URL, which ought to be the case for files pip is
45+
downloading. PyPI does not have a mechanism to swap out a wheel for
46+
another wheel, for example. If this assumption is not true, the
47+
CacheControl issue will need to be fixed.
3648
"""
3749

3850
def __init__(self, directory: str) -> None:
@@ -49,9 +61,13 @@ def _get_cache_path(self, name: str) -> str:
4961
return os.path.join(self.directory, *parts)
5062

5163
def get(self, key: str) -> Optional[bytes]:
52-
path = self._get_cache_path(key)
64+
# The cache entry is only valid if both metadata and body exist.
65+
metadata_path = self._get_cache_path(key)
66+
body_path = metadata_path + ".body"
67+
if not (os.path.exists(metadata_path) and os.path.exists(body_path)):
68+
return None
5369
with suppressed_cache_errors():
54-
with open(path, "rb") as f:
70+
with open(metadata_path, "rb") as f:
5571
return f.read()
5672

5773
def _write(self, path: str, data: bytes) -> None:
@@ -77,9 +93,13 @@ def delete(self, key: str) -> None:
7793
os.remove(path + ".body")
7894

7995
def get_body(self, key: str) -> Optional[BinaryIO]:
80-
path = self._get_cache_path(key) + ".body"
96+
# The cache entry is only valid if both metadata and body exist.
97+
metadata_path = self._get_cache_path(key)
98+
body_path = metadata_path + ".body"
99+
if not (os.path.exists(metadata_path) and os.path.exists(body_path)):
100+
return None
81101
with suppressed_cache_errors():
82-
return open(path, "rb")
102+
return open(body_path, "rb")
83103

84104
def set_body(self, key: str, body: bytes) -> None:
85105
path = self._get_cache_path(key) + ".body"

pipenv/patched/pip/_internal/self_outdated_check.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,15 @@ def _get_statefile_name(key: str) -> str:
3939
return name
4040

4141

42+
def _convert_date(isodate: str) -> datetime.datetime:
43+
"""Convert an ISO format string to a date.
44+
45+
Handles the format 2020-01-22T14:24:01Z (trailing Z)
46+
which is not supported by older versions of fromisoformat.
47+
"""
48+
return datetime.datetime.fromisoformat(isodate.replace("Z", "+00:00"))
49+
50+
4251
class SelfCheckState:
4352
def __init__(self, cache_dir: str) -> None:
4453
self._state: Dict[str, Any] = {}
@@ -73,7 +82,7 @@ def get(self, current_time: datetime.datetime) -> Optional[str]:
7382
return None
7483

7584
# Determine if we need to refresh the state
76-
last_check = datetime.datetime.fromisoformat(self._state["last_check"])
85+
last_check = _convert_date(self._state["last_check"])
7786
time_since_last_check = current_time - last_check
7887
if time_since_last_check > _WEEK:
7988
return None

0 commit comments

Comments
 (0)