Commit ae4f9812 by Arun Babu Neelicattu

PEP610: handle optional vcs_info.requested_version

As per PEP610, presence of `vcs_info.requested_version` is optional in
direct_url.json for vcs packages. Prior to this change, Poetry would
crash when loading an environment with a vcs package not installed by
Poetry.
parent a250f197
...@@ -201,8 +201,10 @@ class InstalledRepository(Repository): ...@@ -201,8 +201,10 @@ class InstalledRepository(Repository):
# VCS distribution # VCS distribution
source_type = url_reference["vcs_info"]["vcs"] source_type = url_reference["vcs_info"]["vcs"]
source_url = url_reference["url"] source_url = url_reference["url"]
source_reference = url_reference["vcs_info"]["requested_revision"]
source_resolved_reference = url_reference["vcs_info"]["commit_id"] source_resolved_reference = url_reference["vcs_info"]["commit_id"]
source_reference = url_reference["vcs_info"].get(
"requested_revision", source_resolved_reference
)
package = Package( package = Package(
distribution.metadata["name"], distribution.metadata["name"],
......
Metadata-Version: 2.1
Name: git-pep-610-no-requested-version
Version: 1.2.3
Summary: Foo
License: MIT
Requires-Python: >=3.6
{
"url": "https://github.com/demo/git-pep-610-no-requested-version.git",
"vcs_info": {
"vcs": "git",
"commit_id": "123456"
}
}
...@@ -34,6 +34,9 @@ INSTALLED_RESULTS = [ ...@@ -34,6 +34,9 @@ INSTALLED_RESULTS = [
metadata.PathDistribution(SITE_PLATLIB / "lib64-2.3.4.dist-info"), metadata.PathDistribution(SITE_PLATLIB / "lib64-2.3.4.dist-info"),
metadata.PathDistribution(SITE_PLATLIB / "bender-2.0.5.dist-info"), metadata.PathDistribution(SITE_PLATLIB / "bender-2.0.5.dist-info"),
metadata.PathDistribution(SITE_PURELIB / "git_pep_610-1.2.3.dist-info"), metadata.PathDistribution(SITE_PURELIB / "git_pep_610-1.2.3.dist-info"),
metadata.PathDistribution(
SITE_PURELIB / "git_pep_610_no_requested_version-1.2.3.dist-info"
),
metadata.PathDistribution(SITE_PURELIB / "url_pep_610-1.2.3.dist-info"), metadata.PathDistribution(SITE_PURELIB / "url_pep_610-1.2.3.dist-info"),
metadata.PathDistribution(SITE_PURELIB / "file_pep_610-1.2.3.dist-info"), metadata.PathDistribution(SITE_PURELIB / "file_pep_610-1.2.3.dist-info"),
metadata.PathDistribution(SITE_PURELIB / "directory_pep_610-1.2.3.dist-info"), metadata.PathDistribution(SITE_PURELIB / "directory_pep_610-1.2.3.dist-info"),
...@@ -189,6 +192,25 @@ def test_load_pep_610_compliant_git_packages(repository: InstalledRepository): ...@@ -189,6 +192,25 @@ def test_load_pep_610_compliant_git_packages(repository: InstalledRepository):
assert package.source_resolved_reference == "123456" assert package.source_resolved_reference == "123456"
def test_load_pep_610_compliant_git_packages_no_requested_version(
repository: InstalledRepository,
):
package = get_package_from_repository(
"git-pep-610-no-requested-version", repository
)
assert package is not None
assert package.name == "git-pep-610-no-requested-version"
assert package.version.text == "1.2.3"
assert package.source_type == "git"
assert (
package.source_url
== "https://github.com/demo/git-pep-610-no-requested-version.git"
)
assert package.source_resolved_reference == "123456"
assert package.source_reference == package.source_resolved_reference
def test_load_pep_610_compliant_url_packages(repository: InstalledRepository): def test_load_pep_610_compliant_url_packages(repository: InstalledRepository):
package = get_package_from_repository("url-pep-610", repository) package = get_package_from_repository("url-pep-610", repository)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment