Skip to content

Commit ae4f981

Browse files
committed
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.
1 parent a250f19 commit ae4f981

4 files changed

Lines changed: 38 additions & 1 deletion

File tree

src/poetry/repositories/installed_repository.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,10 @@ def create_package_from_pep610(cls, distribution: metadata.Distribution) -> Pack
201201
# VCS distribution
202202
source_type = url_reference["vcs_info"]["vcs"]
203203
source_url = url_reference["url"]
204-
source_reference = url_reference["vcs_info"]["requested_revision"]
205204
source_resolved_reference = url_reference["vcs_info"]["commit_id"]
205+
source_reference = url_reference["vcs_info"].get(
206+
"requested_revision", source_resolved_reference
207+
)
206208

207209
package = Package(
208210
distribution.metadata["name"],
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Metadata-Version: 2.1
2+
Name: git-pep-610-no-requested-version
3+
Version: 1.2.3
4+
Summary: Foo
5+
License: MIT
6+
Requires-Python: >=3.6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"url": "https://github.com/demo/git-pep-610-no-requested-version.git",
3+
"vcs_info": {
4+
"vcs": "git",
5+
"commit_id": "123456"
6+
}
7+
}

tests/repositories/test_installed_repository.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@
3434
metadata.PathDistribution(SITE_PLATLIB / "lib64-2.3.4.dist-info"),
3535
metadata.PathDistribution(SITE_PLATLIB / "bender-2.0.5.dist-info"),
3636
metadata.PathDistribution(SITE_PURELIB / "git_pep_610-1.2.3.dist-info"),
37+
metadata.PathDistribution(
38+
SITE_PURELIB / "git_pep_610_no_requested_version-1.2.3.dist-info"
39+
),
3740
metadata.PathDistribution(SITE_PURELIB / "url_pep_610-1.2.3.dist-info"),
3841
metadata.PathDistribution(SITE_PURELIB / "file_pep_610-1.2.3.dist-info"),
3942
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):
189192
assert package.source_resolved_reference == "123456"
190193

191194

195+
def test_load_pep_610_compliant_git_packages_no_requested_version(
196+
repository: InstalledRepository,
197+
):
198+
package = get_package_from_repository(
199+
"git-pep-610-no-requested-version", repository
200+
)
201+
202+
assert package is not None
203+
assert package.name == "git-pep-610-no-requested-version"
204+
assert package.version.text == "1.2.3"
205+
assert package.source_type == "git"
206+
assert (
207+
package.source_url
208+
== "https://github.com/demo/git-pep-610-no-requested-version.git"
209+
)
210+
assert package.source_resolved_reference == "123456"
211+
assert package.source_reference == package.source_resolved_reference
212+
213+
192214
def test_load_pep_610_compliant_url_packages(repository: InstalledRepository):
193215
package = get_package_from_repository("url-pep-610", repository)
194216

0 commit comments

Comments
 (0)