mirror of https://github.com/pypa/pip
Simplify selfcheck state file structure.
Since we are in a prefix-specific state file, we no longer need to have a top-level map keyed by prefix and can have a simple flat structure.
This commit is contained in:
parent
9928409b2f
commit
d81a95a095
|
@ -52,7 +52,7 @@ class SelfCheckState(object):
|
|||
)
|
||||
try:
|
||||
with open(self.statefile_path) as statefile:
|
||||
self.state = json.load(statefile)[self.key]
|
||||
self.state = json.load(statefile)
|
||||
except (IOError, ValueError, KeyError):
|
||||
# Explicitly suppressing exceptions, since we don't want to
|
||||
# error out if the cache file is invalid.
|
||||
|
@ -81,10 +81,11 @@ class SelfCheckState(object):
|
|||
# Since we have a prefix-specific state file, we can just
|
||||
# overwrite whatever is there, no need to check.
|
||||
state = {
|
||||
self.key: {
|
||||
"last_check": current_time.strftime(SELFCHECK_DATE_FMT),
|
||||
"pypi_version": pypi_version,
|
||||
},
|
||||
# Include the key so it's easy to tell which pip wrote the
|
||||
# file.
|
||||
"key": self.key,
|
||||
"last_check": current_time.strftime(SELFCHECK_DATE_FMT),
|
||||
"pypi_version": pypi_version,
|
||||
}
|
||||
|
||||
with open(self.statefile_path, "w") as statefile:
|
||||
|
|
|
@ -162,8 +162,8 @@ def _get_statefile_path(cache_dir, key):
|
|||
|
||||
|
||||
def test_self_check_state(monkeypatch, tmpdir):
|
||||
CONTENT = '''{"pip_prefix": {"last_check": "1970-01-02T11:00:00Z",
|
||||
"pypi_version": "1.0"}}'''
|
||||
CONTENT = '''{"key": "pip_prefix", "last_check": "1970-01-02T11:00:00Z",
|
||||
"pypi_version": "1.0"}'''
|
||||
fake_file = pretend.stub(
|
||||
read=pretend.call_recorder(lambda: CONTENT),
|
||||
write=pretend.call_recorder(lambda s: None),
|
||||
|
@ -229,10 +229,9 @@ def test_self_check_state_reads_expected_statefile(monkeypatch, tmpdir):
|
|||
last_check = "1970-01-02T11:00:00Z"
|
||||
pypi_version = "1.0"
|
||||
content = {
|
||||
key: {
|
||||
"last_check": last_check,
|
||||
"pypi_version": pypi_version,
|
||||
},
|
||||
"key": key,
|
||||
"last_check": last_check,
|
||||
"pypi_version": pypi_version,
|
||||
}
|
||||
|
||||
with open(statefile_path, "w") as f:
|
||||
|
@ -264,9 +263,8 @@ def test_self_check_state_writes_expected_statefile(monkeypatch, tmpdir):
|
|||
saved = json.load(f)
|
||||
|
||||
expected = {
|
||||
key: {
|
||||
"last_check": last_check.strftime(outdated.SELFCHECK_DATE_FMT),
|
||||
"pypi_version": pypi_version,
|
||||
},
|
||||
"key": key,
|
||||
"last_check": last_check.strftime(outdated.SELFCHECK_DATE_FMT),
|
||||
"pypi_version": pypi_version,
|
||||
}
|
||||
assert expected == saved
|
||||
|
|
Loading…
Reference in New Issue