Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Writes hashes in direct_url.json for archives installed from URL #7475

Merged
merged 14 commits into from
Feb 7, 2023
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions src/poetry/installation/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -874,20 +874,12 @@ def _create_git_url_reference(self, package: Package) -> dict[str, Any]:
return reference

def _create_url_url_reference(self, package: Package) -> dict[str, Any]:
archive_info = {}

if package.name in self._hashes:
archive_info["hash"] = self._hashes[package.name]
archive_info = self._get_archive_info(package)

reference = {"url": package.source_url, "archive_info": archive_info}

return reference
return {"url": package.source_url, "archive_info": archive_info}

def _create_file_url_reference(self, package: Package) -> dict[str, Any]:
archive_info = {}

if package.name in self._hashes:
archive_info["hash"] = self._hashes[package.name]
archive_info = self._get_archive_info(package)

assert package.source_url is not None
return {
Expand All @@ -906,3 +898,12 @@ def _create_directory_url_reference(self, package: Package) -> dict[str, Any]:
"url": Path(package.source_url).as_uri(),
"dir_info": dir_info,
}

def _get_archive_info(self, package: Package) -> dict[str, Any]:
archive_info = {}
chopeen marked this conversation as resolved.
Show resolved Hide resolved

if package.name in self._hashes:
algorithm, value = self._hashes[package.name].split(":")
archive_info["hashes"] = {algorithm: value}

return archive_info
21 changes: 18 additions & 3 deletions tests/installation/test_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -701,12 +701,27 @@ def test_executor_should_write_pep610_url_references_for_urls(
source_type="url",
source_url="https://files.pythonhosted.org/demo-0.1.0-py2.py3-none-any.whl",
)
# Set package.files so the executor will attempt to hash the package
chopeen marked this conversation as resolved.
Show resolved Hide resolved
package.files = [
{
"file": "demo-0.1.0-py2.py3-none-any.whl",
"hash": "sha256:70e704135718fffbcbf61ed1fc45933cfd86951a744b681000eaaa75da31f17a", # noqa: E501
}
]

executor = Executor(tmp_venv, pool, config, io)
executor.execute([Install(package)])
verify_installed_distribution(
tmp_venv, package, {"archive_info": {}, "url": package.source_url}
)
expected_url_reference = {
"archive_info": {
"hashes": {
"sha256": (
"70e704135718fffbcbf61ed1fc45933cfd86951a744b681000eaaa75da31f17a"
)
},
},
"url": package.source_url,
}
verify_installed_distribution(tmp_venv, package, expected_url_reference)


def test_executor_should_write_pep610_url_references_for_git(
Expand Down