Skip to content

Commit 6b369fe

Browse files
Fixed: allow omitting the current version in sample-config
If the current version is explicitly left empty during the `sample-config` questionnaire, the resulting `tool.bumpversion` table now lacks a `current_version` key, and will fall back to PEP 621 `project.version` (if not dynamic). The instruction text specifically hints at this new functionality.
1 parent 3032450 commit 6b369fe

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

bumpversion/config/create.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,14 @@ def create_configuration(destination: str, prompt: bool) -> TOMLDocument:
2323
if prompt:
2424
allow_dirty_default = "(Y/n)" if config["allow_dirty"] else "(y/N)"
2525
answers = questionary.form(
26-
current_version=questionary.text("What is the current version?", default=config["current_version"]),
26+
current_version=questionary.text(
27+
"What is the current version?",
28+
default=config["current_version"],
29+
instruction=(
30+
"If omitted, use the project.version key in pyproject.toml. "
31+
"(Does not support dynamically set versions.)"
32+
),
33+
),
2734
commit=questionary.confirm(
2835
"Commit changes made when bumping to version control?", default=config["commit"]
2936
),
@@ -45,6 +52,8 @@ def create_configuration(destination: str, prompt: bool) -> TOMLDocument:
4552
config.update(answers)
4653

4754
for key, val in config.items():
55+
if key == "current_version" and not val:
56+
continue
4857
destination_config["tool"]["bumpversion"][key] = val if val is not None else ""
4958

5059
return destination_config

tests/test_config/test_create.py

+17
Original file line numberDiff line numberDiff line change
@@ -166,3 +166,20 @@ def test_prompt_true_asks_questions_and_updates_result(self, tmp_path: Path, def
166166
assert destination_config["tool"]["bumpversion"]["tag_message"] == default_config["tag_message"]
167167
assert destination_config["tool"]["bumpversion"]["tag_name"] == default_config["tag_name"]
168168
assert mocked_questionary.form.return_value.ask.call_count == 1
169+
170+
def test_prompt_true_empty_current_version_removes_key(self, tmp_path: Path, default_config: dict, mocker):
171+
"""If prompt is True and if current_version is empty, that key should be missing in the answer."""
172+
answer = {
173+
"current_version": "",
174+
"commit": True,
175+
"allow_dirty": True,
176+
"tag": True,
177+
"commit_args": "--no-verify",
178+
}
179+
mocked_questionary = mocker.patch("bumpversion.config.create.questionary", autospec=True)
180+
mocked_questionary.form.return_value.ask.return_value = answer
181+
with inside_dir(tmp_path):
182+
destination_config = create_configuration("pyproject.toml", prompt=True)
183+
184+
assert "current_version" not in destination_config["tool"]["bumpversion"]
185+
assert mocked_questionary.form.return_value.ask.call_count == 1

0 commit comments

Comments
 (0)