Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the pip version check when using --no-cache-dir #5680

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 == {}