diff --git a/news/5679.bugfix b/news/5679.bugfix new file mode 100644 index 00000000000..b8b8b0f1ff3 --- /dev/null +++ b/news/5679.bugfix @@ -0,0 +1 @@ +The pip version check will now work correctly when using ``--no-cache-dir``. diff --git a/src/pip/_internal/utils/outdated.py b/src/pip/_internal/utils/outdated.py index 4c084ab996a..bd094f035ed 100644 --- a/src/pip/_internal/utils/outdated.py +++ b/src/pip/_internal/utils/outdated.py @@ -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 @@ -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 diff --git a/tests/unit/test_unit_outdated.py b/tests/unit/test_unit_outdated.py index 1f20664e769..4c9a89f8e30 100644 --- a/tests/unit/test_unit_outdated.py +++ b/tests/unit/test_unit_outdated.py @@ -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 == {}