Skip to content

Commit

Permalink
add setter for version on ProjectPackage
Browse files Browse the repository at this point in the history
This enables support for dynamically setting the package version
(e.g., from a plugin)

Resolves: python-poetry/poetry#5493
  • Loading branch information
bcavagnolo committed Aug 24, 2022
1 parent 4456c52 commit d8eb476
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/poetry/core/packages/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,7 @@ def __init__(
features=features,
)

if not isinstance(version, Version):
self._version = Version.parse(version)
self._pretty_version = pretty_version or version
else:
self._version = version
self._pretty_version = pretty_version or self._version.text
self._set_version(version, pretty_version)

self.description = ""

Expand Down Expand Up @@ -216,6 +211,18 @@ def all_requires(
for dependency in group.dependencies
]

def _set_version(self,
version: str | Version,
pretty_version: str | None = None) -> None:

if not isinstance(version, Version):
self._version = Version.parse(version)
self._pretty_version = pretty_version or version
else:
self._version = version
self._pretty_version = pretty_version or self._version.text


def _get_author(self) -> dict[str, str | None]:
if not self._authors:
return {"name": None, "email": None}
Expand Down
4 changes: 4 additions & 0 deletions src/poetry/core/packages/project_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ def python_versions(self, value: str) -> None:
create_nested_marker("python_version", self._python_constraint)
)

@version.setter
def version(self, value: str | Version) -> None:
self._set_version(value)

@property
def urls(self) -> dict[str, str]:
urls = super().urls
Expand Down

0 comments on commit d8eb476

Please sign in to comment.