Voice et bot modif
This commit is contained in:
parent
189d56026b
commit
7333a22bcd
10774 changed files with 634644 additions and 933308 deletions
|
|
@ -1,20 +1,13 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import logging
|
||||
from collections.abc import Iterable
|
||||
from optparse import Values
|
||||
from typing import Any, Callable
|
||||
from typing import Any, Iterable, List, Optional, Union
|
||||
|
||||
from pip._vendor.packaging.version import Version
|
||||
from pip._vendor.packaging.version import LegacyVersion, Version
|
||||
|
||||
from pip._internal.cli import cmdoptions
|
||||
from pip._internal.cli.req_command import IndexGroupCommand
|
||||
from pip._internal.cli.status_codes import ERROR, SUCCESS
|
||||
from pip._internal.commands.search import (
|
||||
get_installed_distribution,
|
||||
print_dist_installation_info,
|
||||
)
|
||||
from pip._internal.commands.search import print_dist_installation_info
|
||||
from pip._internal.exceptions import CommandError, DistributionNotFound, PipError
|
||||
from pip._internal.index.collector import LinkCollector
|
||||
from pip._internal.index.package_finder import PackageFinder
|
||||
|
|
@ -41,7 +34,6 @@ class IndexCommand(IndexGroupCommand):
|
|||
|
||||
self.cmd_opts.add_option(cmdoptions.ignore_requires_python())
|
||||
self.cmd_opts.add_option(cmdoptions.pre())
|
||||
self.cmd_opts.add_option(cmdoptions.json())
|
||||
self.cmd_opts.add_option(cmdoptions.no_binary())
|
||||
self.cmd_opts.add_option(cmdoptions.only_binary())
|
||||
|
||||
|
|
@ -53,19 +45,22 @@ class IndexCommand(IndexGroupCommand):
|
|||
self.parser.insert_option_group(0, index_opts)
|
||||
self.parser.insert_option_group(0, self.cmd_opts)
|
||||
|
||||
def handler_map(self) -> dict[str, Callable[[Values, list[str]], None]]:
|
||||
return {
|
||||
def run(self, options: Values, args: List[str]) -> int:
|
||||
handlers = {
|
||||
"versions": self.get_available_package_versions,
|
||||
}
|
||||
|
||||
def run(self, options: Values, args: list[str]) -> int:
|
||||
handler_map = self.handler_map()
|
||||
logger.warning(
|
||||
"pip index is currently an experimental command. "
|
||||
"It may be removed/changed in a future release "
|
||||
"without prior warning."
|
||||
)
|
||||
|
||||
# Determine action
|
||||
if not args or args[0] not in handler_map:
|
||||
if not args or args[0] not in handlers:
|
||||
logger.error(
|
||||
"Need an action (%s) to perform.",
|
||||
", ".join(sorted(handler_map)),
|
||||
", ".join(sorted(handlers)),
|
||||
)
|
||||
return ERROR
|
||||
|
||||
|
|
@ -73,7 +68,7 @@ class IndexCommand(IndexGroupCommand):
|
|||
|
||||
# Error handling happens here, not in the action-handlers.
|
||||
try:
|
||||
handler_map[action](options, args[1:])
|
||||
handlers[action](options, args[1:])
|
||||
except PipError as e:
|
||||
logger.error(e.args[0])
|
||||
return ERROR
|
||||
|
|
@ -84,8 +79,8 @@ class IndexCommand(IndexGroupCommand):
|
|||
self,
|
||||
options: Values,
|
||||
session: PipSession,
|
||||
target_python: TargetPython | None = None,
|
||||
ignore_requires_python: bool | None = None,
|
||||
target_python: Optional[TargetPython] = None,
|
||||
ignore_requires_python: Optional[bool] = None,
|
||||
) -> PackageFinder:
|
||||
"""
|
||||
Create a package finder appropriate to the index command.
|
||||
|
|
@ -105,7 +100,7 @@ class IndexCommand(IndexGroupCommand):
|
|||
target_python=target_python,
|
||||
)
|
||||
|
||||
def get_available_package_versions(self, options: Values, args: list[Any]) -> None:
|
||||
def get_available_package_versions(self, options: Values, args: List[Any]) -> None:
|
||||
if len(args) != 1:
|
||||
raise CommandError("You need to specify exactly one argument")
|
||||
|
||||
|
|
@ -120,7 +115,7 @@ class IndexCommand(IndexGroupCommand):
|
|||
ignore_requires_python=options.ignore_requires_python,
|
||||
)
|
||||
|
||||
versions: Iterable[Version] = (
|
||||
versions: Iterable[Union[LegacyVersion, Version]] = (
|
||||
candidate.version for candidate in finder.find_all_candidates(query)
|
||||
)
|
||||
|
||||
|
|
@ -139,21 +134,6 @@ class IndexCommand(IndexGroupCommand):
|
|||
formatted_versions = [str(ver) for ver in sorted(versions, reverse=True)]
|
||||
latest = formatted_versions[0]
|
||||
|
||||
dist = get_installed_distribution(query)
|
||||
|
||||
if options.json:
|
||||
structured_output = {
|
||||
"name": query,
|
||||
"versions": formatted_versions,
|
||||
"latest": latest,
|
||||
}
|
||||
|
||||
if dist is not None:
|
||||
structured_output["installed_version"] = str(dist.version)
|
||||
|
||||
write_output(json.dumps(structured_output))
|
||||
|
||||
else:
|
||||
write_output(f"{query} ({latest})")
|
||||
write_output("Available versions: {}".format(", ".join(formatted_versions)))
|
||||
print_dist_installation_info(latest, dist)
|
||||
write_output(f"{query} ({latest})")
|
||||
write_output("Available versions: {}".format(", ".join(formatted_versions)))
|
||||
print_dist_installation_info(query, latest)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue