Skip to content

Commit

Permalink
Add uvx examples
Browse files Browse the repository at this point in the history
  • Loading branch information
vemel committed Nov 9, 2024
1 parent d3894ad commit 956a81a
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 38 deletions.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- [Features](#features)
- [Installation](#installation)
- [Usage](#usage)
- [uv](#uv)
- [CLI](#cli)
- [Python library](#python-library)
- [Versioning](#versioning)
Expand All @@ -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
Expand Down
10 changes: 10 additions & 0 deletions newversion/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
52 changes: 20 additions & 32 deletions newversion/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
)

Expand Down Expand Up @@ -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:
"""
Expand Down
8 changes: 4 additions & 4 deletions newversion/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,7 @@ select = [
"PL", # pylint
]
ignore = [
"C901",
"PLR0911",
"PLR0912",
"PLR6201",
"D107", # undocumented-public-init
"D200", # fits-on-one-line
Expand Down

0 comments on commit 956a81a

Please sign in to comment.