mirror of https://github.com/pypa/pip
Add direct_url support to InstallRequirement
pass it to install_wheel via install
This commit is contained in:
parent
94b77130aa
commit
a0ed759fb3
|
@ -31,6 +31,7 @@ from pip._internal.operations.install.wheel import install_wheel
|
|||
from pip._internal.pyproject import load_pyproject_toml, make_pyproject_path
|
||||
from pip._internal.req.req_uninstall import UninstallPathSet
|
||||
from pip._internal.utils.deprecation import deprecated
|
||||
from pip._internal.utils.direct_url_helpers import direct_url_from_link
|
||||
from pip._internal.utils.hashes import Hashes
|
||||
from pip._internal.utils.logging import indent_log
|
||||
from pip._internal.utils.misc import (
|
||||
|
@ -126,6 +127,7 @@ class InstallRequirement(object):
|
|||
# PEP 508 URL requirement
|
||||
link = Link(req.url)
|
||||
self.link = self.original_link = link
|
||||
self.original_link_is_in_wheel_cache = False
|
||||
# Path to any downloaded or already-existing package.
|
||||
self.local_file_path = None # type: Optional[str]
|
||||
if self.link and self.link.is_file:
|
||||
|
@ -785,6 +787,13 @@ class InstallRequirement(object):
|
|||
|
||||
if self.is_wheel:
|
||||
assert self.local_file_path
|
||||
direct_url = None
|
||||
if self.original_link:
|
||||
direct_url = direct_url_from_link(
|
||||
self.original_link,
|
||||
self.source_dir,
|
||||
self.original_link_is_in_wheel_cache,
|
||||
)
|
||||
install_wheel(
|
||||
self.name,
|
||||
self.local_file_path,
|
||||
|
@ -792,6 +801,7 @@ class InstallRequirement(object):
|
|||
req_description=str(self.req),
|
||||
pycompile=pycompile,
|
||||
warn_script_location=warn_script_location,
|
||||
direct_url=direct_url,
|
||||
)
|
||||
self.install_succeeded = True
|
||||
return
|
||||
|
|
|
@ -280,14 +280,16 @@ class Resolver(BaseResolver):
|
|||
|
||||
if self.wheel_cache is None or self.preparer.require_hashes:
|
||||
return
|
||||
cached_link = self.wheel_cache.get(
|
||||
cache_entry = self.wheel_cache.get_cache_entry(
|
||||
link=req.link,
|
||||
package_name=req.name,
|
||||
supported_tags=get_supported(),
|
||||
)
|
||||
if req.link != cached_link:
|
||||
logger.debug('Using cached wheel link: %s', cached_link)
|
||||
req.link = cached_link
|
||||
if cache_entry is not None:
|
||||
logger.debug('Using cached wheel link: %s', cache_entry.link)
|
||||
if req.link is req.original_link and cache_entry.persistent:
|
||||
req.original_link_is_in_wheel_cache = True
|
||||
req.link = cache_entry.link
|
||||
|
||||
def _get_abstract_dist_for(self, req):
|
||||
# type: (InstallRequirement) -> AbstractDistribution
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
import re
|
||||
|
||||
from pip._internal.models.direct_url import DIRECT_URL_METADATA_NAME, DirectUrl
|
||||
from tests.lib import _create_test_package, path_to_url
|
||||
|
||||
|
||||
def _get_created_direct_url(result, pkg):
|
||||
direct_url_metadata_re = re.compile(
|
||||
pkg + r"-[\d\.]+\.dist-info." + DIRECT_URL_METADATA_NAME + r"$"
|
||||
)
|
||||
for filename in result.files_created:
|
||||
if direct_url_metadata_re.search(filename):
|
||||
direct_url_path = result.test_env.base_path / filename
|
||||
with open(direct_url_path) as f:
|
||||
return DirectUrl.from_json(f.read())
|
||||
return None
|
||||
|
||||
|
||||
def test_install_find_links_no_direct_url(script, with_wheel):
|
||||
result = script.pip_install_local("simple")
|
||||
assert not _get_created_direct_url(result, "simple")
|
||||
|
||||
|
||||
def test_install_vcs_editable_no_direct_url(script, with_wheel):
|
||||
pkg_path = _create_test_package(script, name="testpkg")
|
||||
args = ["install", "-e", "git+%s#egg=testpkg" % path_to_url(pkg_path)]
|
||||
result = script.pip(*args)
|
||||
# legacy editable installs do not generate .dist-info,
|
||||
# hence no direct_url.json
|
||||
assert not _get_created_direct_url(result, "testpkg")
|
||||
|
||||
|
||||
def test_install_vcs_non_editable_direct_url(script, with_wheel):
|
||||
pkg_path = _create_test_package(script, name="testpkg")
|
||||
url = path_to_url(pkg_path)
|
||||
args = ["install", "git+{}#egg=testpkg".format(url)]
|
||||
result = script.pip(*args)
|
||||
direct_url = _get_created_direct_url(result, "testpkg")
|
||||
assert direct_url
|
||||
assert direct_url.url == url
|
||||
assert direct_url.info.vcs == "git"
|
||||
|
||||
|
||||
def test_install_archive_direct_url(script, data, with_wheel):
|
||||
req = "simple @ " + path_to_url(data.packages / "simple-2.0.tar.gz")
|
||||
assert req.startswith("simple @ file://")
|
||||
result = script.pip("install", req)
|
||||
assert _get_created_direct_url(result, "simple")
|
Loading…
Reference in New Issue