diff --git a/README.md b/README.md index 1ee34ee..8794b13 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ - [Features](#features) - [Installation](#installation) - [Usage](#usage) + - [uv](#uv) - [CLI](#cli) - [Python library](#python-library) - [Versioning](#versioning) @@ -33,6 +34,26 @@ python -m pip install newversion ## Usage +### uv + +```bash +# bump Python package micro version and update package version +# 1.2.3 -> 1.2.4 +uvx newversion -p bump --save + +# bump Python package minor version and update package version +# 1.2.3 -> 1.3.0 +uvx newversion -p bump minor --save + +# bump Python package major version and update package version +# 1.2.3 -> 2.0.0 +uvx newversion -p bump major --save + +# bump Python package RC pre-release version and update package version +# 1.2.3 -> 1.2.4rc1 +uvx newversion -p bump pre --save +``` + ### CLI ```bash diff --git a/newversion/constants.py b/newversion/constants.py index 08c299b..9822a48 100644 --- a/newversion/constants.py +++ b/newversion/constants.py @@ -9,6 +9,16 @@ LOGGER_NAME: Final = "newversion" +class Prerelease: + """ + Pre-release constants as they are named in PEP 440. + """ + + A: Final = "a" + B: Final = "b" + RC: Final = "rc" + + class VersionParts(enum.Enum): """ Utility class with constants for version parts. diff --git a/newversion/executor.py b/newversion/executor.py index 9555672..221206a 100644 --- a/newversion/executor.py +++ b/newversion/executor.py @@ -6,7 +6,7 @@ from pathlib import Path from typing import Optional -from newversion.constants import Commands, VersionParts +from newversion.constants import Commands, Prerelease, VersionParts from newversion.exceptions import ExecutorError, PackageVersionError from newversion.package_version import PackageVersion from newversion.type_defs import OperatorTypeDef @@ -54,21 +54,21 @@ def command_get( if release == VersionParts.ALPHA: return ( str(self.version.pre[-1]) - if self.version.pre and self.version.pre[0] == "a" + if self.version.pre and self.version.pre[0] == Prerelease.A else "0" ) if release == VersionParts.BETA: return ( str(self.version.pre[-1]) - if self.version.pre and self.version.pre[0] == "b" + if self.version.pre and self.version.pre[0] == Prerelease.B else "0" ) if release == VersionParts.RC: return ( str(self.version.pre[-1]) - if self.version.pre and self.version.pre[0] == "rc" + if self.version.pre and self.version.pre[0] == Prerelease.RC else "0" ) @@ -133,35 +133,23 @@ def command_set(self, release: VersionParts, value: int) -> Version: A new Version. """ if release == VersionParts.PRE: - if self.version.prerelease_type == VersionParts.ALPHA.value: - return self.version.replace(alpha=value) - if self.version.prerelease_type == VersionParts.BETA.value: - return self.version.replace(beta=value) - if self.version.prerelease_type == VersionParts.RC.value: - return self.version.replace(rc=value) - - return self.version.replace(rc=value) - - if release == VersionParts.POST: - return self.version.replace(post=value) - if release == VersionParts.EPOCH: - return self.version.replace(epoch=value) - if release == VersionParts.MAJOR: - return self.version.replace(major=value) - if release == VersionParts.MINOR: - return self.version.replace(minor=value) - if release == VersionParts.MICRO: - return self.version.replace(micro=value) - if release == VersionParts.ALPHA: - return self.version.replace(alpha=value) - if release == VersionParts.BETA: - return self.version.replace(beta=value) - if release == VersionParts.RC: - return self.version.replace(rc=value) - if release == VersionParts.DEV: - return self.version.replace(dev=value) + return self.version.replace( + alpha=value if self.version.prerelease_type == VersionParts.ALPHA.value else None, + beta=value if self.version.prerelease_type == VersionParts.BETA.value else None, + rc=value if self.version.prerelease_type in {VersionParts.RC.value, None} else None, + ) - raise ExecutorError(f"Unknown release name: {release}") from None + return self.version.replace( + post=value if release == VersionParts.POST else None, + epoch=value if release == VersionParts.EPOCH else None, + major=value if release == VersionParts.MAJOR else None, + minor=value if release == VersionParts.MINOR else None, + micro=value if release == VersionParts.MICRO else None, + alpha=value if release == VersionParts.ALPHA else None, + beta=value if release == VersionParts.BETA else None, + rc=value if release == VersionParts.RC else None, + dev=value if release == VersionParts.DEV else None, + ) def command_stable(self) -> Version: """ diff --git a/newversion/version.py b/newversion/version.py index f68bd9a..458b533 100644 --- a/newversion/version.py +++ b/newversion/version.py @@ -7,7 +7,7 @@ import packaging.version from typing_extensions import Self -from newversion.constants import VersionParts +from newversion.constants import Prerelease, VersionParts from newversion.type_defs import ( BaseVersion, PrereleaseLooseTypeDef, @@ -56,11 +56,11 @@ def prerelease_type(self) -> Optional[PrereleaseTypeDef]: return None letter = self.pre[0] - if letter == "rc": + if letter == Prerelease.RC: return VersionParts.RC.value - if letter == "a": + if letter == Prerelease.A: return VersionParts.ALPHA.value - if letter == "b": + if letter == Prerelease.B: return VersionParts.BETA.value return None diff --git a/pyproject.toml b/pyproject.toml index 94356be..0108935 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -131,9 +131,7 @@ select = [ "PL", # pylint ] ignore = [ - "C901", "PLR0911", - "PLR0912", "PLR6201", "D107", # undocumented-public-init "D200", # fits-on-one-line