Skip to content

Commit

Permalink
Merge branch 'main' into joe/warm_cache_in_threadpool
Browse files Browse the repository at this point in the history
  • Loading branch information
jbylund authored Jun 1, 2023
2 parents f1922cc + 5e8e88e commit e491f93
Show file tree
Hide file tree
Showing 31 changed files with 916 additions and 296 deletions.
35 changes: 35 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
917b41d6d73535c090fc312668dff353cdaef906 # Blacken docs/html/conf.py
ed383dd8afa8fe0250dcf9b8962927ada0e21c89 # Blacken docs/pip_sphinxext.py
228405e62451abe8a66233573035007df4be575f # Blacken noxfile.py
f477a9f490e978177b71c9dbaa5465c51ea21129 # Blacken setup.py
e59ba23468390217479465019f8d78e724a23550 # Blacken src/pip/__main__.py
d7013db084e9a52242354ee5754dc5d19ccf062e # Blacken src/pip/_internal/build_env.py
30e9ffacae75378fc3e3df48f754dabad037edb9 # Blacken src/pip/_internal/cache.py
8341d56b46776a805286218ac5fb0e7850fd9341 # Blacken src/pip/_internal/cli/autocompletion.py
3d3461ed65208656358b3595e25d8c31c5c89470 # Blacken src/pip/_internal/cli/base_command.py
d489b0f1b104bc936b0fb17e6c33633664ebdc0e # Blacken src/pip/_internal/cli/cmdoptions.py
591fe4841aefe9befa0530f2a54f820c4ecbb392 # Blacken src/pip/_internal/cli/command_context.py
9265b28ef7248ae1847a80384dbeeb8119c3e2f5 # Blacken src/pip/_internal/cli/main.py
847a369364878c38d210c90beed2737bb6fb3a85 # Blacken src/pip/_internal/cli/main_parser.py
ec97119067041ae58b963935ff5f0e5d9fead80c # Blacken src/pip/_internal/cli/parser.py
6e3b8de22fa39fa3073599ecf9db61367f4b3b32 # Blacken src/pip/_internal/cli/progress_bars.py
55405227de983c5bd5bf0858ea12dbe537d3e490 # Blacken src/pip/_internal/cli/req_command.py
d5ca5c850cae9a0c64882a8f49d3a318699a7e2e # Blacken src/pip/_internal/cli/spinners.py
9747cb48f8430a7a91b36fe697dd18dbddb319f0 # Blacken src/pip/_internal/commands/__init__.py
1c09fd6f124df08ca36bed68085ad68e89bb1957 # Blacken src/pip/_internal/commands/cache.py
315e93d7eb87cd476afcc4eaf0f01a7b56a5037f # Blacken src/pip/_internal/commands/check.py
8ae3b96ed7d24fd24024ccce4840da0dcf635f26 # Blacken src/pip/_internal/commands/completion.py
42ca4792202f26a293ee48380718743a80bbee37 # Blacken src/pip/_internal/commands/configuration.py
790ad78fcd43d41a5bef9dca34a3c128d05eb02c # Blacken src/pip/_internal/commands/debug.py
a6fcc8f045afe257ce321f4012fc8fcb4be01eb3 # Blacken src/pip/_internal/commands/download.py
920e735dfc60109351fbe2f4c483c2f6ede9e52d # Blacken src/pip/_internal/commands/freeze.py
053004e0fcf0851238b1064fbce13aea87b24e9c # Blacken src/pip/_internal/commands/hash.py
a6b6ae487e52c2242045b64cb8962e0a992cfd76 # Blacken src/pip/_internal/commands/help.py
2495cf95a6c7eb61ccf1f9f0e8b8d736af914e53 # Blacken __main__.py
c7ee560e00b85f7486b452c14ff49e4737996eda # Blacken tools/
8e2e1964a4f0a060f7299a96a911c9e116b2283d # Blacken src/pip/_internal/commands/
1bc0eef05679e87f45540ab0a294667cb3c6a88e # Blacken src/pip/_internal/network/
069b01932a7d64a81c708c6254cc93e1f89e6783 # Blacken src/pip/_internal/req
1897784d59e0d5fcda2dd75fea54ddd8be3d502a # Blacken src/pip/_internal/index
94999255d5ede440c37137d210666fdf64302e75 # Reformat the codebase, with black
585037a80a1177f1fa92e159a7079855782e543e # Cleanup implicit string concatenation
6 changes: 5 additions & 1 deletion .readthedocs.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
version: 2

build:
os: ubuntu-22.04
tools:
python: "3.11"

sphinx:
builder: htmldir
configuration: docs/html/conf.py

python:
version: 3.8
install:
- requirements: docs/requirements.txt
4 changes: 2 additions & 2 deletions AUTHORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ Miro Hrončok
Monica Baluna
montefra
Monty Taylor
Muha Ajjan
Muha Ajjan
Nadav Wexler
Nahuel Ambrosini
Nate Coraor
Expand Down Expand Up @@ -725,4 +725,4 @@ Zvezdan Petkovic
Łukasz Langa
Роман Донченко
Семён Марьясин
‮rekcäH nitraM‮
Martin Häcker
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ recursive-include src/pip/_vendor *COPYING*
include docs/docutils.conf
include docs/requirements.txt

exclude .git-blame-ignore-revs
exclude .coveragerc
exclude .mailmap
exclude .appveyor.yml
Expand Down
1 change: 1 addition & 0 deletions news/11985.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Ignore invalid or unreadable ``origin.json`` files in the cache of locally built wheels.
1 change: 1 addition & 0 deletions news/12038.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix installation of packages with PEP658 metadata using non-canonicalized names
1 change: 1 addition & 0 deletions news/12040.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
make rejection messages slightly different between 1 and 8, so the user can make the difference.
Empty file.
1 change: 1 addition & 0 deletions news/requests.vendor.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Upgrade Requests to 2.31.0
1 change: 1 addition & 0 deletions news/typing-extensions.vendor.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Updated typing_extensions to 4.6.0
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ def get_version(rel_path: str) -> str:
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
],
Expand Down
7 changes: 0 additions & 7 deletions src/pip/__main__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import os
import sys
import warnings

# Remove '' and current working directory from the first entry
# of sys.path, if present to avoid using current directory
Expand All @@ -20,12 +19,6 @@
sys.path.insert(0, path)

if __name__ == "__main__":
# Work around the error reported in #9540, pending a proper fix.
# Note: It is essential the warning filter is set *before* importing
# pip, as the deprecation happens at import time, not runtime.
warnings.filterwarnings(
"ignore", category=DeprecationWarning, module=".*packaging\\.version"
)
from pip._internal.cli.main import main as _main

sys.exit(_main())
42 changes: 31 additions & 11 deletions src/pip/_internal/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,17 @@ def __init__(
self.origin: Optional[DirectUrl] = None
origin_direct_url_path = Path(self.link.file_path).parent / ORIGIN_JSON_NAME
if origin_direct_url_path.exists():
self.origin = DirectUrl.from_json(origin_direct_url_path.read_text())
try:
self.origin = DirectUrl.from_json(
origin_direct_url_path.read_text(encoding="utf-8")
)
except Exception as e:
logger.warning(
"Ignoring invalid cache entry origin file %s for %s (%s)",
origin_direct_url_path,
link.filename,
e,
)


class WheelCache(Cache):
Expand Down Expand Up @@ -257,16 +267,26 @@ def get_cache_entry(
@staticmethod
def record_download_origin(cache_dir: str, download_info: DirectUrl) -> None:
origin_path = Path(cache_dir) / ORIGIN_JSON_NAME
if origin_path.is_file():
origin = DirectUrl.from_json(origin_path.read_text())
# TODO: use DirectUrl.equivalent when https://github.com/pypa/pip/pull/10564
# is merged.
if origin.url != download_info.url:
if origin_path.exists():
try:
origin = DirectUrl.from_json(origin_path.read_text(encoding="utf-8"))
except Exception as e:
logger.warning(
"Origin URL %s in cache entry %s does not match download URL %s. "
"This is likely a pip bug or a cache corruption issue.",
origin.url,
cache_dir,
download_info.url,
"Could not read origin file %s in cache entry (%s). "
"Will attempt to overwrite it.",
origin_path,
e,
)
else:
# TODO: use DirectUrl.equivalent when
# https://github.com/pypa/pip/pull/10564 is merged.
if origin.url != download_info.url:
logger.warning(
"Origin URL %s in cache entry %s does not match download URL "
"%s. This is likely a pip bug or a cache corruption issue. "
"Will overwrite it with the new value.",
origin.url,
cache_dir,
download_info.url,
)
origin_path.write_text(download_info.to_json(), encoding="utf-8")
7 changes: 5 additions & 2 deletions src/pip/_internal/commands/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,10 @@ def add_options(self) -> None:
dest="list_format",
default="columns",
choices=("columns", "freeze", "json"),
help="Select the output format among: columns (default), freeze, or json",
help=(
"Select the output format among: columns (default), freeze, or json. "
"The 'freeze' format cannot be used with the --outdated option."
),
)

self.cmd_opts.add_option(
Expand Down Expand Up @@ -157,7 +160,7 @@ def run(self, options: Values, args: List[str]) -> int:

if options.outdated and options.list_format == "freeze":
raise CommandError(
"List format 'freeze' can not be used with the --outdated option."
"List format 'freeze' cannot be used with the --outdated option."
)

cmdoptions.check_list_path_option(options)
Expand Down
2 changes: 1 addition & 1 deletion src/pip/_internal/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ def body(self) -> str:
# so the output can be directly copied into the requirements file.
package = (
self.req.original_link
if self.req.original_link
if self.req.is_direct
# In case someone feeds something downright stupid
# to InstallRequirement's constructor.
else getattr(self.req, "req", None)
Expand Down
2 changes: 1 addition & 1 deletion src/pip/_internal/models/installation_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def _install_req_to_dict(cls, ireq: InstallRequirement) -> Dict[str, Any]:
# is_direct is true if the requirement was a direct URL reference (which
# includes editable requirements), and false if the requirement was
# downloaded from a PEP 503 index or --find-links.
"is_direct": bool(ireq.original_link),
"is_direct": ireq.is_direct,
# requested is true if the requirement was specified by the user (aka
# top level requirement), and false if it was installed as a dependency of a
# requirement. https://peps.python.org/pep-0376/#requested
Expand Down
4 changes: 2 additions & 2 deletions src/pip/_internal/operations/prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ def _get_linked_req_hashes(self, req: InstallRequirement) -> Hashes:
# a surprising hash mismatch in the future.
# file:/// URLs aren't pinnable, so don't complain about them
# not being pinned.
if req.original_link is None and not req.is_pinned:
if not req.is_direct and not req.is_pinned:
raise HashUnpinned()

# If known-good hashes are missing for this requirement,
Expand Down Expand Up @@ -410,7 +410,7 @@ def _fetch_metadata_using_link_data_attr(
# NB: raw_name will fall back to the name from the install requirement if
# the Name: field is not present, but it's noted in the raw_name docstring
# that that should NEVER happen anyway.
if metadata_dist.raw_name != req.req.name:
if canonicalize_name(metadata_dist.raw_name) != canonicalize_name(req.req.name):
raise MetadataInconsistent(
req, "Name", req.req.name, metadata_dist.raw_name
)
Expand Down
11 changes: 9 additions & 2 deletions src/pip/_internal/req/req_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ def __init__(
if link.is_file:
self.source_dir = os.path.normpath(os.path.abspath(link.file_path))

# original_link is the direct URL that was provided by the user for the
# requirement, either directly or via a constraints file.
if link is None and req and req.url:
# PEP 508 URL requirement
link = Link(req.url)
Expand Down Expand Up @@ -244,6 +246,11 @@ def supports_pyproject_editable(self) -> bool:
def specifier(self) -> SpecifierSet:
return self.req.specifier

@property
def is_direct(self) -> bool:
"""Whether this requirement was specified as a direct URL."""
return self.original_link is not None

@property
def is_pinned(self) -> bool:
"""Return whether I am pinned to an exact version.
Expand Down Expand Up @@ -293,7 +300,7 @@ def hashes(self, trust_internet: bool = True) -> Hashes:
good_hashes = self.hash_options.copy()
if trust_internet:
link = self.link
elif self.original_link and self.user_supplied:
elif self.is_direct and self.user_supplied:
link = self.original_link
else:
link = None
Expand Down Expand Up @@ -804,7 +811,7 @@ def install(
req_description=str(self.req),
pycompile=pycompile,
warn_script_location=warn_script_location,
direct_url=self.download_info if self.original_link else None,
direct_url=self.download_info if self.is_direct else None,
requested=self.user_supplied,
)
self.install_succeeded = True
Expand Down
2 changes: 1 addition & 1 deletion src/pip/_internal/resolution/resolvelib/reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def __init__(self) -> None:
"requirements. This could take a while."
),
8: (
"pip is looking at multiple versions of {package_name} to "
"pip is still looking at multiple versions of {package_name} to "
"determine which version is compatible with other "
"requirements. This could take a while."
),
Expand Down
8 changes: 4 additions & 4 deletions src/pip/_vendor/requests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ def check_compatibility(urllib3_version, chardet_version, charset_normalizer_ver
# Check urllib3 for compatibility.
major, minor, patch = urllib3_version # noqa: F811
major, minor, patch = int(major), int(minor), int(patch)
# urllib3 >= 1.21.1, <= 1.26
assert major == 1
assert minor >= 21
assert minor <= 26
# urllib3 >= 1.21.1
assert major >= 1
if major == 1:
assert minor >= 21

# Check charset_normalizer for compatibility.
if chardet_version:
Expand Down
4 changes: 2 additions & 2 deletions src/pip/_vendor/requests/__version__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
__title__ = "requests"
__description__ = "Python HTTP for Humans."
__url__ = "https://requests.readthedocs.io"
__version__ = "2.28.2"
__build__ = 0x022802
__version__ = "2.31.0"
__build__ = 0x023100
__author__ = "Kenneth Reitz"
__author_email__ = "me@kennethreitz.org"
__license__ = "Apache 2.0"
Expand Down
6 changes: 4 additions & 2 deletions src/pip/_vendor/requests/_internal_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,11 @@
_VALID_HEADER_VALUE_RE_BYTE = re.compile(rb"^\S[^\r\n]*$|^$")
_VALID_HEADER_VALUE_RE_STR = re.compile(r"^\S[^\r\n]*$|^$")

_HEADER_VALIDATORS_STR = (_VALID_HEADER_NAME_RE_STR, _VALID_HEADER_VALUE_RE_STR)
_HEADER_VALIDATORS_BYTE = (_VALID_HEADER_NAME_RE_BYTE, _VALID_HEADER_VALUE_RE_BYTE)
HEADER_VALIDATORS = {
bytes: (_VALID_HEADER_NAME_RE_BYTE, _VALID_HEADER_VALUE_RE_BYTE),
str: (_VALID_HEADER_NAME_RE_STR, _VALID_HEADER_VALUE_RE_STR),
bytes: _HEADER_VALIDATORS_BYTE,
str: _HEADER_VALIDATORS_STR,
}


Expand Down
Loading

0 comments on commit e491f93

Please sign in to comment.