提交 6b57c1f5 编写于 作者: J John Paton

Move outdated outside utils and rename (pypa/pip#6532)

上级 af6f719a
......@@ -86,7 +86,7 @@ difference may simply be historical and may not actually be necessary.)
Each of these commands also uses the ``PackageFinder`` class for pip's
"self-check," (i.e. to check whether a pip upgrade is available). In this
case, the ``PackageFinder`` instance is created by the ``outdated.py``
module's ``pip_version_check()`` function.
module's ``pip_self_version_check()`` function.
The ``PackageFinder`` class is responsible for doing all of the things listed
in the :ref:`Overview <index-py-overview>` section like fetching and parsing
......
......@@ -25,8 +25,11 @@ from pip._internal.req.constructors import (
install_req_from_req_string,
)
from pip._internal.req.req_file import parse_requirements
from pip._internal.self_outdated_check import (
make_link_collector,
pip_self_version_check,
)
from pip._internal.utils.misc import normalize_path
from pip._internal.utils.outdated import make_link_collector, pip_version_check
from pip._internal.utils.typing import MYPY_CHECK_RUNNING
if MYPY_CHECK_RUNNING:
......@@ -136,7 +139,7 @@ class IndexGroupCommand(Command, SessionCommandMixin):
timeout=min(5, options.timeout)
)
with session:
pip_version_check(session, options)
pip_self_version_check(session, options)
class RequirementCommand(IndexGroupCommand):
......
......@@ -14,12 +14,12 @@ from pip._internal.cli.req_command import IndexGroupCommand
from pip._internal.exceptions import CommandError
from pip._internal.index import PackageFinder
from pip._internal.models.selection_prefs import SelectionPreferences
from pip._internal.self_outdated_check import make_link_collector
from pip._internal.utils.misc import (
dist_is_editable,
get_installed_distributions,
write_output,
)
from pip._internal.utils.outdated import make_link_collector
from pip._internal.utils.packaging import get_installer
logger = logging.getLogger(__name__)
......
......@@ -157,7 +157,7 @@ def was_installed_by_pip(pkg):
return False
def pip_version_check(session, options):
def pip_self_version_check(session, options):
# type: (PipSession, optparse.Values) -> None
"""Check for an update for pip.
......
......@@ -144,7 +144,7 @@ extra work on your end in order to solve the problems described above.
``pip/_vendor/``, then modify ``pip/_vendor/__init__.py`` so that the
``WHEEL_DIR`` variable points to the location you've placed them.
6. *(optional)* Update the ``pip_version_check`` logic to use the
6. *(optional)* Update the ``pip_self_version_check`` logic to use the
appropriate logic for determining the latest available version of pip and
prompt the user with the correct upgrade message.
......
......@@ -73,7 +73,7 @@ def test_index_group_commands():
@pytest.mark.parametrize(
'disable_pip_version_check, no_index, expected_called',
[
# pip_version_check() is only called when both
# pip_self_version_check() is only called when both
# disable_pip_version_check and no_index are False.
(False, False, True),
(False, True, False),
......@@ -81,14 +81,15 @@ def test_index_group_commands():
(True, True, False),
],
)
@patch('pip._internal.cli.req_command.pip_version_check')
@patch('pip._internal.cli.req_command.pip_self_version_check')
def test_index_group_handle_pip_version_check(
mock_version_check, command_name, disable_pip_version_check, no_index,
expected_called,
):
"""
Test whether pip_version_check() is called when handle_pip_version_check()
is called, for each of the IndexGroupCommand classes.
Test whether pip_self_version_check() is called when
handle_pip_version_check() is called, for each of the
IndexGroupCommand classes.
"""
command = create_command(command_name)
options = command.parser.get_default_values()
......
......@@ -9,14 +9,14 @@ import pytest
from mock import patch
from pip._vendor import pkg_resources
from pip._internal import self_outdated_check
from pip._internal.index import InstallationCandidate
from pip._internal.network.session import PipSession
from pip._internal.utils import outdated
from pip._internal.utils.outdated import (
from pip._internal.self_outdated_check import (
SelfCheckState,
logger,
make_link_collector,
pip_version_check,
pip_self_version_check,
)
from tests.lib.path import Path
......@@ -133,7 +133,8 @@ class MockDistribution(object):
def _options():
''' Some default options that we pass to outdated.pip_version_check '''
''' Some default options that we pass to
self_outdated_check.pip_self_version_check '''
return pretend.stub(
find_links=[], index_url='default_url', extra_index_urls=[],
no_index=False, pre=False, cache_dir='',
......@@ -160,12 +161,13 @@ def _options():
('1970-01-9T10:00:00Z', '6.9.0', '6.9.0', 'pip', False, False),
]
)
def test_pip_version_check(monkeypatch, stored_time, installed_ver, new_ver,
installer, check_if_upgrade_required,
check_warn_logs):
monkeypatch.setattr(outdated, 'get_installed_version',
def test_pip_self_version_check(monkeypatch, stored_time, installed_ver,
new_ver, installer,
check_if_upgrade_required, check_warn_logs):
monkeypatch.setattr(self_outdated_check, 'get_installed_version',
lambda name: installed_ver)
monkeypatch.setattr(outdated, 'PackageFinder', MockPackageFinder)
monkeypatch.setattr(self_outdated_check, 'PackageFinder',
MockPackageFinder)
monkeypatch.setattr(logger, 'warning',
pretend.call_recorder(lambda *a, **kw: None))
monkeypatch.setattr(logger, 'debug',
......@@ -178,7 +180,7 @@ def test_pip_version_check(monkeypatch, stored_time, installed_ver, new_ver,
save=pretend.call_recorder(lambda v, t: None),
)
monkeypatch.setattr(
outdated, 'SelfCheckState', lambda **kw: fake_state
self_outdated_check, 'SelfCheckState', lambda **kw: fake_state
)
with freezegun.freeze_time(
......@@ -189,7 +191,7 @@ def test_pip_version_check(monkeypatch, stored_time, installed_ver, new_ver,
"pip._vendor.requests.packages.urllib3.packages.six.moves",
]
):
latest_pypi_version = pip_version_check(None, _options())
latest_pypi_version = pip_self_version_check(None, _options())
# See we return None if not installed_version
if not installed_ver:
......@@ -226,12 +228,12 @@ statefile_name_case_2 = (
("C:\\Users\\User\\Desktop\\venv", statefile_name_case_2),
])
def test_get_statefile_name_known_values(key, expected):
assert expected == outdated._get_statefile_name(key)
assert expected == self_outdated_check._get_statefile_name(key)
def _get_statefile_path(cache_dir, key):
return os.path.join(
cache_dir, "selfcheck", outdated._get_statefile_name(key)
cache_dir, "selfcheck", self_outdated_check._get_statefile_name(key)
)
......@@ -245,7 +247,7 @@ def test_self_check_state_key_uses_sys_prefix(monkeypatch):
key = "helloworld"
monkeypatch.setattr(sys, "prefix", key)
state = outdated.SelfCheckState("")
state = self_outdated_check.SelfCheckState("")
assert state.key == key
......@@ -270,7 +272,7 @@ def test_self_check_state_reads_expected_statefile(monkeypatch, tmpdir):
json.dump(content, f)
monkeypatch.setattr(sys, "prefix", key)
state = outdated.SelfCheckState(str(cache_dir))
state = self_outdated_check.SelfCheckState(str(cache_dir))
assert state.state["last_check"] == last_check
assert state.state["pypi_version"] == pypi_version
......@@ -283,12 +285,12 @@ def test_self_check_state_writes_expected_statefile(monkeypatch, tmpdir):
statefile_path = _get_statefile_path(str(cache_dir), key)
last_check = datetime.datetime.strptime(
"1970-01-02T11:00:00Z", outdated.SELFCHECK_DATE_FMT
"1970-01-02T11:00:00Z", self_outdated_check.SELFCHECK_DATE_FMT
)
pypi_version = "1.0"
monkeypatch.setattr(sys, "prefix", key)
state = outdated.SelfCheckState(str(cache_dir))
state = self_outdated_check.SelfCheckState(str(cache_dir))
state.save(pypi_version, last_check)
with open(statefile_path) as f:
......@@ -296,7 +298,8 @@ def test_self_check_state_writes_expected_statefile(monkeypatch, tmpdir):
expected = {
"key": key,
"last_check": last_check.strftime(outdated.SELFCHECK_DATE_FMT),
"last_check": last_check.strftime(
self_outdated_check.SELFCHECK_DATE_FMT),
"pypi_version": pypi_version,
}
assert expected == saved
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册