"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "poetry/console/commands/version.py" between
poetry-1.1.15.tar.gz and poetry-1.2.0.tar.gz

About: Poetry is a tool for dependency management and packaging in Python.

version.py  (poetry-1.1.15):version.py  (poetry-1.2.0)
from cleo import argument from __future__ import annotations
from cleo import option
from .command import Command from typing import TYPE_CHECKING
from typing import Any
class VersionCommand(Command): from cleo.helpers import argument
from cleo.helpers import option
from tomlkit.toml_document import TOMLDocument
from poetry.console.commands.command import Command
if TYPE_CHECKING:
from poetry.core.semver.version import Version
class VersionCommand(Command):
name = "version" name = "version"
description = ( description = (
"Shows the version of the project or bumps it when a valid " "Shows the version of the project or bumps it when a valid "
"bump rule is provided." "bump rule is provided."
) )
arguments = [ arguments = [
argument( argument(
"version", "version",
"The version number or the rule to update the version.", "The version number or the rule to update the version.",
optional=True, optional=True,
) )
] ]
options = [option("short", "s", "Output the version number only")] options = [
option("short", "s", "Output the version number only"),
option(
"dry-run",
None,
"Do not update pyproject.toml file",
),
]
help = """\ help = """\
The version command shows the current version of the project or bumps the versio n of The version command shows the current version of the project or bumps the versio n of
the project and writes the new version back to <comment>pyproject.toml</> if a v alid the project and writes the new version back to <comment>pyproject.toml</> if a v alid
bump rule is provided. bump rule is provided.
The new version should ideally be a valid semver string or a valid bump rule: The new version should ideally be a valid semver string or a valid bump rule:
patch, minor, major, prepatch, preminor, premajor, prerelease. patch, minor, major, prepatch, preminor, premajor, prerelease.
""" """
RESERVED = { RESERVED = {
"major", "major",
"minor", "minor",
"patch", "patch",
"premajor", "premajor",
"preminor", "preminor",
"prepatch", "prepatch",
"prerelease", "prerelease",
} }
def handle(self): def handle(self) -> int:
version = self.argument("version") version = self.argument("version")
if version: if version:
version = self.increment_version( version = self.increment_version(
self.poetry.package.pretty_version, version self.poetry.package.pretty_version, version
) )
self.line( if self.option("short"):
"Bumping version from <b>{}</> to <fg=green>{}</>".format( self.line(version.to_string())
self.poetry.package.pretty_version, version else:
self.line(
f"Bumping version from <b>{self.poetry.package.pretty_versio
n}</>"
f" to <fg=green>{version}</>"
) )
)
content = self.poetry.file.read() if not self.option("dry-run"):
poetry_content = content["tool"]["poetry"] content: dict[str, Any] = self.poetry.file.read()
poetry_content["version"] = version.text poetry_content = content["tool"]["poetry"]
poetry_content["version"] = version.text
self.poetry.file.write(content) assert isinstance(content, TOMLDocument)
self.poetry.file.write(content)
else: else:
if self.option("short"): if self.option("short"):
self.line("{}".format(self.poetry.package.pretty_version)) self.line(self.poetry.package.pretty_version)
else: else:
self.line( self.line(
"<comment>{}</> <info>{}</>".format( f"<comment>{self.poetry.package.name}</>"
self.poetry.package.name, self.poetry.package.pretty_ver f" <info>{self.poetry.package.pretty_version}</>"
sion
)
) )
def increment_version(self, version, rule): return 0
from poetry.core.semver import Version
def increment_version(self, version: str, rule: str) -> Version:
from poetry.core.semver.version import Version
try: try:
version = Version.parse(version) parsed = Version.parse(version)
except ValueError: except ValueError:
raise ValueError("The project's version doesn't seem to follow semve r") raise ValueError("The project's version doesn't seem to follow semve r")
if rule in {"major", "premajor"}: if rule in {"major", "premajor"}:
new = version.next_major new = parsed.next_major()
if rule == "premajor": if rule == "premajor":
new = new.first_prerelease new = new.first_prerelease()
elif rule in {"minor", "preminor"}: elif rule in {"minor", "preminor"}:
new = version.next_minor new = parsed.next_minor()
if rule == "preminor": if rule == "preminor":
new = new.first_prerelease new = new.first_prerelease()
elif rule in {"patch", "prepatch"}: elif rule in {"patch", "prepatch"}:
new = version.next_patch new = parsed.next_patch()
if rule == "prepatch": if rule == "prepatch":
new = new.first_prerelease new = new.first_prerelease()
elif rule == "prerelease": elif rule == "prerelease":
if version.is_prerelease(): if parsed.is_unstable():
pre = version.prerelease pre = parsed.pre
new_prerelease = int(pre[1]) + 1 assert pre is not None
new = Version.parse( new = Version(parsed.epoch, parsed.release, pre.next())
"{}.{}.{}-{}".format(
version.major,
version.minor,
version.patch,
".".join([pre[0], str(new_prerelease)]),
)
)
else: else:
new = version.next_patch.first_prerelease new = parsed.next_patch().first_prerelease()
else: else:
new = Version.parse(rule) new = Version.parse(rule)
return new return new
 End of changes. 22 change blocks. 
40 lines changed or deleted 53 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)