Skip to content

Commit d60abab

Browse files
authored
Merge branch 'main' into add-docs-for-platform-and-python-version
2 parents 9c804ed + c3f08f0 commit d60abab

File tree

23 files changed

+361
-122
lines changed

23 files changed

+361
-122
lines changed

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636

3737
steps:
3838
- name: Download all the dists
39-
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4
39+
uses: actions/download-artifact@cc203385981b70ca67e1cc392babf9cc229d5806 # v4
4040
with:
4141
name: python-package-distributions
4242
path: dist/

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ repos:
2222
- id: black
2323

2424
- repo: https://github.com/astral-sh/ruff-pre-commit
25-
rev: v0.9.5
25+
rev: v0.9.9
2626
hooks:
2727
- id: ruff
2828
args: [--fix, --exit-non-zero-on-fix]

docs/html/topics/more-dependency-resolution.md

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ operations:
132132
* `get_preference` - this provides information to the resolver to help it choose
133133
which requirement to look at "next" when working through the resolution
134134
process.
135+
* `narrow_requirement_selection` - this provides a way to limit the number of
136+
identifiers passed to `get_preference`.
135137
* `find_matches` - given a set of constraints, determine what candidates exist
136138
that satisfy them. This is essentially where the finder interacts with the
137139
resolver.
@@ -140,19 +142,26 @@ operations:
140142
* `get_dependencies` - get the dependency metadata for a candidate. This is
141143
the implementation of the process of getting and reading package metadata.
142144

143-
Of these methods, the only non-trivial one is the `get_preference` method. This
144-
implements the heuristics used to guide the resolution, telling it which
145-
requirement to try to satisfy next. It's this method that is responsible for
146-
trying to guess which route through the dependency tree will be most productive.
147-
As noted above, it's doing this with limited information. See the following
148-
diagram
145+
Of these methods, the only non-trivial ones are the `get_preference` and
146+
`narrow_requirement_selection` methods. These implement heuristics used
147+
to guide the resolution, telling it which requirement to try to satisfy next.
148+
It's these methods that are responsible for trying to guess which route through
149+
the dependency tree will be most productive. As noted above, it's doing this
150+
with limited information. See the following diagram:
149151

150152
![](deps.png)
151153

152154
When the provider is asked to choose between the red requirements (A->B and
153155
A->C) it doesn't know anything about the dependencies of B or C (i.e., the
154156
grey parts of the graph).
155157

158+
Pip's current implementation of the provider implements
159+
`narrow_requirement_selection` as follows:
160+
161+
* If Requires-Python is present only consider that
162+
* If there are causes of resolution conflict (backtrack causes) then
163+
only consider them until there are no longer any resolution conflicts
164+
156165
Pip's current implementation of the provider implements `get_preference` as
157166
follows:
158167

news/12718.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Disable Git and SSH prompts when ``--no-input`` is passed.

news/13135.feature.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Use :pep:`753` "Well-known Project URLs in Metadata" normalization rules when
2+
identifying an equivalent project URL to replace a missing ``Home-Page`` field
3+
in ``pip show``.

news/13194.feature.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add a structured ``--json`` output to ``pip index versions``

news/13229.bugfix.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Parse wheel filenames according to `binary distribution format specification
2+
<https://packaging.python.org/en/latest/specifications/binary-distribution-format/#file-format>`_.
3+
When a filename doesn't match the spec a deprecation warning is emitted and the
4+
filename is parsed using the old method.

news/13253.feature.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Speed up resolution by first only considering the preference of
2+
candidates that must be required to complete the resolution.

src/pip/_internal/cli/cmdoptions.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -928,6 +928,14 @@ def _handle_config_settings(
928928
"pip only finds stable versions.",
929929
)
930930

931+
json: Callable[..., Option] = partial(
932+
Option,
933+
"--json",
934+
action="store_true",
935+
default=False,
936+
help="Output data in a machine-readable JSON format.",
937+
)
938+
931939
disable_pip_version_check: Callable[..., Option] = partial(
932940
Option,
933941
"--disable-pip-version-check",

src/pip/_internal/commands/index.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import json
12
import logging
23
from optparse import Values
34
from typing import Any, Iterable, List, Optional
@@ -7,7 +8,10 @@
78
from pip._internal.cli import cmdoptions
89
from pip._internal.cli.req_command import IndexGroupCommand
910
from pip._internal.cli.status_codes import ERROR, SUCCESS
10-
from pip._internal.commands.search import print_dist_installation_info
11+
from pip._internal.commands.search import (
12+
get_installed_distribution,
13+
print_dist_installation_info,
14+
)
1115
from pip._internal.exceptions import CommandError, DistributionNotFound, PipError
1216
from pip._internal.index.collector import LinkCollector
1317
from pip._internal.index.package_finder import PackageFinder
@@ -34,6 +38,7 @@ def add_options(self) -> None:
3438

3539
self.cmd_opts.add_option(cmdoptions.ignore_requires_python())
3640
self.cmd_opts.add_option(cmdoptions.pre())
41+
self.cmd_opts.add_option(cmdoptions.json())
3742
self.cmd_opts.add_option(cmdoptions.no_binary())
3843
self.cmd_opts.add_option(cmdoptions.only_binary())
3944

@@ -134,6 +139,21 @@ def get_available_package_versions(self, options: Values, args: List[Any]) -> No
134139
formatted_versions = [str(ver) for ver in sorted(versions, reverse=True)]
135140
latest = formatted_versions[0]
136141

137-
write_output(f"{query} ({latest})")
138-
write_output("Available versions: {}".format(", ".join(formatted_versions)))
139-
print_dist_installation_info(query, latest)
142+
dist = get_installed_distribution(query)
143+
144+
if options.json:
145+
structured_output = {
146+
"name": query,
147+
"versions": formatted_versions,
148+
"latest": latest,
149+
}
150+
151+
if dist is not None:
152+
structured_output["installed_version"] = str(dist.version)
153+
154+
write_output(json.dumps(structured_output))
155+
156+
else:
157+
write_output(f"{query} ({latest})")
158+
write_output("Available versions: {}".format(", ".join(formatted_versions)))
159+
print_dist_installation_info(latest, dist)

0 commit comments

Comments
 (0)