From d9d801f8182fcdffc7c8f77c95749113e0feb08a Mon Sep 17 00:00:00 2001 From: Pradyun Gedam Date: Mon, 6 Jan 2020 19:29:56 +0530 Subject: [PATCH 1/2] Drop no-suffix checks for pip-from-PATH --- src/pip/_internal/utils/misc.py | 10 +++++----- tests/functional/test_install.py | 3 --- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/pip/_internal/utils/misc.py b/src/pip/_internal/utils/misc.py index a53ce0dc9f9..50b603adbb0 100644 --- a/src/pip/_internal/utils/misc.py +++ b/src/pip/_internal/utils/misc.py @@ -836,11 +836,11 @@ def protect_pip_from_modification_on_windows(modifying_pip): On Windows, any operation modifying pip should be run as: python -m pip ... """ - pip_names = set() - for ext in ('', '.exe'): - pip_names.add('pip{ext}'.format(ext=ext)) - pip_names.add('pip{}{ext}'.format(sys.version_info[0], ext=ext)) - pip_names.add('pip{}.{}{ext}'.format(*sys.version_info[:2], ext=ext)) + pip_names = [ + "pip.exe", + "pip{}.exe".format(sys.version_info[0]), + "pip{}.{}.exe".format(*sys.version_info[:2]) + ] # See https://github.com/pypa/pip/issues/1299 for more discussion should_show_use_python_msg = ( diff --git a/tests/functional/test_install.py b/tests/functional/test_install.py index 7b2d0b9f92a..e9cadca20df 100644 --- a/tests/functional/test_install.py +++ b/tests/functional/test_install.py @@ -1661,9 +1661,6 @@ def test_user_config_accepted(script): @pytest.mark.network @pytest.mark.skipif("sys.platform != 'win32'") @pytest.mark.parametrize('pip_name', [ - 'pip', - 'pip{}'.format(sys.version_info[0]), - 'pip{}.{}'.format(*sys.version_info[:2]), 'pip.exe', 'pip{}.exe'.format(sys.version_info[0]), 'pip{}.{}.exe'.format(*sys.version_info[:2]) From 4ee779f79e297982422018bfc7603f07fba59215 Mon Sep 17 00:00:00 2001 From: Pradyun Gedam Date: Tue, 7 Jan 2020 12:21:13 +0530 Subject: [PATCH 2/2] Drop no longer valid tests --- tests/functional/test_install.py | 81 -------------------------------- 1 file changed, 81 deletions(-) diff --git a/tests/functional/test_install.py b/tests/functional/test_install.py index e9cadca20df..713c9518b5d 100644 --- a/tests/functional/test_install.py +++ b/tests/functional/test_install.py @@ -10,7 +10,6 @@ import pytest -from pip import __version__ as pip_current_version from pip._internal.cli.status_codes import ERROR, SUCCESS from pip._internal.models.index import PyPI, TestPyPI from pip._internal.utils.misc import rmtree @@ -1658,86 +1657,6 @@ def test_user_config_accepted(script): assert join(relative_user, 'simplewheel') in result.files_created -@pytest.mark.network -@pytest.mark.skipif("sys.platform != 'win32'") -@pytest.mark.parametrize('pip_name', [ - 'pip.exe', - 'pip{}.exe'.format(sys.version_info[0]), - 'pip{}.{}.exe'.format(*sys.version_info[:2]) -]) -def test_protect_pip_from_modification_on_windows(script, pip_name): - """ - Test that pip modification command using ``pip install ...`` - raises an error on Windows. - """ - command = [pip_name, 'install', 'pip != {}'.format(pip_current_version)] - result = script.run(*command, expect_error=True) - new_command = [sys.executable, '-m', 'pip'] + command[1:] - expected_message = ( - 'To modify pip, please run the following command:\n{}' - .format(' '.join(new_command)) - ) - assert expected_message in result.stderr, str(result) - - -@pytest.mark.network -@pytest.mark.skipif("sys.platform != 'win32'") -def test_protect_pip_from_modification_via_deps_on_windows(script): - """ - Test ``pip install pkga`` raises an error on Windows - if `pkga` implicitly tries to upgrade pip. - """ - pkga_wheel_path = create_basic_wheel_for_package( - script, - 'pkga', '0.1', - depends=['pip != {}'.format(pip_current_version)], - ) - - # Make sure pip install pkga raises an error - args = ['install', pkga_wheel_path] - result = script.pip(*args, expect_error=True, use_module=False) - new_command = [sys.executable, '-m', 'pip'] + args - expected_message = ( - 'To modify pip, please run the following command:\n{}' - .format(' '.join(new_command)) - ) - assert expected_message in result.stderr, str(result) - - -@pytest.mark.network -@pytest.mark.skipif("sys.platform != 'win32'") -def test_protect_pip_from_modification_via_sub_deps_on_windows(script): - """ - Test ``pip install pkga`` raises an error on Windows - if sub-dependencies of `pkga` implicitly tries to upgrade pip. - """ - # Make a wheel for pkga which requires pkgb - pkga_wheel_path = create_basic_wheel_for_package( - script, - 'pkga', '0.1', - depends=['pkgb'], - ) - - # Make a wheel for pkgb which requires pip - pkgb_wheel_path = create_basic_wheel_for_package( - script, - 'pkgb', '0.1', - depends=['pip != {}'.format(pip_current_version)], - ) - - # Make sure pip install pkga raises an error - args = [ - 'install', pkga_wheel_path, '--find-links', pkgb_wheel_path.parent - ] - result = script.pip(*args, expect_error=True, use_module=False) - new_command = [sys.executable, '-m', 'pip'] + args - expected_message = ( - 'To modify pip, please run the following command:\n{}' - .format(' '.join(new_command)) - ) - assert expected_message in result.stderr, str(result) - - @pytest.mark.parametrize( 'install_args, expected_message', [ ([], 'Requirement already satisfied: pip in'),