diff --git a/poetry/inspection/info.py b/poetry/inspection/info.py index ae5f59bd63f..9c602603ba2 100644 --- a/poetry/inspection/info.py +++ b/poetry/inspection/info.py @@ -141,7 +141,7 @@ def to_package( package = Package( name=name, - version=self.version, + version=self.public_version, source_type=self._source_type, source_url=self._source_url, source_reference=self._source_reference, @@ -588,3 +588,10 @@ def from_path(cls, path: Path) -> "PackageInfo": return cls.from_bdist(path=path) except PackageInfoError: return cls.from_sdist(path=path) + + @property + def public_version(self) -> str: + """ + Removes + from packages. + """ + return self.version.split("+")[0] diff --git a/tests/inspection/test_info.py b/tests/inspection/test_info.py index 3a15e605a6f..11f204a4c2e 100644 --- a/tests/inspection/test_info.py +++ b/tests/inspection/test_info.py @@ -4,6 +4,8 @@ import pytest +from poetry.core.packages.package import Package +from poetry.core.semver.version import Version from poetry.inspection.info import PackageInfo from poetry.inspection.info import PackageInfoError from poetry.utils._compat import decode @@ -225,3 +227,19 @@ def test_info_prefer_poetry_config_over_egg_info(): FIXTURE_DIR_INSPECTIONS / "demo_with_obsolete_egg_info" ) demo_check_info(info) + + +@pytest.mark.parametrize( + "version,expected", + [ + ("1.2.3+local_super_version", "1.2.3"), + ("1.2.3+localVersion", "1.2.3"), + ("1.2.3", "1.2.3"), + ], +) +def test_info_public_version(version, expected): + package_info = PackageInfo(name="test-package", version=version) + assert package_info.public_version == expected + package = package_info.to_package() # type: Package + assert type(package.version) == Version + assert package.version.text == expected