Skip to content

Commit

Permalink
feat: add 'dev' as a version bump rule to increment versions with .devM
Browse files Browse the repository at this point in the history
  • Loading branch information
gaileyleseman committed Nov 27, 2023
1 parent 0578ed8 commit 738dcab
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
5 changes: 4 additions & 1 deletion docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ bump rule is provided.

The new version should be a valid [PEP 440](https://peps.python.org/pep-0440/)
string or a valid bump rule: `patch`, `minor`, `major`, `prepatch`, `preminor`,
`premajor`, `prerelease`.
`premajor`, `prerelease`, `dev`.

{{% note %}}

Expand All @@ -697,6 +697,9 @@ The table below illustrates the effect of these rules with concrete examples.
| prerelease | 1.0.2 | 1.0.3a0 |
| prerelease | 1.0.3a0 | 1.0.3a1 |
| prerelease | 1.0.3b0 | 1.0.3b1 |
| dev | 1.0.2 | 1.0.2.dev0 |
| dev | 1.0.2.dev0 | 1.0.2.dev1 |
| dev | 1.0.2a0 | 1.0.2a0.dev0 |

The option `--next-phase` allows the increment of prerelease phase versions.

Expand Down
12 changes: 9 additions & 3 deletions src/poetry/console/commands/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
class VersionCommand(Command):
name = "version"
description = (
"Shows the version of the project or bumps it when a valid "
"bump rule is provided."
"Shows the version of the project or bumps it when a valid bump rule is"
" provided."
)

arguments = [
Expand All @@ -45,7 +45,7 @@ class VersionCommand(Command):
bump rule is provided.
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, dev.
"""

RESERVED = {
Expand All @@ -56,6 +56,7 @@ class VersionCommand(Command):
"preminor",
"prepatch",
"prerelease",
"dev",
}

def handle(self) -> int:
Expand Down Expand Up @@ -122,6 +123,11 @@ def increment_version(
new = Version(parsed.epoch, parsed.release, pre)
else:
new = parsed.next_patch().first_prerelease()
elif rule == "dev":
if parsed.is_devrelease():
new = parsed.next_devrelease()
else:
new = parsed.first_devrelease()
else:
new = Version.parse(rule)

Expand Down
3 changes: 3 additions & 0 deletions tests/console/commands/test_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ def tester(command_tester_factory: CommandTesterFactory) -> CommandTester:
("1.2.3beta1", "prerelease", "1.2.3b2"),
("1.2.3b1", "prerelease", "1.2.3b2"),
("1.2.3", "prerelease", "1.2.4a0"),
("1.2.3", "dev", "1.2.3.dev0"),
("1.2.3.dev0", "dev", "1.2.3.dev1"),
("1.2.3a0", "dev", "1.2.3a0.dev0"),
("0.0.0", "1.2.3", "1.2.3"),
],
)
Expand Down

0 comments on commit 738dcab

Please sign in to comment.