From ab9131a0af7eb5fcddf7c4553242eaa00e243b05010f0867adade40b37882ca9 Mon Sep 17 00:00:00 2001 From: Dirk Mueller Date: Sun, 7 Nov 2021 18:12:24 +0000 Subject: [PATCH] - update to 21.3.1: * Always refuse installing or building projects that have no ``pyproject.toml`` nor ``setup.py``. * Tweak running-as-root detection, to check ``os.getuid`` if it exists, on Unix-y and non-Linux/non-MacOS machines. * When installing projects with a ``pyproject.toml`` in editable mode, and the build backend does not support :pep:`660`, prepare metadata using ``prepare_metadata_for_build_wheel`` instead of ``setup.py egg_info``. Also, refuse installing projects that only have a ``setup.cfg`` and no ``setup.py`` nor ``pyproject.toml``. These restore the pre-21.3 behaviour. * Restore compatibility of where configuration files are loaded from on MacOS * Upgrade pep517 to 0.12.0 * Improve deprecation warning regarding the copying of source trees when installing from a local directory. * Suppress location mismatch warnings when pip is invoked from a Python source tree, so ``ensurepip`` does not emit warnings on CPython ``make install``. * On Python 3.10 or later, the installation scheme backend has been changed to use ``sysconfig``. This is to anticipate the deprecation of ``distutils`` in Python 3.10, and its scheduled removal in 3.12. For compatibility considerations, pip installations running on Python 3.9 or lower will continue to use ``distutils``. * Remove the ``--build-dir`` option and aliases, one last time. * In-tree builds are now the default. ``--use-feature=in-tree-build`` is now ignored. ``--use-deprecated=out-of-tree-build`` may be used temporarily to ease the transition. * Un-deprecate source distribution re-installation behaviour. * Replace vendored appdirs with platformdirs. * Support `PEP 610 `_ to detect editable installs in ``pip freeze`` and ``pip list``. The ``pip list`` column output has a new ``Editable project location`` column, and the JSON output has a new ``editable_project_location`` field. OBS-URL: https://build.opensuse.org/package/show/devel:languages:python/python-pip?expand=0&rev=92 --- pip-20.2.4-gh.tar.gz | 3 - pip-21.3.1-gh.tar.gz | 3 + pip-shipped-requests-cabundle.patch | 32 +- python-pip.changes | 62 +++ python-pip.spec | 9 +- remove_mock.patch | 601 ---------------------------- 6 files changed, 92 insertions(+), 618 deletions(-) delete mode 100644 pip-20.2.4-gh.tar.gz create mode 100644 pip-21.3.1-gh.tar.gz delete mode 100644 remove_mock.patch diff --git a/pip-20.2.4-gh.tar.gz b/pip-20.2.4-gh.tar.gz deleted file mode 100644 index 3285d07..0000000 --- a/pip-20.2.4-gh.tar.gz +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:f3a068a9ff1986747514dd07f0a465a5a498c9f426c3198fa88f8a208c98d6a4 -size 8723163 diff --git a/pip-21.3.1-gh.tar.gz b/pip-21.3.1-gh.tar.gz new file mode 100644 index 0000000..712d8a5 --- /dev/null +++ b/pip-21.3.1-gh.tar.gz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cbfb6a0b5bc2d1e4b4647729ee5b944bb313c8ffd9ff83b9d2e0f727f0c79714 +size 8961896 diff --git a/pip-shipped-requests-cabundle.patch b/pip-shipped-requests-cabundle.patch index 43abd0f..6201245 100644 --- a/pip-shipped-requests-cabundle.patch +++ b/pip-shipped-requests-cabundle.patch @@ -1,25 +1,39 @@ -Index: pip-20.2.3/src/pip/_vendor/certifi/core.py +Index: pip-21.3.1/src/pip/_vendor/certifi/core.py =================================================================== ---- pip-20.2.3.orig/src/pip/_vendor/certifi/core.py -+++ pip-20.2.3/src/pip/_vendor/certifi/core.py -@@ -5,56 +5,18 @@ certifi.py +--- pip-21.3.1.orig/src/pip/_vendor/certifi/core.py ++++ pip-21.3.1/src/pip/_vendor/certifi/core.py +@@ -5,72 +5,18 @@ certifi.py ~~~~~~~~~~ This module returns the installation location of cacert.pem or its contents. -""" -import os +- --try: -- from importlib.resources import path as get_path, read_text +-class _PipPatchedCertificate(Exception): +- pass +Patched by openSUSE: return the system bundle +""" -- _CACERT_CTX = None -- _CACERT_PATH = None +def read_text(_module=None, _path=None, encoding="ascii"): + with open(where(), "r", encoding=encoding) as data: + return data.read() +-try: +- # Return a certificate file on disk for a standalone pip zipapp running in +- # an isolated build environment to use. Passing --cert to the standalone +- # pip does not work since requests calls where() unconditionally on import. +- _PIP_STANDALONE_CERT = os.environ.get("_PIP_STANDALONE_CERT") +- if _PIP_STANDALONE_CERT: +- def where(): +- return _PIP_STANDALONE_CERT +- raise _PipPatchedCertificate() +- +- from importlib.resources import path as get_path, read_text +- +- _CACERT_CTX = None +- _CACERT_PATH = None +- - def where(): - # This is slightly terrible, but we want to delay extracting the file - # in cases where we're inside of a zipimport situation until someone @@ -44,6 +58,8 @@ Index: pip-20.2.3/src/pip/_vendor/certifi/core.py - - return _CACERT_PATH - +-except _PipPatchedCertificate: +- pass - -except ImportError: - # This fallback will work for Python versions prior to 3.7 that lack the diff --git a/python-pip.changes b/python-pip.changes index 052159c..f3ad078 100644 --- a/python-pip.changes +++ b/python-pip.changes @@ -1,3 +1,65 @@ +------------------------------------------------------------------- +Sun Nov 7 17:07:30 UTC 2021 - Dirk Müller + +- update to 21.3.1: + * Always refuse installing or building projects that have no ``pyproject.toml`` nor + ``setup.py``. + * Tweak running-as-root detection, to check ``os.getuid`` if it exists, on + Unix-y and non-Linux/non-MacOS machines. + * When installing projects with a ``pyproject.toml`` in editable mode, and the build + backend does not support :pep:`660`, prepare metadata using + ``prepare_metadata_for_build_wheel`` instead of ``setup.py egg_info``. Also, refuse + installing projects that only have a ``setup.cfg`` and no ``setup.py`` nor + ``pyproject.toml``. These restore the pre-21.3 behaviour. + * Restore compatibility of where configuration files are loaded from on MacOS + * Upgrade pep517 to 0.12.0 + * Improve deprecation warning regarding the copying of source trees when + installing from a local directory. + * Suppress location mismatch warnings when pip is invoked from a Python source + tree, so ``ensurepip`` does not emit warnings on CPython ``make install``. + * On Python 3.10 or later, the installation scheme backend has been changed to use + ``sysconfig``. This is to anticipate the deprecation of ``distutils`` in Python + 3.10, and its scheduled removal in 3.12. For compatibility considerations, pip + installations running on Python 3.9 or lower will continue to use ``distutils``. + * Remove the ``--build-dir`` option and aliases, one last time. + * In-tree builds are now the default. ``--use-feature=in-tree-build`` is now + ignored. ``--use-deprecated=out-of-tree-build`` may be used temporarily to ease + the transition. + * Un-deprecate source distribution re-installation behaviour. + * Replace vendored appdirs with platformdirs. + * Support `PEP 610 `_ to detect + editable installs in ``pip freeze`` and ``pip list``. The ``pip list`` column output + has a new ``Editable project location`` column, and the JSON output has a new + ``editable_project_location`` field. + * ``pip freeze`` will now always fallback to reporting the editable project + location when it encounters a VCS error while analyzing an editable + requirement. Before, it sometimes reported the requirement as non-editable. + * ``pip show`` now sorts ``Requires`` and ``Required-By`` alphabetically. + * Do not raise error when there are no files to remove with ``pip cache purge/remove``. + Instead log a warning and continue (to log that we removed 0 files). + * When backtracking during dependency resolution, prefer the dependencies + which are involved in the most recent conflict. This can significantly + reduce the amount of backtracking required. + * Cache requirement objects, to improve performance reducing reparses of requirement strings. + * Support editable installs for projects that have a ``pyproject.toml`` and use a + build backend that supports :pep:`660`. + * When a revision is specified in a Git URL, use git's partial clone feature + to speed up source retrieval. + * Add a ``--debug`` flag, to enable a mode that doesn't log errors and + propagates them to the top level instead. This is primarily to aid with + debugging pip's crashes. + * If a host is explicitly specified as trusted by the user (via the + --trusted-host option), cache HTTP responses from it in addition to HTTPS + ones. + * Present a better error message, when a ``file:`` URL is not found. + * Fix the auth credential cache to allow for the case in which + the index url contains the username, but the password comes + from an external source, such as keyring. + * Fix double unescape of HTML ``data-requires-python`` and ``data-yanked`` attributes. + * New resolver: Fixes depth ordering of packages during resolution, e.g. a + dependency 2 levels deep will be ordered before a dependecy 3 levels deep. +- drop remove_mock.patch (upstream) + ------------------------------------------------------------------- Wed Sep 8 16:07:38 UTC 2021 - Stefan Schubert diff --git a/python-pip.spec b/python-pip.spec index 8a8bd8b..a36c2d2 100644 --- a/python-pip.spec +++ b/python-pip.spec @@ -1,5 +1,5 @@ # -# spec file for package python-pip +# spec file # # Copyright (c) 2021 SUSE LLC # @@ -39,7 +39,7 @@ %endif %endif Name: python-pip%{psuffix} -Version: 20.2.4 +Version: 21.3.1 Release: 0 Summary: A Python package management system License: MIT @@ -48,9 +48,6 @@ URL: http://www.pip-installer.org Source: https://github.com/pypa/pip/archive/%{version}.tar.gz#/pip-%{version}-gh.tar.gz # PATCH-FIX-OPENSUSE pip-shipped-requests-cabundle.patch -- adapted patch from python-certifi package Patch0: pip-shipped-requests-cabundle.patch -# PATCH-FIX-UPSTREAM remove_mock.patch gh#pypa/pip#9266 mcepl@suse.com -# remove dependency on the external module mock -Patch1: remove_mock.patch BuildRequires: %{python_module setuptools >= 40.8.0} BuildRequires: fdupes BuildRequires: python-rpm-macros >= 20210929 @@ -63,7 +60,7 @@ Requires: alts BuildRequires: alts %else Requires(post): update-alternatives -Requires(postun): update-alternatives +Requires(postun):update-alternatives %endif Recommends: ca-certificates-mozilla BuildArch: noarch diff --git a/remove_mock.patch b/remove_mock.patch deleted file mode 100644 index ad93ae1..0000000 --- a/remove_mock.patch +++ /dev/null @@ -1,601 +0,0 @@ ---- - tests/functional/test_help.py | 5 + - tests/lib/server.py | 5 + - tests/unit/resolution_resolvelib/test_resolver.py | 5 + - tests/unit/test_base_command.py | 5 + - tests/unit/test_check.py | 5 + - tests/unit/test_collector.py | 66 +++++++++++----------- - tests/unit/test_command_install.py | 5 + - tests/unit/test_commands.py | 5 + - tests/unit/test_configuration.py | 5 + - tests/unit/test_direct_url_helpers.py | 5 + - tests/unit/test_finder.py | 5 + - tests/unit/test_locations.py | 5 + - tests/unit/test_logging.py | 5 + - tests/unit/test_network_cache.py | 5 + - tests/unit/test_operations_prepare.py | 5 + - tests/unit/test_req.py | 5 + - tests/unit/test_req_file.py | 5 + - tests/unit/test_req_uninstall.py | 5 + - tests/unit/test_resolution_legacy_resolver.py | 5 + - tests/unit/test_target_python.py | 5 + - tests/unit/test_utils.py | 5 + - tests/unit/test_utils_compatibility_tags.py | 5 + - tests/unit/test_vcs.py | 5 + - tests/unit/test_wheel.py | 5 + - tests/unit/test_wheel_builder.py | 5 + - 25 files changed, 130 insertions(+), 56 deletions(-) - ---- a/tests/lib/server.py -+++ b/tests/lib/server.py -@@ -5,7 +5,10 @@ import threading - from contextlib import contextmanager - from textwrap import dedent - --from mock import Mock -+try: -+ from unittest.mock import Mock -+except ImportError: -+ from mock import Mock - from pip._vendor.contextlib2 import nullcontext - from werkzeug.serving import WSGIRequestHandler - from werkzeug.serving import make_server as _make_server ---- a/tests/unit/test_base_command.py -+++ b/tests/unit/test_base_command.py -@@ -3,7 +3,10 @@ import os - import time - - import pytest --from mock import Mock, patch -+try: -+ from unittest.mock import Mock, patch -+except ImportError: -+ from mock import Mock, patch - - from pip._internal.cli.base_command import Command - from pip._internal.cli.status_codes import SUCCESS ---- a/tests/unit/test_commands.py -+++ b/tests/unit/test_commands.py -@@ -1,5 +1,8 @@ - import pytest --from mock import patch -+try: -+ from unittest.mock import patch -+except ImportError: -+ from mock import patch - - from pip._internal.cli.req_command import ( - IndexGroupCommand, ---- a/tests/unit/test_network_cache.py -+++ b/tests/unit/test_network_cache.py -@@ -1,7 +1,10 @@ - import os - - import pytest --from mock import Mock -+try: -+ from unittest.mock import Mock -+except ImportError: -+ from mock import Mock - from pip._vendor.cachecontrol.caches import FileCache - - from pip._internal.network.cache import SafeFileCache ---- a/tests/unit/test_req_file.py -+++ b/tests/unit/test_req_file.py -@@ -5,7 +5,10 @@ import subprocess - import textwrap - - import pytest --from mock import patch -+try: -+ from unittest.mock import patch -+except ImportError: -+ from mock import patch - from pip._vendor.six import PY2 - from pretend import stub - ---- a/tests/unit/test_resolution_legacy_resolver.py -+++ b/tests/unit/test_resolution_legacy_resolver.py -@@ -1,6 +1,9 @@ - import logging - --import mock -+try: -+ from unittest.mock import Mock -+except ImportError: -+ from mock import Mock - import pytest - from pip._vendor import pkg_resources - -@@ -189,7 +192,7 @@ class TestYankedWarning(object): - - return Resolver( - finder=finder, -- preparer=mock.Mock(), # Not used. -+ preparer=Mock(), # Not used. - make_install_req=install_req_from_line, - wheel_cache=None, - use_user_site=False, ---- a/tests/unit/test_target_python.py -+++ b/tests/unit/test_target_python.py -@@ -1,5 +1,8 @@ - import pytest --from mock import patch -+try: -+ from unittest.mock import patch -+except ImportError: -+ from mock import patch - - from pip._internal.models.target_python import TargetPython - from tests.lib import CURRENT_PY_VERSION_INFO, pyversion ---- a/tests/unit/test_utils.py -+++ b/tests/unit/test_utils.py -@@ -14,7 +14,10 @@ import time - from io import BytesIO - - import pytest --from mock import Mock, patch -+try: -+ from unittest.mock import Mock, patch -+except ImportError: -+ from mock import Mock, patch - - from pip._internal.exceptions import ( - HashMismatch, ---- a/tests/unit/test_utils_compatibility_tags.py -+++ b/tests/unit/test_utils_compatibility_tags.py -@@ -1,7 +1,10 @@ - import sysconfig - - import pytest --from mock import patch -+try: -+ from unittest.mock import patch -+except ImportError: -+ from mock import patch - - from pip._internal.utils import compatibility_tags - ---- a/tests/unit/test_vcs.py -+++ b/tests/unit/test_vcs.py -@@ -2,7 +2,10 @@ import os - from unittest import TestCase - - import pytest --from mock import patch -+try: -+ from unittest.mock import patch -+except ImportError: -+ from mock import patch - from pip._vendor.packaging.version import parse as parse_version - - from pip._internal.exceptions import BadCommand, InstallationError ---- a/tests/unit/test_wheel.py -+++ b/tests/unit/test_wheel.py -@@ -8,7 +8,10 @@ import textwrap - from email import message_from_string - - import pytest --from mock import patch -+try: -+ from unittest.mock import patch -+except ImportError: -+ from mock import patch - from pip._vendor.packaging.requirements import Requirement - - from pip._internal.exceptions import InstallationError ---- a/tests/unit/test_wheel_builder.py -+++ b/tests/unit/test_wheel_builder.py -@@ -1,7 +1,10 @@ - import logging - - import pytest --from mock import patch -+try: -+ from unittest.mock import patch -+except ImportError: -+ from mock import patch - - from pip._internal import wheel_builder - from pip._internal.models.link import Link ---- a/tests/functional/test_help.py -+++ b/tests/functional/test_help.py -@@ -1,5 +1,8 @@ - import pytest --from mock import Mock -+try: -+ from unittest.mock import Mock -+except ImportError: -+ from mock import Mock - - from pip._internal.cli.status_codes import ERROR, SUCCESS - from pip._internal.commands import commands_dict, create_command ---- a/tests/unit/resolution_resolvelib/test_resolver.py -+++ b/tests/unit/resolution_resolvelib/test_resolver.py -@@ -1,4 +1,7 @@ --import mock -+try: -+ from unittest.mock import Mock -+except ImportError: -+ from mock import Mock - import pytest - from pip._vendor.packaging.utils import canonicalize_name - from pip._vendor.resolvelib.resolvers import Result -@@ -18,7 +21,7 @@ def resolver(preparer, finder): - preparer=preparer, - finder=finder, - wheel_cache=None, -- make_install_req=mock.Mock(), -+ make_install_req=Mock(), - use_user_site="not-used", - ignore_dependencies="not-used", - ignore_installed="not-used", ---- a/tests/unit/test_check.py -+++ b/tests/unit/test_check.py -@@ -1,7 +1,10 @@ - """Unit Tests for pip's dependency checking logic - """ - --import mock -+try: -+ from unittest.mock import MagicMock -+except ImportError: -+ from mock import MagicMock - - from pip._internal.operations import check - -@@ -9,7 +12,7 @@ from pip._internal.operations import che - class TestInstalledDistributionsCall(object): - - def test_passes_correct_default_kwargs(self, monkeypatch): -- my_mock = mock.MagicMock(return_value=[]) -+ my_mock = MagicMock(return_value=[]) - monkeypatch.setattr(check, "get_installed_distributions", my_mock) - - check.create_package_set_from_installed() -@@ -17,7 +20,7 @@ class TestInstalledDistributionsCall(obj - my_mock.assert_called_with(local_only=False, skip=()) - - def test_passes_any_given_kwargs(self, monkeypatch): -- my_mock = mock.MagicMock(return_value=[]) -+ my_mock = MagicMock(return_value=[]) - monkeypatch.setattr(check, "get_installed_distributions", my_mock) - - obj = object() ---- a/tests/unit/test_collector.py -+++ b/tests/unit/test_collector.py -@@ -4,10 +4,12 @@ import re - import uuid - from textwrap import dedent - --import mock -+try: -+ from unittest.mock import Mock, call, patch -+except ImportError: -+ from mock import Mock, call, patch - import pretend - import pytest --from mock import Mock, patch - from pip._vendor import html5lib, requests - from pip._vendor.six.moves.urllib import request as urllib_request - -@@ -46,7 +48,7 @@ def test_get_html_response_archive_to_na - does not allow "poking" without getting data. - """ - with pytest.raises(_NotHTTP): -- _get_html_response(url, session=mock.Mock(PipSession)) -+ _get_html_response(url, session=Mock(PipSession)) - - - @pytest.mark.parametrize( -@@ -56,15 +58,15 @@ def test_get_html_response_archive_to_na - ("https://pypi.org/pip-18.0.tar.gz", "application/gzip"), - ], - ) --@mock.patch("pip._internal.index.collector.raise_for_status") -+@patch("pip._internal.index.collector.raise_for_status") - def test_get_html_response_archive_to_http_scheme(mock_raise_for_status, url, - content_type): - """ - `_get_html_response()` should send a HEAD request on an archive-like URL - if the scheme supports it, and raise `_NotHTML` if the response isn't HTML. - """ -- session = mock.Mock(PipSession) -- session.head.return_value = mock.Mock(**{ -+ session = Mock(PipSession) -+ session.head.return_value = Mock(**{ - "request.method": "HEAD", - "headers": {"Content-Type": content_type}, - }) -@@ -73,7 +75,7 @@ def test_get_html_response_archive_to_ht - _get_html_response(url, session=session) - - session.assert_has_calls([ -- mock.call.head(url, allow_redirects=True), -+ call.head(url, allow_redirects=True), - ]) - mock_raise_for_status.assert_called_once_with(session.head.return_value) - assert ctx.value.args == (content_type, "HEAD") -@@ -93,7 +95,7 @@ def test_get_html_page_invalid_content_t - caplog.set_level(logging.WARNING) - link = Link(url) - -- session = mock.Mock(PipSession) -+ session = Mock(PipSession) - - assert _get_html_page(link, session=session) is None - assert ('pip._internal.index.collector', -@@ -111,7 +113,7 @@ def test_get_html_page_invalid_content_t - "https://pypi.org/pip-18.0.tar.gz", - ], - ) --@mock.patch("pip._internal.index.collector.raise_for_status") -+@patch("pip._internal.index.collector.raise_for_status") - def test_get_html_response_archive_to_http_scheme_is_html( - mock_raise_for_status, url - ): -@@ -119,25 +121,25 @@ def test_get_html_response_archive_to_ht - `_get_html_response()` should work with archive-like URLs if the HEAD - request is responded with text/html. - """ -- session = mock.Mock(PipSession) -- session.head.return_value = mock.Mock(**{ -+ session = Mock(PipSession) -+ session.head.return_value = Mock(**{ - "request.method": "HEAD", - "headers": {"Content-Type": "text/html"}, - }) -- session.get.return_value = mock.Mock(headers={"Content-Type": "text/html"}) -+ session.get.return_value = Mock(headers={"Content-Type": "text/html"}) - - resp = _get_html_response(url, session=session) - - assert resp is not None - assert session.mock_calls == [ -- mock.call.head(url, allow_redirects=True), -- mock.call.get(url, headers={ -+ call.head(url, allow_redirects=True), -+ call.get(url, headers={ - "Accept": "text/html", "Cache-Control": "max-age=0", - }), - ] - assert mock_raise_for_status.mock_calls == [ -- mock.call(session.head.return_value), -- mock.call(resp) -+ call(session.head.return_value), -+ call(resp) - ] - - -@@ -149,16 +151,16 @@ def test_get_html_response_archive_to_ht - "https://python.org/sitemap.xml", - ], - ) --@mock.patch("pip._internal.index.collector.raise_for_status") -+@patch("pip._internal.index.collector.raise_for_status") - def test_get_html_response_no_head(mock_raise_for_status, url): - """ - `_get_html_response()` shouldn't send a HEAD request if the URL does not - look like an archive, only the GET request that retrieves data. - """ -- session = mock.Mock(PipSession) -+ session = Mock(PipSession) - - # Mock the headers dict to ensure it is accessed. -- session.get.return_value = mock.Mock(headers=mock.Mock(**{ -+ session.get.return_value = Mock(headers=Mock(**{ - "get.return_value": "text/html", - })) - -@@ -167,25 +169,25 @@ def test_get_html_response_no_head(mock_ - assert resp is not None - assert session.head.call_count == 0 - assert session.get.mock_calls == [ -- mock.call(url, headers={ -+ call(url, headers={ - "Accept": "text/html", "Cache-Control": "max-age=0", - }), -- mock.call().headers.get("Content-Type", ""), -+ call().headers.get("Content-Type", ""), - ] - mock_raise_for_status.assert_called_once_with(resp) - - --@mock.patch("pip._internal.index.collector.raise_for_status") -+@patch("pip._internal.index.collector.raise_for_status") - def test_get_html_response_dont_log_clear_text_password(mock_raise_for_status, - caplog): - """ - `_get_html_response()` should redact the password from the index URL - in its DEBUG log message. - """ -- session = mock.Mock(PipSession) -+ session = Mock(PipSession) - - # Mock the headers dict to ensure it is accessed. -- session.get.return_value = mock.Mock(headers=mock.Mock(**{ -+ session.get.return_value = Mock(headers=Mock(**{ - "get.return_value": "text/html", - })) - -@@ -451,7 +453,7 @@ def test_parse_links_caches_same_page_by - assert 'pkg2' in parsed_links_3[0].url - - --@mock.patch("pip._internal.index.collector.raise_for_status") -+@patch("pip._internal.index.collector.raise_for_status") - def test_request_http_error(mock_raise_for_status, caplog): - caplog.set_level(logging.DEBUG) - link = Link('http://localhost') -@@ -504,7 +506,7 @@ def test_get_html_page_invalid_scheme(ca - Only file:, http:, https:, and ftp: are allowed. - """ - with caplog.at_level(logging.WARNING): -- page = _get_html_page(Link(url), session=mock.Mock(PipSession)) -+ page = _get_html_page(Link(url), session=Mock(PipSession)) - - assert page is None - assert caplog.record_tuples == [ -@@ -524,7 +526,7 @@ def test_get_html_page_invalid_scheme(ca - "application/json", - ], - ) --@mock.patch("pip._internal.index.collector.raise_for_status") -+@patch("pip._internal.index.collector.raise_for_status") - def test_get_html_page_invalid_content_type(mock_raise_for_status, - caplog, content_type): - """`_get_html_page()` should warn if an invalid content-type is given. -@@ -534,8 +536,8 @@ def test_get_html_page_invalid_content_t - url = 'https://pypi.org/simple/pip' - link = Link(url) - -- session = mock.Mock(PipSession) -- session.get.return_value = mock.Mock(**{ -+ session = Mock(PipSession) -+ session.get.return_value = Mock(**{ - "request.method": "GET", - "headers": {"Content-Type": content_type}, - }) -@@ -573,14 +575,14 @@ def test_get_html_page_directory_append_ - ) - expected_url = "{}/index.html".format(dir_url.rstrip("/")) - -- session = mock.Mock(PipSession) -+ session = Mock(PipSession) - fake_response = make_fake_html_response(expected_url) -- mock_func = mock.patch("pip._internal.index.collector._get_html_response") -+ mock_func = patch("pip._internal.index.collector._get_html_response") - with mock_func as mock_func: - mock_func.return_value = fake_response - actual = _get_html_page(Link(dir_url), session=session) - assert mock_func.mock_calls == [ -- mock.call(expected_url, session=session), -+ call(expected_url, session=session), - ], 'actual calls: {}'.format(mock_func.mock_calls) - - assert actual.content == fake_response.content ---- a/tests/unit/test_command_install.py -+++ b/tests/unit/test_command_install.py -@@ -1,7 +1,10 @@ - import errno - - import pytest --from mock import patch -+try: -+ from unittest.mock import patch -+except ImportError: -+ from mock import patch - from pip._vendor.packaging.requirements import Requirement - - from pip._internal.commands.install import ( ---- a/tests/unit/test_configuration.py -+++ b/tests/unit/test_configuration.py -@@ -4,7 +4,10 @@ - import os - - import pytest --from mock import MagicMock -+try: -+ from unittest.mock import MagicMock -+except ImportError: -+ from mock import MagicMock - - from pip._internal.configuration import get_configuration_files, kinds - from pip._internal.exceptions import ConfigurationError ---- a/tests/unit/test_direct_url_helpers.py -+++ b/tests/unit/test_direct_url_helpers.py -@@ -1,6 +1,9 @@ - from functools import partial - --from mock import MagicMock, patch -+try: -+ from unittest.mock import MagicMock, patch -+except ImportError: -+ from mock import MagicMock, patch - - from pip._internal.models.direct_url import ( - DIRECT_URL_METADATA_NAME, ---- a/tests/unit/test_finder.py -+++ b/tests/unit/test_finder.py -@@ -2,7 +2,10 @@ import logging - import sys - - import pytest --from mock import Mock, patch -+try: -+ from unittest.mock import Mock, patch -+except ImportError: -+ from mock import Mock, patch - from pip._vendor.packaging.specifiers import SpecifierSet - from pip._vendor.packaging.tags import Tag - from pkg_resources import parse_version ---- a/tests/unit/test_locations.py -+++ b/tests/unit/test_locations.py -@@ -9,7 +9,10 @@ import sys - import tempfile - - import pytest --from mock import Mock -+try: -+ from unittest.mock import Mock -+except ImportError: -+ from mock import Mock - - from pip._internal.locations import distutils_scheme - ---- a/tests/unit/test_logging.py -+++ b/tests/unit/test_logging.py -@@ -5,7 +5,10 @@ import time - from threading import Thread - - import pytest --from mock import patch -+try: -+ from unittest.mock import patch -+except ImportError: -+ from mock import patch - from pip._vendor.six import PY2 - - from pip._internal.utils.logging import ( ---- a/tests/unit/test_operations_prepare.py -+++ b/tests/unit/test_operations_prepare.py -@@ -4,7 +4,10 @@ from shutil import rmtree - from tempfile import mkdtemp - - import pytest --from mock import Mock, patch -+try: -+ from unittest.mock import Mock, patch -+except ImportError: -+ from mock import Mock, patch - - from pip._internal.exceptions import HashMismatch - from pip._internal.models.link import Link ---- a/tests/unit/test_req.py -+++ b/tests/unit/test_req.py -@@ -6,7 +6,10 @@ import tempfile - from functools import partial - - import pytest --from mock import patch -+try: -+ from unittest.mock import patch -+except ImportError: -+ from mock import patch - from pip._vendor import pkg_resources - from pip._vendor.packaging.markers import Marker - from pip._vendor.packaging.requirements import Requirement ---- a/tests/unit/test_req_uninstall.py -+++ b/tests/unit/test_req_uninstall.py -@@ -2,7 +2,10 @@ import os - import sys - - import pytest --from mock import Mock -+try: -+ from unittest.mock import Mock -+except ImportError: -+ from mock import Mock - - import pip._internal.req.req_uninstall - from pip._internal.req.req_uninstall import (