diff --git a/src/pip/_internal/utils/outdated.py b/src/pip/_internal/utils/outdated.py index f8f64669d..b6d191b37 100644 --- a/src/pip/_internal/utils/outdated.py +++ b/src/pip/_internal/utils/outdated.py @@ -21,31 +21,6 @@ SELFCHECK_DATE_FMT = "%Y-%m-%dT%H:%M:%SZ" logger = logging.getLogger(__name__) -class VirtualenvSelfCheckState(object): - def __init__(self): - self.statefile_path = os.path.join(sys.prefix, "pip-selfcheck.json") - - # Load the existing state - try: - with open(self.statefile_path) as statefile: - self.state = json.load(statefile) - except (IOError, ValueError): - self.state = {} - - def save(self, pypi_version, current_time): - # Attempt to write out our version check file - with open(self.statefile_path, "w") as statefile: - json.dump( - { - "last_check": current_time.strftime(SELFCHECK_DATE_FMT), - "pypi_version": pypi_version, - }, - statefile, - sort_keys=True, - separators=(",", ":") - ) - - class GlobalSelfCheckState(object): def __init__(self): self.statefile_path = os.path.join(USER_CACHE_DIR, "selfcheck.json") @@ -84,13 +59,6 @@ class GlobalSelfCheckState(object): separators=(",", ":")) -def load_selfcheck_statefile(): - if running_under_virtualenv(): - return VirtualenvSelfCheckState() - else: - return GlobalSelfCheckState() - - def pip_version_check(session, options): """Check for an update for pip. @@ -106,7 +74,7 @@ def pip_version_check(session, options): pypi_version = None try: - state = load_selfcheck_statefile() + state = GlobalSelfCheckState() current_time = datetime.datetime.utcnow() # Determine if we need to refresh the state diff --git a/tests/unit/test_unit_outdated.py b/tests/unit/test_unit_outdated.py index 531ff02d2..f76ecbf96 100644 --- a/tests/unit/test_unit_outdated.py +++ b/tests/unit/test_unit_outdated.py @@ -72,7 +72,7 @@ def test_pip_version_check(monkeypatch, stored_time, installed_ver, new_ver, save=pretend.call_recorder(lambda v, t: None), ) monkeypatch.setattr( - outdated, 'load_selfcheck_statefile', lambda: fake_state + outdated, 'GlobalSelfCheckState', lambda: fake_state ) with freezegun.freeze_time( @@ -105,40 +105,6 @@ def test_pip_version_check(monkeypatch, stored_time, installed_ver, new_ver, assert len(outdated.logger.warning.calls) == 0 -def test_virtualenv_state(monkeypatch): - CONTENT = '{"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), - ) - - @pretend.call_recorder - @contextmanager - def fake_open(filename, mode='r'): - yield fake_file - - monkeypatch.setattr(outdated, 'open', fake_open, raising=False) - - monkeypatch.setattr(outdated, 'running_under_virtualenv', - pretend.call_recorder(lambda: True)) - - monkeypatch.setattr(sys, 'prefix', 'virtually_env') - - state = outdated.load_selfcheck_statefile() - state.save('2.0', datetime.datetime.utcnow()) - - assert len(outdated.running_under_virtualenv.calls) == 1 - - expected_path = os.path.join('virtually_env', 'pip-selfcheck.json') - assert fake_open.calls == [ - pretend.call(expected_path), - pretend.call(expected_path, 'w'), - ] - - # json.dumps will call this a number of times - assert len(fake_file.write.calls) - - def test_global_state(monkeypatch, tmpdir): CONTENT = '''{"pip_prefix": {"last_check": "1970-01-02T11:00:00Z", "pypi_version": "1.0"}}''' @@ -164,18 +130,14 @@ def test_global_state(monkeypatch, tmpdir): monkeypatch.setattr(lockfile, 'LockFile', fake_lock) monkeypatch.setattr(os.path, "exists", lambda p: True) - monkeypatch.setattr(outdated, 'running_under_virtualenv', - pretend.call_recorder(lambda: False)) cache_dir = tmpdir / 'cache_dir' monkeypatch.setattr(outdated, 'USER_CACHE_DIR', cache_dir) monkeypatch.setattr(sys, 'prefix', tmpdir / 'pip_prefix') - state = outdated.load_selfcheck_statefile() + state = outdated.GlobalSelfCheckState() state.save('2.0', datetime.datetime.utcnow()) - assert len(outdated.running_under_virtualenv.calls) == 1 - expected_path = cache_dir / 'selfcheck.json' assert fake_lock.calls == [pretend.call(expected_path)]