未验证 提交 00a595d0 编写于 作者: F Frost Ming

Remove some compatibility code

上级 89d61172
Write a `sitecustomize.py` instead of a `.pth` file to enable PEP 582.
Update `get_package_finder()` to be compatible with `pip 20.3`.
......@@ -268,7 +268,7 @@ zipp = {marker = "python_version < '3.8'", version = "*"}
[[package]]
name = "pip"
sections = ["default"]
version = "20.2.4"
version = "20.3.1"
summary = "The PyPA recommended tool for installing Python packages."
[[package]]
......@@ -728,9 +728,9 @@ summary = "Backport of pathlib-compatible object wrapper for zip files"
{file = "pep517-0.9.1-py2.py3-none-any.whl", hash = "sha256:3985b91ebf576883efe5fa501f42a16de2607684f3797ddba7202b71b7d0da51"},
{file = "pep517-0.9.1.tar.gz", hash = "sha256:aeb78601f2d1aa461960b43add204cc7955667687fbcf9cdb5170f00556f117f"},
]
"pip 20.2.4" = [
{file = "pip-20.2.4-py2.py3-none-any.whl", hash = "sha256:51f1c7514530bd5c145d8f13ed936ad6b8bfcb8cf74e10403d0890bc986f0033"},
{file = "pip-20.2.4.tar.gz", hash = "sha256:85c99a857ea0fb0aedf23833d9be5c40cf253fe24443f0829c7b472e23c364a1"},
"pip 20.3.1" = [
{file = "pip-20.3.1-py2.py3-none-any.whl", hash = "sha256:425e79b20939abbffa7633a91151a882aedc77564d9313e3584eb0416c28c558"},
{file = "pip-20.3.1.tar.gz", hash = "sha256:43f7d3811f05db95809d39515a5111dd05994965d870178a4fe10d5482f9d2e2"},
]
"pip-shims 0.5.3" = [
{file = "pip_shims-0.5.3-py2.py3-none-any.whl", hash = "sha256:16ca9f87485667b16b978b68a1aae4f9cc082c0fa018aed28567f9f34a590569"},
......@@ -952,4 +952,3 @@ summary = "Backport of pathlib-compatible object wrapper for zip files"
[root]
meta_version = "0.0.1"
content_hash = "md5:cf7dd9fb5ea311d0fb65a7e99ba86e71"
......@@ -29,7 +29,7 @@ from pip_shims.shims import (
from pdm._types import Source
if TYPE_CHECKING:
from pip_shims.compat import TCommand, TFinder, TSession, TShimmedFunc, Values
from pip_shims.compat import TCommand, TFinder, Values
try:
from functools import cached_property
......@@ -100,17 +100,10 @@ def get_abi_tag(python_version):
def get_package_finder(
install_cmd=None, # type: Optional[TCommand]
install_cmd, # type: TCommand
options=None, # type: Optional[Values]
session=None, # type: Optional[TSession]
platform=None, # type: Optional[str]
python_version=None, # type: Optional[Tuple[int, int]]
abi=None, # type: Optional[str]
implementation=None, # type: Optional[str]
target_python=None, # type: Optional[Any]
ignore_requires_python=None, # type: Optional[bool]
target_python_builder=None, # type: Optional[TShimmedFunc]
install_cmd_provider=None, # type: Optional[TShimmedFunc]
):
# type: (...) -> TFinder
"""Shim for compatibility to generate package finders.
......@@ -118,85 +111,26 @@ def get_package_finder(
Build and return a :class:`~pip._internal.index.package_finder.PackageFinder`
instance using the :class:`~pip._internal.commands.install.InstallCommand` helper
method to construct the finder, shimmed with backports as needed for compatibility.
:param install_cmd_provider: A shim for providing new install command instances.
:type install_cmd_provider: :class:`~pip_shims.models.ShimmedPathCollection`
:param install_cmd: A :class:`~pip._internal.commands.install.InstallCommand`
instance which is used to generate the finder.
:param optparse.Values options: An optional :class:`optparse.Values` instance
generated by calling `install_cmd.parser.parse_args()` typically.
:param session: An optional session instance, can be created by the `install_cmd`.
:param Optional[str] platform: An optional platform string, e.g. linux_x86_64
:param Optional[Tuple[str, ...]] python_version: A tuple of 2-digit strings
representing python versions, e.g. ("27", "35", "36", "37"...)
:param Optional[str] abi: The target abi to support, e.g. "cp38"
:param Optional[str] implementation: An optional implementation string for limiting
searches to a specific implementation, e.g. "cp" or "py"
:param target_python: A :class:`~pip._internal.models.target_python.TargetPython`
instance (will be translated to alternate arguments if necessary on incompatible
pip versions).
:param Optional[bool] ignore_requires_python: Whether to ignore `requires_python`
on resulting candidates, only valid after pip version 19.3.1
:param target_python_builder: A 'TargetPython' builder (e.g. the class itself,
uninstantiated)
:return: A :class:`pip._internal.index.package_finder.PackageFinder` instance
:rtype: :class:`pip._internal.index.package_finder.PackageFinder`
"""
from pip_shims.compat import get_session, resolve_possible_shim
from pip_shims.compat import get_session
if install_cmd is None:
install_cmd_provider = resolve_possible_shim(install_cmd_provider)
assert isinstance(install_cmd_provider, (type, functools.partial))
install_cmd = install_cmd_provider()
if options is None:
options, _ = install_cmd.parser.parse_args([]) # type: ignore
if session is None:
session = get_session(install_cmd=install_cmd, options=options) # type: ignore
builder_args = inspect.getargs(
install_cmd._build_package_finder.__code__
) # type: ignore
session = get_session(install_cmd=install_cmd, options=options) # type: ignore
build_kwargs = {"options": options, "session": session}
expects_targetpython = "target_python" in builder_args.args
received_python = any(
arg for arg in [platform, python_version, abi, implementation]
)
if expects_targetpython and received_python:
if not target_python:
if target_python_builder is None:
target_python_builder = TargetPython
if python_version and not abi:
abi = get_abi_tag(python_version)
target_python = target_python_builder(
platform=platform,
abi=abi,
implementation=implementation,
py_version_info=python_version,
)
if python_version:
target_python_builder = TargetPython
abi = get_abi_tag(python_version)
builder_args = inspect.signature(target_python_builder).parameters
target_python_params = {"py_version_info": python_version}
if "abi" in builder_args:
target_python_params["abi"] = abi
elif "abis" in builder_args:
target_python_params["abis"] = [abi]
target_python = target_python_builder(**target_python_params)
build_kwargs["target_python"] = target_python
elif any(
arg in builder_args.args
for arg in ["platform", "python_version", "abi", "implementation"]
):
if target_python and not received_python:
tags = target_python.get_tags()
version_impl = set([t[0] for t in tags])
# impls = set([v[:2] for v in version_impl])
# impls.remove("py")
# impl = next(iter(impls), "py") if not target_python
versions = set([v[2:] for v in version_impl])
build_kwargs.update(
{
"platform": target_python.platform,
"python_versions": versions,
"abi": target_python.abi,
"implementation": target_python.implementation,
}
)
if (
ignore_requires_python is not None
and "ignore_requires_python" in builder_args.args
):
build_kwargs["ignore_requires_python"] = ignore_requires_python
build_kwargs["ignore_requires_python"] = ignore_requires_python
return install_cmd._build_package_finder(**build_kwargs) # type: ignore
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册