Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added 'dev' as a version bump rule to increment versions with .devM #8719

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 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 @@ -684,6 +684,10 @@ If you would like to use semantic versioning for your project, please see

{{% /note %}}

If you use the `dev` rule on a stable version, it will first be updated to a
prerelease version to increment the version numbers before appending the
`.dev0` suffix.

The table below illustrates the effect of these rules with concrete examples.

| rule | before | after |
Expand All @@ -697,6 +701,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.3a0.dev0 |
| dev | 1.1.0a0 | 1.1.0a0.dev0 |
| dev | 1.0.2a0 | 1.0.2a0.dev0 |
Comment on lines +705 to +706
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still a decrement. (1.1.0a0.dev0 comes before 1.1.0a0.)


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

Expand Down
16 changes: 13 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,15 @@ def increment_version(
new = Version(parsed.epoch, parsed.release, pre)
else:
new = parsed.next_patch().first_prerelease()
elif rule == "dev":
if parsed.is_stable():
new = self.increment_version(
version, "prerelease", next_phase
).first_devrelease()
elif parsed.is_devrelease():
new = parsed.next_devrelease()
else:
new = parsed.first_devrelease()
Comment on lines +133 to +134
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a decrement.

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.4a0.dev0"),
("1.2.3a0", "dev", "1.2.3a0.dev0"),
("1.2.3a0.dev0", "dev", "1.2.3a0.dev1"),
("0.0.0", "1.2.3", "1.2.3"),
],
)
Expand Down