Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release 20.2.2 #8746

Merged
merged 8 commits into from
Aug 11, 2020
19 changes: 19 additions & 0 deletions NEWS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,25 @@

.. towncrier release notes start

20.2.2 (2020-08-11)
===================

Bug Fixes
---------

- Only attempt to use the keyring once and if it fails, don't try again.
This prevents spamming users with several keyring unlock prompts when they
cannot unlock or don't want to do so. (`#8090 <https://github.com/pypa/pip/issues/8090>`_)
- Fix regression that distributions in system site-packages are not correctly
found when a virtual environment is configured with ``system-site-packages``
on. (`#8695 <https://github.com/pypa/pip/issues/8695>`_)
- Disable caching for range requests, which causes corrupted wheels
when pip tries to obtain metadata using the feature ``fast-deps``. (`#8701 <https://github.com/pypa/pip/issues/8701>`_, `#8716 <https://github.com/pypa/pip/issues/8716>`_)
- Always use UTF-8 to read ``pyvenv.cfg`` to match the built-in ``venv``. (`#8717 <https://github.com/pypa/pip/issues/8717>`_)
- 2020 Resolver: Correctly handle marker evaluation in constraints and exclude
them if their markers do not match the current environment. (`#8724 <https://github.com/pypa/pip/issues/8724>`_)


20.2.1 (2020-08-04)
===================

Expand Down
2 changes: 1 addition & 1 deletion src/pip/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from typing import List, Optional


__version__ = "20.2.1"
__version__ = "20.3.dev0"


def main(args=None):
Expand Down
1 change: 1 addition & 0 deletions src/pip/_internal/commands/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ def print_results(hits, name_column_width=None, terminal_width=None):
write_output(line)
if name in installed_packages:
dist = get_distribution(name)
assert dist is not None
with indent_log():
if dist.version == latest:
write_output('INSTALLED: %s (latest)', dist.version)
Expand Down
2 changes: 2 additions & 0 deletions src/pip/_internal/network/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
def get_keyring_auth(url, username):
# type: (str, str) -> Optional[AuthInfo]
"""Return the tuple auth for a given url from keyring."""
global keyring
if not url or not keyring:
return None

Expand All @@ -69,6 +70,7 @@ def get_keyring_auth(url, username):
logger.warning(
"Keyring is skipped due to an exception: %s", str(exc),
)
keyring = None
return None


Expand Down
6 changes: 4 additions & 2 deletions src/pip/_internal/network/lazy_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,10 @@ def _check_zip(self):
def _stream_response(self, start, end, base_headers=HEADERS):
# type: (int, int, Dict[str, str]) -> Response
"""Return HTTP response to a range request from start to end."""
headers = {'Range': 'bytes={}-{}'.format(start, end)}
headers.update(base_headers)
headers = base_headers.copy()
headers['Range'] = 'bytes={}-{}'.format(start, end)
# TODO: Get range requests to be correctly cached
headers['Cache-Control'] = 'no-cache'
return self._session.get(self._url, headers=headers, stream=True)

def _merge(self, start, end, left, right):
Expand Down
3 changes: 2 additions & 1 deletion src/pip/_internal/resolution/resolvelib/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ def resolve(self, root_reqs, check_supported_wheels):
problem = check_invalid_constraint_type(req)
if problem:
raise InstallationError(problem)

if not req.match_markers():
continue
name = canonicalize_name(req.name)
if name in constraints:
constraints[name] = constraints[name] & req.specifier
Expand Down
27 changes: 22 additions & 5 deletions src/pip/_internal/utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,22 +483,39 @@ def user_test(d):
]


def search_distribution(req_name):
def _search_distribution(req_name):
# type: (str) -> Optional[Distribution]
"""Find a distribution matching the ``req_name`` in the environment.

This searches from *all* distributions available in the environment, to
match the behavior of ``pkg_resources.get_distribution()``.
"""
# Canonicalize the name before searching in the list of
# installed distributions and also while creating the package
# dictionary to get the Distribution object
req_name = canonicalize_name(req_name)
packages = get_installed_distributions(skip=())
packages = get_installed_distributions(
local_only=False,
skip=(),
include_editables=True,
editables_only=False,
user_only=False,
paths=None,
)
pkg_dict = {canonicalize_name(p.key): p for p in packages}
return pkg_dict.get(req_name)


def get_distribution(req_name):
"""Given a requirement name, return the installed Distribution object"""
# type: (str) -> Optional[Distribution]
"""Given a requirement name, return the installed Distribution object.

This searches from *all* distributions available in the environment, to
match the behavior of ``pkg_resources.get_distribution()``.
"""

# Search the distribution by looking through the working set
dist = search_distribution(req_name)
dist = _search_distribution(req_name)

# If distribution could not be found, call working_set.require
# to update the working set, and try to find the distribution
Expand All @@ -514,7 +531,7 @@ def get_distribution(req_name):
pkg_resources.working_set.require(req_name)
except pkg_resources.DistributionNotFound:
return None
return search_distribution(req_name)
return _search_distribution(req_name)


def egg_link_path(dist):
Expand Down
5 changes: 4 additions & 1 deletion src/pip/_internal/utils/virtualenv.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import absolute_import

import io
import logging
import os
import re
Expand Down Expand Up @@ -51,7 +52,9 @@ def _get_pyvenv_cfg_lines():
"""
pyvenv_cfg_file = os.path.join(sys.prefix, 'pyvenv.cfg')
try:
with open(pyvenv_cfg_file) as f:
# Although PEP 405 does not specify, the built-in venv module always
# writes with UTF-8. (pypa/pip#8717)
with io.open(pyvenv_cfg_file, encoding='utf-8') as f:
return f.read().splitlines() # avoids trailing newlines
except IOError:
return None
Expand Down
25 changes: 25 additions & 0 deletions tests/functional/test_new_resolver.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
import os
import sys
import textwrap

import pytest
from pip._vendor.packaging.utils import canonicalize_name
Expand Down Expand Up @@ -729,6 +730,30 @@ def test_new_resolver_constraint_on_path(script):
assert msg in result.stderr, str(result)


def test_new_resolver_constraint_only_marker_match(script):
create_basic_wheel_for_package(script, "pkg", "1.0")
create_basic_wheel_for_package(script, "pkg", "2.0")
create_basic_wheel_for_package(script, "pkg", "3.0")

constrants_content = textwrap.dedent(
"""
pkg==1.0; python_version == "{ver[0]}.{ver[1]}" # Always satisfies.
pkg==2.0; python_version < "0" # Never satisfies.
"""
).format(ver=sys.version_info)
constraints_txt = script.scratch_path / "constraints.txt"
constraints_txt.write_text(constrants_content)

script.pip(
"install", "--use-feature=2020-resolver",
"--no-cache-dir", "--no-index",
"-c", constraints_txt,
"--find-links", script.scratch_path,
"pkg",
)
assert_installed(script, pkg="1.0")


def test_new_resolver_upgrade_needs_option(script):
# Install pkg 1.0.0
create_basic_wheel_for_package(script, "pkg", "1.0.0")
Expand Down
26 changes: 26 additions & 0 deletions tests/unit/test_network_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,3 +242,29 @@ def test_keyring_get_credential(monkeypatch, url, expect):
assert auth._get_new_credentials(
url, allow_netrc=False, allow_keyring=True
) == expect


class KeyringModuleBroken(object):
"""Represents the current supported API of keyring, but broken"""

def __init__(self):
self._call_count = 0

def get_credential(self, system, username):
self._call_count += 1
raise Exception("This keyring is broken!")


def test_broken_keyring_disables_keyring(monkeypatch):
keyring_broken = KeyringModuleBroken()
monkeypatch.setattr(pip._internal.network.auth, 'keyring', keyring_broken)

auth = MultiDomainBasicAuth(index_urls=["http://example.com/"])

assert keyring_broken._call_count == 0
for i in range(5):
url = "http://example.com/path" + str(i)
assert auth._get_new_credentials(
url, allow_netrc=False, allow_keyring=True
) == (None, None)
assert keyring_broken._call_count == 1
74 changes: 60 additions & 14 deletions tests/unit/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

"""
import codecs
import itertools
import os
import shutil
import stat
Expand Down Expand Up @@ -34,6 +35,7 @@
build_url_from_netloc,
egg_link_path,
format_size,
get_distribution,
get_installed_distributions,
get_prog,
hide_url,
Expand Down Expand Up @@ -192,26 +194,30 @@ def test_noegglink_in_sitepkgs_venv_global(self):
@patch('pip._internal.utils.misc.dist_in_usersite')
@patch('pip._internal.utils.misc.dist_is_local')
@patch('pip._internal.utils.misc.dist_is_editable')
class Tests_get_installed_distributions:
"""test util.get_installed_distributions"""

workingset = [
Mock(test_name="global"),
Mock(test_name="editable"),
Mock(test_name="normal"),
Mock(test_name="user"),
]

workingset_stdlib = [
class TestsGetDistributions(object):
"""Test get_installed_distributions() and get_distribution().
"""
class MockWorkingSet(list):
def require(self, name):
pass

workingset = MockWorkingSet((
Mock(test_name="global", key="global"),
Mock(test_name="editable", key="editable"),
Mock(test_name="normal", key="normal"),
Mock(test_name="user", key="user"),
))

workingset_stdlib = MockWorkingSet((
Mock(test_name='normal', key='argparse'),
Mock(test_name='normal', key='wsgiref')
]
))

workingset_freeze = [
workingset_freeze = MockWorkingSet((
Mock(test_name='normal', key='pip'),
Mock(test_name='normal', key='setuptools'),
Mock(test_name='normal', key='distribute')
]
))

def dist_is_editable(self, dist):
return dist.test_name == "editable"
Expand Down Expand Up @@ -287,6 +293,46 @@ def test_freeze_excludes(self, mock_dist_is_editable,
skip=('setuptools', 'pip', 'distribute'))
assert len(dists) == 0

@pytest.mark.parametrize(
"working_set, req_name",
itertools.chain(
itertools.product([workingset], (d.key for d in workingset)),
itertools.product(
[workingset_stdlib], (d.key for d in workingset_stdlib),
),
),
)
def test_get_distribution(
self,
mock_dist_is_editable,
mock_dist_is_local,
mock_dist_in_usersite,
working_set,
req_name,
):
"""Ensure get_distribution() finds all kinds of distributions.
"""
mock_dist_is_editable.side_effect = self.dist_is_editable
mock_dist_is_local.side_effect = self.dist_is_local
mock_dist_in_usersite.side_effect = self.dist_in_usersite
with patch("pip._vendor.pkg_resources.working_set", working_set):
dist = get_distribution(req_name)
assert dist is not None
assert dist.key == req_name

@patch('pip._vendor.pkg_resources.working_set', workingset)
def test_get_distribution_nonexist(
self,
mock_dist_is_editable,
mock_dist_is_local,
mock_dist_in_usersite,
):
mock_dist_is_editable.side_effect = self.dist_is_editable
mock_dist_is_local.side_effect = self.dist_is_local
mock_dist_in_usersite.side_effect = self.dist_in_usersite
dist = get_distribution("non-exist")
assert dist is None


def test_rmtree_errorhandler_nonexistent_directory(tmpdir):
"""
Expand Down