Skip to content

Commit

Permalink
Shorten selfcheck filenames and move to cache subdirectory.
Browse files Browse the repository at this point in the history
  • Loading branch information
chrahunt committed Aug 15, 2019
1 parent c91af0d commit 5f4da50
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/pip/_internal/utils/outdated.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
def _get_statefile_name(key):
# type: (Union[str, Text]) -> str
key_bytes = ensure_binary(key)
name = hashlib.sha256(key_bytes).hexdigest()
return "selfcheck-{}.json".format(name)
name = hashlib.sha224(key_bytes).hexdigest()
return name


class SelfCheckState(object):
Expand All @@ -48,7 +48,7 @@ def __init__(self, cache_dir):
# Try to load the existing state
if cache_dir:
self.statefile_path = os.path.join(
cache_dir, _get_statefile_name(self.key)
cache_dir, "selfcheck", _get_statefile_name(self.key)
)
try:
with open(self.statefile_path) as statefile:
Expand Down
12 changes: 6 additions & 6 deletions tests/unit/test_unit_outdated.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

from pip._internal.index import InstallationCandidate
from pip._internal.utils import outdated
from tests.lib.path import Path


class MockFoundCandidates(object):
Expand Down Expand Up @@ -137,13 +138,11 @@ def test_pip_version_check(monkeypatch, stored_time, installed_ver, new_ver,


statefile_name_case_1 = (
"selfcheck-"
"d0d922be2c876108df5bd95254ebf2b9228716063584a623cadcc72159364474.json"
"fcd2d5175dd33d5df759ee7b045264230205ef837bf9f582f7c3ada7"
)

statefile_name_case_2 = (
"selfcheck-"
"37d748d2f9a7d61c07aa598962da9a6a620b6b2203038952062471fbf22762ec.json"
"902cecc0745b8ecf2509ba473f3556f0ba222fedc6df433acda24aa5"
)


Expand All @@ -157,7 +156,7 @@ def test_get_statefile_name_known_values(key, expected):

def _get_statefile_path(cache_dir, key):
return os.path.join(
cache_dir, outdated._get_statefile_name(key)
cache_dir, "selfcheck", outdated._get_statefile_name(key)
)


Expand All @@ -184,7 +183,6 @@ def fake_lock(filename):
monkeypatch.setattr(outdated, "check_path_owner", lambda p: True)

monkeypatch.setattr(lockfile, 'LockFile', fake_lock)
monkeypatch.setattr(os.path, "exists", lambda p: True)

cache_dir = tmpdir / 'cache_dir'
key = 'pip_prefix'
Expand Down Expand Up @@ -234,6 +232,8 @@ def test_self_check_state_reads_expected_statefile(monkeypatch, tmpdir):
"pypi_version": pypi_version,
}

Path(statefile_path).parent.mkdir()

with open(statefile_path, "w") as f:
json.dump(content, f)

Expand Down

0 comments on commit 5f4da50

Please sign in to comment.