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

Strip Local version label (PEP 440) from Packages build from PackageInfo #4221

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 8 additions & 1 deletion poetry/inspection/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 +<local version label> from packages.
"""
return self.version.split("+")[0]
19 changes: 19 additions & 0 deletions tests/inspection/test_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -225,3 +227,20 @@ def test_info_prefer_poetry_config_over_egg_info():
FIXTURE_DIR_INSPECTIONS / "demo_with_obsolete_egg_info"
)
demo_check_info(info)


def test_info_public_version():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to see these two combined into a parameterized test, and then this should be good to go.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

<mickey-mouse-voice>I got three in one blow!</mickey-mouse-voice>

package_info = PackageInfo(version="1.2.3+localVersion")
assert package_info.public_version == "1.2.3"


def test_info_public_version_no_mutation():
package_info = PackageInfo(version="1.2.3")
assert package_info.public_version == "1.2.3"


def test_package_from_info_with_public_version():
package_info = PackageInfo(name="test-package", version="1.2.3+local_super_version")
package = package_info.to_package() # type: Package
assert type(package.version) == Version
assert package.version.text == "1.2.3"