Skip to content

feat(version): add development release bump option#10942

Open
Yijian6 wants to merge 1 commit into
python-poetry:mainfrom
Yijian6:version-dev-bump
Open

feat(version): add development release bump option#10942
Yijian6 wants to merge 1 commit into
python-poetry:mainfrom
Yijian6:version-dev-bump

Conversation

@Yijian6

@Yijian6 Yijian6 commented Jun 6, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds a --dev option to poetry version so existing bump rules can create or advance PEP 440 development releases.

Resolves: #8718

Why

The issue discussion settled on using --dev with the existing bump rules instead of adding an ambiguous standalone dev bump rule. This keeps version bumps moving forward and avoids the previous PR's decrement cases such as moving from a prerelease to an earlier dev release.

How

  • Reuses poetry-core's first_devrelease(), next_devrelease(), and without_devrelease() helpers.
  • Applies --dev only to known bump rules.
  • Increments .devN when the selected bump rule already targets the current development release base; otherwise creates .dev0 on the bumped target.
  • Lets the same command without --dev remove the development release suffix for the discussed release cases.

Testing

  • python -m pytest tests/console/commands/test_version.py -q
  • python -m ruff check src/poetry/console/commands/version.py tests/console/commands/test_version.py
  • python -m ruff format --check src/poetry/console/commands/version.py tests/console/commands/test_version.py
  • python -m mypy src/poetry/console/commands/version.py tests/console/commands/test_version.py
  • git diff --check

Breaking changes

None.

Pull Request Check List

  • Added tests for changed code.
  • Updated documentation for changed code.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've found 1 issue, and left some high level feedback:

  • The bump_rules set is recreated on every increment_version call; consider moving it to a class-level or module-level constant to avoid repeated allocation and to centralize the definition of supported bump rules.
  • When --dev is used with a non-bump rule (e.g. an explicit version string), it is silently ignored; consider either raising a clear error or logging a message so users know --dev only applies to the defined bump rules.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `bump_rules` set is recreated on every `increment_version` call; consider moving it to a class-level or module-level constant to avoid repeated allocation and to centralize the definition of supported bump rules.
- When `--dev` is used with a non-bump rule (e.g. an explicit version string), it is silently ignored; consider either raising a clear error or logging a message so users know `--dev` only applies to the defined bump rules.

## Individual Comments

### Comment 1
<location path="tests/console/commands/test_version.py" line_range="92-107" />
<code_context>
     assert command.increment_version(version, rule, True).text == expected


+@pytest.mark.parametrize(
+    "version, rule, next_phase, expected",
+    [
+        ("1.1.0", "major", False, "2.0.0.dev0"),
+        ("2.0.0.dev0", "major", False, "2.0.0.dev1"),
+        ("1.1.0", "minor", False, "1.2.0.dev0"),
+        ("1.1.0", "patch", False, "1.1.1.dev0"),
+        ("1.1.0", "premajor", False, "2.0.0a0.dev0"),
+        ("1.1.0", "preminor", False, "1.2.0a0.dev0"),
+        ("1.1.0", "prepatch", False, "1.1.1a0.dev0"),
+        ("1.1.0", "prerelease", False, "1.1.1a0.dev0"),
+        ("1.1.1a0.dev0", "prerelease", False, "1.1.1a0.dev1"),
+        ("1.1.0a2.dev1", "prerelease", True, "1.1.0b0.dev0"),
+    ],
+)
+def test_dev_version(
+    version: str,
+    rule: str,
+    next_phase: bool,
+    expected: str,
+    command: VersionCommand,
+) -> None:
+    assert (
+        command.increment_version(version, rule, next_phase, dev=True).text == expected
+    )
</code_context>
<issue_to_address>
**suggestion (testing):** Add edge-case test where `--dev` bumps from a dev version to a different base (e.g. `1.1.0.dev0``1.2.0.dev0` with `minor --dev`).

Current parameters cover creating dev releases from stable versions and incrementing dev within the same base (e.g. `2.0.0.dev0` + major → `2.0.0.dev1`). Please also add a case where the starting version is already a dev release but the bump changes the base, e.g.:

```python
("1.1.0.dev0", "minor", False, "1.2.0.dev0"),
```

in `test_dev_version`. This will assert that `--dev` resets to `.dev0` when the base version changes, matching the `new == parsed.without_devrelease()` condition.

```suggestion
@pytest.mark.parametrize(
    "version, rule, next_phase, expected",
    [
        ("1.1.0", "major", False, "2.0.0.dev0"),
        ("2.0.0.dev0", "major", False, "2.0.0.dev1"),
        ("1.1.0", "minor", False, "1.2.0.dev0"),
        ("1.1.0.dev0", "minor", False, "1.2.0.dev0"),
        ("1.1.0", "patch", False, "1.1.1.dev0"),
        ("1.1.0", "premajor", False, "2.0.0a0.dev0"),
        ("1.1.0", "preminor", False, "1.2.0a0.dev0"),
        ("1.1.0", "prepatch", False, "1.1.1a0.dev0"),
        ("1.1.0", "prerelease", False, "1.1.1a0.dev0"),
        ("1.1.1a0.dev0", "prerelease", False, "1.1.1a0.dev1"),
        ("1.1.0a2.dev1", "prerelease", True, "1.1.0b0.dev0"),
    ],
)
def test_dev_version(
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread tests/console/commands/test_version.py Outdated
Comment on lines +92 to +107
@pytest.mark.parametrize(
"version, rule, next_phase, expected",
[
("1.1.0", "major", False, "2.0.0.dev0"),
("2.0.0.dev0", "major", False, "2.0.0.dev1"),
("1.1.0", "minor", False, "1.2.0.dev0"),
("1.1.0", "patch", False, "1.1.1.dev0"),
("1.1.0", "premajor", False, "2.0.0a0.dev0"),
("1.1.0", "preminor", False, "1.2.0a0.dev0"),
("1.1.0", "prepatch", False, "1.1.1a0.dev0"),
("1.1.0", "prerelease", False, "1.1.1a0.dev0"),
("1.1.1a0.dev0", "prerelease", False, "1.1.1a0.dev1"),
("1.1.0a2.dev1", "prerelease", True, "1.1.0b0.dev0"),
],
)
def test_dev_version(

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion (testing): Add edge-case test where --dev bumps from a dev version to a different base (e.g. 1.1.0.dev01.2.0.dev0 with minor --dev).

Current parameters cover creating dev releases from stable versions and incrementing dev within the same base (e.g. 2.0.0.dev0 + major → 2.0.0.dev1). Please also add a case where the starting version is already a dev release but the bump changes the base, e.g.:

("1.1.0.dev0", "minor", False, "1.2.0.dev0"),

in test_dev_version. This will assert that --dev resets to .dev0 when the base version changes, matching the new == parsed.without_devrelease() condition.

Suggested change
@pytest.mark.parametrize(
"version, rule, next_phase, expected",
[
("1.1.0", "major", False, "2.0.0.dev0"),
("2.0.0.dev0", "major", False, "2.0.0.dev1"),
("1.1.0", "minor", False, "1.2.0.dev0"),
("1.1.0", "patch", False, "1.1.1.dev0"),
("1.1.0", "premajor", False, "2.0.0a0.dev0"),
("1.1.0", "preminor", False, "1.2.0a0.dev0"),
("1.1.0", "prepatch", False, "1.1.1a0.dev0"),
("1.1.0", "prerelease", False, "1.1.1a0.dev0"),
("1.1.1a0.dev0", "prerelease", False, "1.1.1a0.dev1"),
("1.1.0a2.dev1", "prerelease", True, "1.1.0b0.dev0"),
],
)
def test_dev_version(
@pytest.mark.parametrize(
"version, rule, next_phase, expected",
[
("1.1.0", "major", False, "2.0.0.dev0"),
("2.0.0.dev0", "major", False, "2.0.0.dev1"),
("1.1.0", "minor", False, "1.2.0.dev0"),
("1.1.0.dev0", "minor", False, "1.2.0.dev0"),
("1.1.0", "patch", False, "1.1.1.dev0"),
("1.1.0", "premajor", False, "2.0.0a0.dev0"),
("1.1.0", "preminor", False, "1.2.0a0.dev0"),
("1.1.0", "prepatch", False, "1.1.1a0.dev0"),
("1.1.0", "prerelease", False, "1.1.1a0.dev0"),
("1.1.1a0.dev0", "prerelease", False, "1.1.1a0.dev1"),
("1.1.0a2.dev1", "prerelease", True, "1.1.0b0.dev0"),
],
)
def test_dev_version(

@Yijian6 Yijian6 force-pushed the version-dev-bump branch from dd1cd4f to 918b4f9 Compare June 6, 2026 13:26
@Yijian6 Yijian6 force-pushed the version-dev-bump branch from 918b4f9 to 14f8b6c Compare June 7, 2026 00:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add 'dev' as version bump rule for developmental releases.

1 participant