1
1
Fork 0
mirror of https://github.com/pypa/pip synced 2023-12-13 21:30:23 +01:00

Merge branch 'main' into per-req-config-settings

This commit is contained in:
q0w 2023-03-27 16:57:49 +03:00
commit c8b017dd34
18 changed files with 130 additions and 79 deletions

View file

@ -74,9 +74,9 @@ intersphinx_mapping = {
# -- Options for extlinks -------------------------------------------------------------
extlinks = {
"issue": ("https://github.com/pypa/pip/issues/%s", "#"),
"pull": ("https://github.com/pypa/pip/pull/%s", "PR #"),
"pypi": ("https://pypi.org/project/%s/", ""),
"issue": ("https://github.com/pypa/pip/issues/%s", "#%s"),
"pull": ("https://github.com/pypa/pip/pull/%s", "PR #%s"),
"pypi": ("https://pypi.org/project/%s/", "%s"),
}
# -- Options for towncrier_draft extension --------------------------------------------

View file

@ -23,7 +23,7 @@ The report is a JSON object with the following properties:
- `pip_version`: a string with the version of pip used to produce the report.
- `installed`: an array of [InspectReportItem](InspectReportItem) representing the
- `installed`: an array of [`InspectReportItem`](InspectReportItem) representing the
distribution packages that are installed.
- `environment`: an object describing the environment where the installation report was
@ -50,10 +50,11 @@ the following properties:
```
- `direct_url`: Information about the direct URL that was used for installation, if any,
using the [direct
URL](https://packaging.python.org/en/latest/specifications/direct-url/) data
structure. In most case, this field corresponds to the `direct_url.json` metadata,
except for legacy editable installs, where it is emulated.
using the [direct URL data
structure](https://packaging.python.org/en/latest/specifications/direct-url-data-structure/).
In most case, this field corresponds to the
[`direct_url.json`](https://packaging.python.org/en/latest/specifications/direct-url)
metadata, except for legacy editable installs, where it is emulated.
- `requested`: `true` if the `REQUESTED` metadata is present, `false` otherwise. This
field is only present for modern `.dist-info` installations.

View file

@ -36,7 +36,7 @@ The report is a JSON object with the following properties:
- `pip_version`: a string with the version of pip used to produce the report.
- `install`: an array of [InstallationReportItem](InstallationReportItem) representing
- `install`: an array of [`InstallationReportItem`](InstallationReportItem) representing
the distribution packages (to be) installed.
- `environment`: an object describing the environment where the installation report was
@ -58,9 +58,10 @@ package with the following properties:
specifier.
- `download_info`: Information about the artifact (to be) downloaded for installation,
using the [direct
URL](https://packaging.python.org/en/latest/specifications/direct-url/) data
structure. When `is_direct` is `true`, this field is the same as the `direct_url.json`
using the [direct URL data
structure](https://packaging.python.org/en/latest/specifications/direct-url-data-structure/).
When `is_direct` is `true`, this field is the same as the
[`direct_url.json`](https://packaging.python.org/en/latest/specifications/direct-url)
metadata, otherwise it represents the URL of the artifact obtained from the index or
`--find-links`.

1
news/10937.feature.rst Normal file
View file

@ -0,0 +1 @@
Present conflict information during installation after each choice that is rejected (pass ``-vv`` to ``pip install`` to show it)

1
news/11882.bugfix.rst Normal file
View file

@ -0,0 +1 @@
Include ``AUTHORS.txt`` in pip's wheels.

View file

@ -1 +1 @@
Upgrade resolvelib to 0.9.0
Upgrade resolvelib to 1.0.1

View file

@ -111,6 +111,3 @@ exclude_lines =
pragma: no cover
# This excludes typing-specific code, which will be validated by mypy anyway.
if TYPE_CHECKING
[metadata]
license_file = LICENSE.txt

View file

@ -412,7 +412,7 @@ class RequirementCommand(IndexGroupCommand):
for req in args:
req_to_add = install_req_from_line(
req,
None,
comes_from=None,
isolated=options.isolated_mode,
use_pep517=options.use_pep517,
user_supplied=True,

View file

@ -11,7 +11,7 @@ InstallRequirement.
import logging
import os
import re
from typing import Any, Dict, Optional, Set, Tuple, Union
from typing import Dict, List, Optional, Set, Tuple, Union
from pip._vendor.packaging.markers import Marker
from pip._vendor.packaging.requirements import InvalidRequirement, Requirement
@ -201,13 +201,15 @@ def parse_req_from_editable(editable_req: str) -> RequirementParts:
def install_req_from_editable(
editable_req: str,
comes_from: Optional[Union[InstallRequirement, str]] = None,
*,
use_pep517: Optional[bool] = None,
isolated: bool = False,
options: Optional[Dict[str, Any]] = None,
global_options: Optional[List[str]] = None,
hash_options: Optional[Dict[str, List[str]]] = None,
constraint: bool = False,
user_supplied: bool = False,
permit_editable_wheels: bool = False,
config_settings: Optional[Dict[str, str]] = None,
config_settings: Optional[Dict[str, Union[str, List[str]]]] = None,
) -> InstallRequirement:
parts = parse_req_from_editable(editable_req)
@ -222,8 +224,8 @@ def install_req_from_editable(
constraint=constraint,
use_pep517=use_pep517,
isolated=isolated,
global_options=options.get("global_options", []) if options else [],
hash_options=options.get("hashes", {}) if options else {},
global_options=global_options,
hash_options=hash_options,
config_settings=config_settings,
extras=parts.extras,
)
@ -375,13 +377,15 @@ def parse_req_from_line(name: str, line_source: Optional[str]) -> RequirementPar
def install_req_from_line(
name: str,
comes_from: Optional[Union[str, InstallRequirement]] = None,
*,
use_pep517: Optional[bool] = None,
isolated: bool = False,
options: Optional[Dict[str, Any]] = None,
global_options: Optional[List[str]] = None,
hash_options: Optional[Dict[str, List[str]]] = None,
constraint: bool = False,
line_source: Optional[str] = None,
user_supplied: bool = False,
config_settings: Optional[Dict[str, str]] = None,
config_settings: Optional[Dict[str, Union[str, List[str]]]] = None,
) -> InstallRequirement:
"""Creates an InstallRequirement from a name, which might be a
requirement, directory containing 'setup.py', filename, or URL.
@ -398,8 +402,8 @@ def install_req_from_line(
markers=parts.markers,
use_pep517=use_pep517,
isolated=isolated,
global_options=options.get("global_options", []) if options else [],
hash_options=options.get("hashes", {}) if options else {},
global_options=global_options,
hash_options=hash_options,
config_settings=config_settings,
constraint=constraint,
extras=parts.extras,
@ -413,7 +417,7 @@ def install_req_from_req_string(
isolated: bool = False,
use_pep517: Optional[bool] = None,
user_supplied: bool = False,
config_settings: Optional[Dict[str, str]] = None,
config_settings: Optional[Dict[str, Union[str, List[str]]]] = None,
) -> InstallRequirement:
try:
req = get_requirement(req_string)
@ -452,7 +456,6 @@ def install_req_from_parsed_requirement(
isolated: bool = False,
use_pep517: Optional[bool] = None,
user_supplied: bool = False,
config_settings: Optional[Dict[str, str]] = None,
) -> InstallRequirement:
if parsed_req.is_editable:
req = install_req_from_editable(
@ -462,7 +465,6 @@ def install_req_from_parsed_requirement(
constraint=parsed_req.constraint,
isolated=isolated,
user_supplied=user_supplied,
config_settings=config_settings,
)
else:
@ -471,11 +473,17 @@ def install_req_from_parsed_requirement(
comes_from=parsed_req.comes_from,
use_pep517=use_pep517,
isolated=isolated,
options=parsed_req.options,
global_options=(
parsed_req.options.get("global_options", [])
if parsed_req.options
else []
),
hash_options=(
parsed_req.options.get("hashes", {}) if parsed_req.options else {}
),
constraint=parsed_req.constraint,
line_source=parsed_req.line_source,
user_supplied=user_supplied,
config_settings=config_settings,
)
return req

View file

@ -85,7 +85,7 @@ class InstallRequirement:
*,
global_options: Optional[List[str]] = None,
hash_options: Optional[Dict[str, List[str]]] = None,
config_settings: Optional[Dict[str, str]] = None,
config_settings: Optional[Dict[str, Union[str, List[str]]]] = None,
constraint: bool = False,
extras: Collection[str] = (),
user_supplied: bool = False,

View file

@ -65,10 +65,8 @@ def make_install_req_from_link(
use_pep517=template.use_pep517,
isolated=template.isolated,
constraint=template.constraint,
options=dict(
global_options=template.global_options,
hashes=template.hash_options,
),
global_options=template.global_options,
hash_options=template.hash_options,
config_settings=template.config_settings,
)
ireq.original_link = template.original_link
@ -88,10 +86,8 @@ def make_install_req_from_editable(
isolated=template.isolated,
constraint=template.constraint,
permit_editable_wheels=template.permit_editable_wheels,
options=dict(
global_options=template.global_options,
hashes=template.hash_options,
),
global_options=template.global_options,
hash_options=template.hash_options,
config_settings=template.config_settings,
)
@ -112,10 +108,8 @@ def _make_install_req_from_dist(
use_pep517=template.use_pep517,
isolated=template.isolated,
constraint=template.constraint,
options=dict(
global_options=template.global_options,
hashes=template.hash_options,
),
global_options=template.global_options,
hash_options=template.hash_options,
config_settings=template.config_settings,
)
ireq.satisfied_by = dist

View file

@ -42,6 +42,18 @@ class PipReporter(BaseReporter):
message = self._messages_at_reject_count[count]
logger.info("INFO: %s", message.format(package_name=candidate.name))
msg = "Will try a different candidate, due to conflict:"
for req_info in criterion.information:
req, parent = req_info.requirement, req_info.parent
# Inspired by Factory.get_installation_error
msg += "\n "
if parent:
msg += f"{parent.name} {parent.version} depends on "
else:
msg += "The user requested "
msg += req.format_for_error()
logger.debug(msg)
class PipDebuggingReporter(BaseReporter):
"""A reporter that does an info log for every event it sees."""

View file

@ -672,7 +672,7 @@ class ConfiguredBuildBackendHookCaller(BuildBackendHookCaller):
def build_wheel(
self,
wheel_directory: str,
config_settings: Optional[Dict[str, str]] = None,
config_settings: Optional[Dict[str, Union[str, List[str]]]] = None,
metadata_directory: Optional[str] = None,
) -> str:
cs = self.config_holder.config_settings
@ -681,7 +681,9 @@ class ConfiguredBuildBackendHookCaller(BuildBackendHookCaller):
)
def build_sdist(
self, sdist_directory: str, config_settings: Optional[Dict[str, str]] = None
self,
sdist_directory: str,
config_settings: Optional[Dict[str, Union[str, List[str]]]] = None,
) -> str:
cs = self.config_holder.config_settings
return super().build_sdist(sdist_directory, config_settings=cs)
@ -689,7 +691,7 @@ class ConfiguredBuildBackendHookCaller(BuildBackendHookCaller):
def build_editable(
self,
wheel_directory: str,
config_settings: Optional[Dict[str, str]] = None,
config_settings: Optional[Dict[str, Union[str, List[str]]]] = None,
metadata_directory: Optional[str] = None,
) -> str:
cs = self.config_holder.config_settings
@ -698,19 +700,19 @@ class ConfiguredBuildBackendHookCaller(BuildBackendHookCaller):
)
def get_requires_for_build_wheel(
self, config_settings: Optional[Dict[str, str]] = None
self, config_settings: Optional[Dict[str, Union[str, List[str]]]] = None
) -> List[str]:
cs = self.config_holder.config_settings
return super().get_requires_for_build_wheel(config_settings=cs)
def get_requires_for_build_sdist(
self, config_settings: Optional[Dict[str, str]] = None
self, config_settings: Optional[Dict[str, Union[str, List[str]]]] = None
) -> List[str]:
cs = self.config_holder.config_settings
return super().get_requires_for_build_sdist(config_settings=cs)
def get_requires_for_build_editable(
self, config_settings: Optional[Dict[str, str]] = None
self, config_settings: Optional[Dict[str, Union[str, List[str]]]] = None
) -> List[str]:
cs = self.config_holder.config_settings
return super().get_requires_for_build_editable(config_settings=cs)
@ -718,7 +720,7 @@ class ConfiguredBuildBackendHookCaller(BuildBackendHookCaller):
def prepare_metadata_for_build_wheel(
self,
metadata_directory: str,
config_settings: Optional[Dict[str, str]] = None,
config_settings: Optional[Dict[str, Union[str, List[str]]]] = None,
_allow_fallback: bool = True,
) -> str:
cs = self.config_holder.config_settings
@ -731,7 +733,7 @@ class ConfiguredBuildBackendHookCaller(BuildBackendHookCaller):
def prepare_metadata_for_build_editable(
self,
metadata_directory: str,
config_settings: Optional[Dict[str, str]] = None,
config_settings: Optional[Dict[str, Union[str, List[str]]]] = None,
_allow_fallback: bool = True,
) -> str:
cs = self.config_holder.config_settings

View file

@ -11,7 +11,7 @@ __all__ = [
"ResolutionTooDeep",
]
__version__ = "0.9.0"
__version__ = "1.0.1"
from .providers import AbstractProvider, AbstractResolver

View file

@ -1,4 +1,5 @@
import collections
import itertools
import operator
from .providers import AbstractResolver
@ -191,8 +192,8 @@ class Resolution(object):
information
for information in criterion.information
if (
information[1] is None
or self._p.identify(information[1]) not in parents
information.parent is None
or self._p.identify(information.parent) not in parents
)
],
criterion.incompatibilities,
@ -266,8 +267,8 @@ class Resolution(object):
# end, signal for backtracking.
return causes
def _backtrack(self):
"""Perform backtracking.
def _backjump(self, causes):
"""Perform backjumping.
When we enter here, the stack is like this::
@ -283,22 +284,46 @@ class Resolution(object):
Each iteration of the loop will:
1. Discard Z.
2. Discard Y but remember its incompatibility information gathered
1. Identify Z. The incompatibility is not always caused by the latest
state. For example, given three requirements A, B and C, with
dependencies A1, B1 and C1, where A1 and B1 are incompatible: the
last state might be related to C, so we want to discard the
previous state.
2. Discard Z.
3. Discard Y but remember its incompatibility information gathered
previously, and the failure we're dealing with right now.
3. Push a new state Y' based on X, and apply the incompatibility
4. Push a new state Y' based on X, and apply the incompatibility
information from Y to Y'.
4a. If this causes Y' to conflict, we need to backtrack again. Make Y'
5a. If this causes Y' to conflict, we need to backtrack again. Make Y'
the new Z and go back to step 2.
4b. If the incompatibilities apply cleanly, end backtracking.
5b. If the incompatibilities apply cleanly, end backtracking.
"""
incompatible_reqs = itertools.chain(
(c.parent for c in causes if c.parent is not None),
(c.requirement for c in causes),
)
incompatible_deps = {self._p.identify(r) for r in incompatible_reqs}
while len(self._states) >= 3:
# Remove the state that triggered backtracking.
del self._states[-1]
# Retrieve the last candidate pin and known incompatibilities.
broken_state = self._states.pop()
name, candidate = broken_state.mapping.popitem()
# Ensure to backtrack to a state that caused the incompatibility
incompatible_state = False
while not incompatible_state:
# Retrieve the last candidate pin and known incompatibilities.
try:
broken_state = self._states.pop()
name, candidate = broken_state.mapping.popitem()
except (IndexError, KeyError):
raise ResolutionImpossible(causes)
current_dependencies = {
self._p.identify(d)
for d in self._p.get_dependencies(candidate)
}
incompatible_state = not current_dependencies.isdisjoint(
incompatible_deps
)
incompatibilities_from_broken = [
(k, list(v.incompatibilities))
for k, v in broken_state.criteria.items()
@ -403,10 +428,10 @@ class Resolution(object):
if failure_causes:
causes = [i for c in failure_causes for i in c.information]
# Backtrack if pinning fails. The backtrack process puts us in
# Backjump if pinning fails. The backjump process puts us in
# an unpinned state, so we can work on it in the next round.
self._r.resolving_conflicts(causes=causes)
success = self._backtrack()
success = self._backjump(causes)
self.state.backtrack_causes[:] = causes
# Dead ends everywhere. Give up.

View file

@ -15,7 +15,7 @@ requests==2.28.2
rich==12.6.0
pygments==2.13.0
typing_extensions==4.4.0
resolvelib==0.9.0
resolvelib==1.0.1
setuptools==65.6.3
six==1.16.0
tenacity==8.1.0

View file

@ -342,6 +342,15 @@ def test_pip_wheel_with_user_set_in_config(
sys.platform.startswith("win"),
reason="The empty extension module does not work on Win",
)
@pytest.mark.xfail(
condition=sys.platform == "darwin" and sys.version_info < (3, 9),
reason=(
"Unexplained 'no module named platform' in "
"https://github.com/pypa/wheel/blob"
"/c87e6ed82b58b41b258a3e8c852af8bc1817bb00"
"/src/wheel/vendored/packaging/tags.py#L396-L411"
),
)
def test_pip_wheel_ext_module_with_tmpdir_inside(
script: PipTestEnvironment, data: TestData, common_wheels: Path
) -> None:

View file

@ -63,7 +63,7 @@ def test_duplicates_sort_ok(data: TestData) -> None:
def test_finder_detects_latest_find_links(data: TestData) -> None:
"""Test PackageFinder detects latest using find-links"""
req = install_req_from_line("simple", None)
req = install_req_from_line("simple")
finder = make_test_finder(find_links=[data.find_links])
found = finder.find_requirement(req, False)
assert found is not None
@ -72,7 +72,7 @@ def test_finder_detects_latest_find_links(data: TestData) -> None:
def test_incorrect_case_file_index(data: TestData) -> None:
"""Test PackageFinder detects latest using wrong case"""
req = install_req_from_line("dinner", None)
req = install_req_from_line("dinner")
finder = make_test_finder(index_urls=[data.find_links3])
found = finder.find_requirement(req, False)
assert found is not None
@ -82,7 +82,7 @@ def test_incorrect_case_file_index(data: TestData) -> None:
@pytest.mark.network
def test_finder_detects_latest_already_satisfied_find_links(data: TestData) -> None:
"""Test PackageFinder detects latest already satisfied using find-links"""
req = install_req_from_line("simple", None)
req = install_req_from_line("simple")
# the latest simple in local pkgs is 3.0
latest_version = "3.0"
satisfied_by = Mock(
@ -99,7 +99,7 @@ def test_finder_detects_latest_already_satisfied_find_links(data: TestData) -> N
@pytest.mark.network
def test_finder_detects_latest_already_satisfied_pypi_links() -> None:
"""Test PackageFinder detects latest already satisfied using pypi links"""
req = install_req_from_line("initools", None)
req = install_req_from_line("initools")
# the latest initools on PyPI is 0.3.1
latest_version = "0.3.1"
satisfied_by = Mock(
@ -180,7 +180,7 @@ class TestWheel:
Test existing install has priority over wheels.
`test_link_sorting` also covers this at a lower level
"""
req = install_req_from_line("priority", None)
req = install_req_from_line("priority")
latest_version = "1.0"
satisfied_by = Mock(
location="/path",
@ -309,7 +309,7 @@ class TestCandidateEvaluator:
def test_finder_priority_file_over_page(data: TestData) -> None:
"""Test PackageFinder prefers file links over equivalent page links"""
req = install_req_from_line("gmpy==1.15", None)
req = install_req_from_line("gmpy==1.15")
finder = make_test_finder(
find_links=[data.find_links],
index_urls=["http://pypi.org/simple/"],
@ -328,7 +328,7 @@ def test_finder_priority_file_over_page(data: TestData) -> None:
def test_finder_priority_nonegg_over_eggfragments() -> None:
"""Test PackageFinder prefers non-egg links over "#egg=" links"""
req = install_req_from_line("bar==1.0", None)
req = install_req_from_line("bar==1.0")
links = ["http://foo/bar.py#egg=bar-1.0", "http://foo/bar-1.0.tar.gz"]
finder = make_test_finder(links)
@ -358,7 +358,7 @@ def test_finder_only_installs_stable_releases(data: TestData) -> None:
Test PackageFinder only accepts stable versioned releases by default.
"""
req = install_req_from_line("bar", None)
req = install_req_from_line("bar")
# using a local index (that has pre & dev releases)
finder = make_test_finder(index_urls=[data.index_url("pre")])
@ -404,7 +404,7 @@ def test_finder_installs_pre_releases(data: TestData) -> None:
Test PackageFinder finds pre-releases if asked to.
"""
req = install_req_from_line("bar", None)
req = install_req_from_line("bar")
# using a local index (that has pre & dev releases)
finder = make_test_finder(
@ -436,7 +436,7 @@ def test_finder_installs_dev_releases(data: TestData) -> None:
Test PackageFinder finds dev releases if asked to.
"""
req = install_req_from_line("bar", None)
req = install_req_from_line("bar")
# using a local index (that has dev releases)
finder = make_test_finder(
@ -452,7 +452,7 @@ def test_finder_installs_pre_releases_with_version_spec() -> None:
"""
Test PackageFinder only accepts stable versioned releases by default.
"""
req = install_req_from_line("bar>=0.0.dev0", None)
req = install_req_from_line("bar>=0.0.dev0")
links = ["https://foo/bar-1.0.tar.gz", "https://foo/bar-2.0b1.tar.gz"]
finder = make_test_finder(links)