Skip to content

Commit 62dfe8e

Browse files
committed
Fix commas in legacy multiline options
1 parent e13b0f0 commit 62dfe8e

5 files changed

+31
-2
lines changed

bumpversion/autocast.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,14 @@ def listify(s: str) -> list:
4343
Returns:
4444
List of homogenous basic types.
4545
"""
46-
if "," not in s and "\n" not in s:
46+
if "\n" in s:
47+
str_list = s.strip().split("\n")
48+
elif "," in s:
49+
str_list = s.strip().split(",")
50+
else:
4751
raise ValueError("Not a List")
4852

4953
# derive the type of the variable
50-
str_list = s.strip().split(",") if "," in s else s.strip().split("\n")
5154
element_caster = str
5255
for caster in (boolify, int, float, noneify, element_caster):
5356
with contextlib.suppress(ValueError):
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[bumpversion]
2+
current_version = 1.0.0
3+
4+
[bumpversion:file:MULTILINE_SEARCH.md]
5+
search = **unreleased**,
6+
**v{current_version}**,
7+
replace = **unreleased**,
8+
**v{new_version}**,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"current_version": "1.0.0",
3+
"files": [
4+
{
5+
"filename": "MULTILINE_SEARCH.md",
6+
"search": "**unreleased**,\n**v{current_version}**,",
7+
"replace": "**unreleased**,\n**v{new_version}**,"
8+
}
9+
],
10+
"parts": {}
11+
}

tests/test_autocast.py

+2
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def test_noneify():
4646
param("1,2,3,4", [1, 2, 3, 4], id="int"),
4747
param("1\n2\n3\n4", [1, 2, 3, 4], id="int"),
4848
param("s,t,r", ["s", "t", "r"], id="str"),
49+
param("s,\nt,\nr\n", ["s,", "t,", "r"], id="str_newline"),
4950
param("1.1,2,3.14", [1.1, 2.0, 3.14], id="float"),
5051
param("True,False,true,false", [True, False, True, False], id="bool"),
5152
param("None,None,None", [None, None, None], id="none"),
@@ -75,6 +76,7 @@ def test_listify_invalid():
7576
param("False", False, id="False"),
7677
param("1,2,3,4", [1, 2, 3, 4], id="int-list"),
7778
param("s,t,r", ["s", "t", "r"], id="str-list"),
79+
param("s,\nt,\nr\n", ["s,", "t,", "r"], id="str-list-newline"),
7880
param("1", 1, id="int"),
7981
param("1.0", 1.0, id="float"),
8082
param(1, 1, id="real-int"),

tests/test_config/test_files_legacy.py

+5
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ def cfg_file(request) -> str:
3535
[
3636
param("basic_cfg.cfg", "basic_cfg_expected.json", id="ini basic cfg"),
3737
param("legacy_multiline_search.cfg", "legacy_multiline_search_expected.json", id="multiline search cfg"),
38+
param(
39+
"legacy_multiline_search_comma.cfg",
40+
"legacy_multiline_search_comma_expected.json",
41+
id="multiline search comma cfg",
42+
),
3843
],
3944
)
4045
def test_read_ini_file(conf_file: str, expected_file: str, fixtures_path: Path) -> None:

0 commit comments

Comments
 (0)