Skip to content

Commit

Permalink
Add DirectUrl support to install_wheel
Browse files Browse the repository at this point in the history
  • Loading branch information
sbidoul committed Feb 1, 2020
1 parent 7fc4ba7 commit 9e24b58
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/pip/_internal/operations/install/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

from pip._internal.exceptions import InstallationError
from pip._internal.locations import get_major_minor_version
from pip._internal.models.direct_url import DIRECT_URL_METADATA_NAME, DirectUrl
from pip._internal.utils.misc import captured_stdout, ensure_dir, hash_file
from pip._internal.utils.temp_dir import TempDirectory
from pip._internal.utils.typing import MYPY_CHECK_RUNNING
Expand Down Expand Up @@ -287,7 +288,8 @@ def install_unpacked_wheel(
scheme, # type: Scheme
req_description, # type: str
pycompile=True, # type: bool
warn_script_location=True # type: bool
warn_script_location=True, # type: bool
direct_url=None, # type: DirectUrl
):
# type: (...) -> None
"""Install a wheel.
Expand Down Expand Up @@ -573,6 +575,17 @@ def is_entrypoint_wrapper(name):
shutil.move(temp_installer, installer)
generated.append(installer)

# Record the PEP 610 direct URL reference
if direct_url is not None:
direct_url_path = os.path.join(dest_info_dir, DIRECT_URL_METADATA_NAME)
temp_direct_url_path = os.path.join(
dest_info_dir, DIRECT_URL_METADATA_NAME + ".pip"
)
with open(temp_direct_url_path, 'wb') as temp_direct_url_file:
temp_direct_url_file.write(direct_url.to_json().encode("utf-8"))
shutil.move(temp_direct_url_path, direct_url_path)
generated.append(direct_url_path)

# Record details of all files installed
record = os.path.join(dest_info_dir, 'RECORD')
temp_record = os.path.join(dest_info_dir, 'RECORD.pip')
Expand All @@ -598,6 +611,7 @@ def install_wheel(
pycompile=True, # type: bool
warn_script_location=True, # type: bool
_temp_dir_for_testing=None, # type: Optional[str]
direct_url=None, # type: DirectUrl
):
# type: (...) -> None
with TempDirectory(
Expand All @@ -612,4 +626,5 @@ def install_wheel(
req_description=req_description,
pycompile=pycompile,
warn_script_location=warn_script_location,
direct_url=direct_url,
)
29 changes: 29 additions & 0 deletions tests/unit/test_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
from pip._vendor.packaging.requirements import Requirement

from pip._internal.locations import get_scheme
from pip._internal.models.direct_url import (
DIRECT_URL_METADATA_NAME,
ArchiveInfo,
DirectUrl,
)
from pip._internal.models.scheme import Scheme
from pip._internal.operations.build.wheel_legacy import (
get_legacy_build_wheel_path,
Expand Down Expand Up @@ -259,6 +264,30 @@ def test_std_install(self, data, tmpdir):
)
self.assert_installed()

def test_std_install_with_direct_url(self, data, tmpdir):
self.prep(data, tmpdir)
direct_url = DirectUrl()
direct_url.url = "file:///home/user/archive.tgz"
direct_url.info = ArchiveInfo()
wheel.install_wheel(
self.name,
self.wheelpath,
scheme=self.scheme,
req_description=str(self.req),
direct_url=direct_url,
)
direct_url_path = os.path.join(
self.dest_dist_info, DIRECT_URL_METADATA_NAME
)
assert os.path.isfile(direct_url_path)
with open(direct_url_path, 'rb') as f:
expected_direct_url_json = direct_url.to_json()
direct_url_json = f.read().decode("utf-8")
assert direct_url_json == expected_direct_url_json
# check that the direc_url file is part of RECORDS
with open(os.path.join(self.dest_dist_info, "RECORD")) as f:
assert DIRECT_URL_METADATA_NAME in f.read()

def test_install_prefix(self, data, tmpdir):
prefix = os.path.join(os.path.sep, 'some', 'path')
self.prep(data, tmpdir)
Expand Down

0 comments on commit 9e24b58

Please sign in to comment.