Skip to content

Commit

Permalink
Fix the pip version check when using --no-cache-dir
Browse files Browse the repository at this point in the history
Fixes #5679
  • Loading branch information
segevfiner committed Jul 31, 2018
1 parent b2b6295 commit 15a810e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions news/5679.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The pip version check will now work correctly when using ``--no-cache-dir``.
9 changes: 9 additions & 0 deletions src/pip/_internal/utils/outdated.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@

class SelfCheckState(object):
def __init__(self, cache_dir):
# cache_dir might be unset (e.g. False)
if not cache_dir:
self.statefile_path = None
self.state = {}
return

self.statefile_path = os.path.join(cache_dir, "selfcheck.json")

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

def save(self, pypi_version, current_time):
if self.statefile_path is None:
return

# Check to make sure that we own the directory
if not check_path_owner(os.path.dirname(self.statefile_path)):
return
Expand Down
5 changes: 5 additions & 0 deletions tests/unit/test_unit_outdated.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,8 @@ def fake_lock(filename):

# json.dumps will call this a number of times
assert len(fake_file.write.calls)


def test_self_check_state_no_cache_dir():
state = outdated.SelfCheckState(cache_dir=False)
assert state.state == {}

0 comments on commit 15a810e

Please sign in to comment.