diff --git a/src/poetry/repositories/installed_repository.py b/src/poetry/repositories/installed_repository.py index 47130090f40..e1568df41c4 100644 --- a/src/poetry/repositories/installed_repository.py +++ b/src/poetry/repositories/installed_repository.py @@ -201,8 +201,10 @@ def create_package_from_pep610(cls, distribution: metadata.Distribution) -> Pack # VCS distribution source_type = url_reference["vcs_info"]["vcs"] source_url = url_reference["url"] - source_reference = url_reference["vcs_info"]["requested_revision"] source_resolved_reference = url_reference["vcs_info"]["commit_id"] + source_reference = url_reference["vcs_info"].get( + "requested_revision", source_resolved_reference + ) package = Package( distribution.metadata["name"], diff --git a/tests/repositories/fixtures/installed/lib/python3.7/site-packages/git_pep_610_no_requested_version-1.2.3.dist-info/METADATA b/tests/repositories/fixtures/installed/lib/python3.7/site-packages/git_pep_610_no_requested_version-1.2.3.dist-info/METADATA new file mode 100644 index 00000000000..986f958ab4f --- /dev/null +++ b/tests/repositories/fixtures/installed/lib/python3.7/site-packages/git_pep_610_no_requested_version-1.2.3.dist-info/METADATA @@ -0,0 +1,6 @@ +Metadata-Version: 2.1 +Name: git-pep-610-no-requested-version +Version: 1.2.3 +Summary: Foo +License: MIT +Requires-Python: >=3.6 diff --git a/tests/repositories/fixtures/installed/lib/python3.7/site-packages/git_pep_610_no_requested_version-1.2.3.dist-info/direct_url.json b/tests/repositories/fixtures/installed/lib/python3.7/site-packages/git_pep_610_no_requested_version-1.2.3.dist-info/direct_url.json new file mode 100644 index 00000000000..d646852cdde --- /dev/null +++ b/tests/repositories/fixtures/installed/lib/python3.7/site-packages/git_pep_610_no_requested_version-1.2.3.dist-info/direct_url.json @@ -0,0 +1,7 @@ +{ + "url": "https://github.com/demo/git-pep-610-no-requested-version.git", + "vcs_info": { + "vcs": "git", + "commit_id": "123456" + } +} diff --git a/tests/repositories/test_installed_repository.py b/tests/repositories/test_installed_repository.py index 3230bf5317e..c13be7d8e3e 100644 --- a/tests/repositories/test_installed_repository.py +++ b/tests/repositories/test_installed_repository.py @@ -34,6 +34,9 @@ metadata.PathDistribution(SITE_PLATLIB / "lib64-2.3.4.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_no_requested_version-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 / "directory_pep_610-1.2.3.dist-info"), @@ -189,6 +192,25 @@ def test_load_pep_610_compliant_git_packages(repository: InstalledRepository): 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): package = get_package_from_repository("url-pep-610", repository) diff --git a/tests/utils/test_env.py b/tests/utils/test_env.py index e92f391e1fe..afc5aa9207a 100644 --- a/tests/utils/test_env.py +++ b/tests/utils/test_env.py @@ -995,7 +995,7 @@ def test_create_venv_uses_patch_version_to_detect_compatibility_with_executable( def test_create_venv_fails_if_current_python_version_is_not_supported( - manager: EnvManager, poetry: "Poetry" + manager: EnvManager, poetry: Poetry ): if "VIRTUAL_ENV" in os.environ: del os.environ["VIRTUAL_ENV"]