diff --git a/src/poetry/core/factory.py b/src/poetry/core/factory.py index daa6a96d0..a111f480e 100644 --- a/src/poetry/core/factory.py +++ b/src/poetry/core/factory.py @@ -72,7 +72,7 @@ def create_poetry( def get_package(cls, name: str, version: str) -> ProjectPackage: from poetry.core.packages.project_package import ProjectPackage - return ProjectPackage(name, version, version) + return ProjectPackage(name, version) @classmethod def _add_package_group_dependencies( diff --git a/src/poetry/core/packages/package.py b/src/poetry/core/packages/package.py index 3b50b2896..66ac69299 100644 --- a/src/poetry/core/packages/package.py +++ b/src/poetry/core/packages/package.py @@ -2,6 +2,7 @@ import copy import re +import warnings from contextlib import contextmanager from pathlib import Path @@ -69,6 +70,14 @@ def __init__( """ from poetry.core.version.markers import AnyMarker + if pretty_version is not None: + warnings.warn( + "The `pretty_version` parameter is deprecated and will be removed" + " in a future release.", + DeprecationWarning, + stacklevel=2, + ) + super().__init__( name, source_type=source_type, @@ -79,7 +88,7 @@ def __init__( features=features, ) - self._set_version(version, pretty_version) + self._set_version(version) self.description = "" @@ -130,7 +139,7 @@ def version(self) -> Version: @property def pretty_version(self) -> str: - return self._pretty_version + return self._version.text @property def unique_name(self) -> str: @@ -146,22 +155,22 @@ def pretty_string(self) -> str: @property def full_pretty_version(self) -> str: if self.source_type in ["file", "directory", "url"]: - return f"{self._pretty_version} {self.source_url}" + return f"{self.pretty_version} {self.source_url}" if self.source_type not in ["hg", "git"]: - return self._pretty_version + return self.pretty_version ref: str | None if self.source_resolved_reference and len(self.source_resolved_reference) == 40: ref = self.source_resolved_reference[0:7] - return f"{self._pretty_version} {ref}" + return f"{self.pretty_version} {ref}" # if source reference is a sha1 hash -- truncate if self.source_reference and len(self.source_reference) == 40: - return f"{self._pretty_version} {self.source_reference[0:7]}" + return f"{self.pretty_version} {self.source_reference[0:7]}" ref = self._source_resolved_reference or self._source_reference - return f"{self._pretty_version} {ref}" + return f"{self.pretty_version} {ref}" @property def authors(self) -> list[str]: @@ -210,9 +219,7 @@ def all_requires( for dependency in group.dependencies ] - def _set_version( - self, version: str | Version, pretty_version: str | None = None - ) -> None: + def _set_version(self, version: str | Version) -> None: from poetry.core.constraints.version import Version if not isinstance(version, Version): @@ -224,7 +231,6 @@ def _set_version( ) self._version = version - self._pretty_version = pretty_version or version.text def _get_author(self) -> dict[str, str | None]: if not self._authors: @@ -368,8 +374,6 @@ def urls(self) -> dict[str, str]: @property def readme(self) -> Path | None: - import warnings - warnings.warn( "`readme` is deprecated: you are getting only the first readme file. Please" " use the plural form `readmes`.", @@ -379,8 +383,6 @@ def readme(self) -> Path | None: @readme.setter def readme(self, path: Path) -> None: - import warnings - warnings.warn( "`readme` is deprecated. Please assign a tuple to the plural form" " `readmes`.", diff --git a/src/poetry/core/packages/project_package.py b/src/poetry/core/packages/project_package.py index c993fc991..046c8da28 100644 --- a/src/poetry/core/packages/project_package.py +++ b/src/poetry/core/packages/project_package.py @@ -1,5 +1,7 @@ from __future__ import annotations +import warnings + from typing import TYPE_CHECKING from typing import Any @@ -22,7 +24,15 @@ def __init__( version: str | Version, pretty_version: str | None = None, ) -> None: - super().__init__(name, version, pretty_version) + if pretty_version is not None: + warnings.warn( + "The `pretty_version` parameter is deprecated and will be removed" + " in a future release.", + DeprecationWarning, + stacklevel=2, + ) + + super().__init__(name, version) self.build_config: dict[str, Any] = {} self.packages: list[dict[str, Any]] = [] diff --git a/tests/packages/test_package.py b/tests/packages/test_package.py index 998b25e22..5ee406968 100644 --- a/tests/packages/test_package.py +++ b/tests/packages/test_package.py @@ -443,7 +443,6 @@ def test_package_clone(f: Factory) -> None: p = Package( "lol_wut", "3.141.5926535", - pretty_version="③.⑭.⑮", source_type="git", source_url="http://some.url", source_reference="fe4d2adabf3feb5d32b70ab5c105285fa713b10c",