Skip to content

Commit 15a810e

Browse files
committed
Fix the pip version check when using --no-cache-dir
Fixes #5679
1 parent b2b6295 commit 15a810e

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

news/5679.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
The pip version check will now work correctly when using ``--no-cache-dir``.

src/pip/_internal/utils/outdated.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@
2222

2323
class SelfCheckState(object):
2424
def __init__(self, cache_dir):
25+
# cache_dir might be unset (e.g. False)
26+
if not cache_dir:
27+
self.statefile_path = None
28+
self.state = {}
29+
return
30+
2531
self.statefile_path = os.path.join(cache_dir, "selfcheck.json")
2632

2733
# Load the existing state
@@ -32,6 +38,9 @@ def __init__(self, cache_dir):
3238
self.state = {}
3339

3440
def save(self, pypi_version, current_time):
41+
if self.statefile_path is None:
42+
return
43+
3544
# Check to make sure that we own the directory
3645
if not check_path_owner(os.path.dirname(self.statefile_path)):
3746
return

tests/unit/test_unit_outdated.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,3 +169,8 @@ def fake_lock(filename):
169169

170170
# json.dumps will call this a number of times
171171
assert len(fake_file.write.calls)
172+
173+
174+
def test_self_check_state_no_cache_dir():
175+
state = outdated.SelfCheckState(cache_dir=False)
176+
assert state.state == {}

0 commit comments

Comments
 (0)