Skip to content

Commit

Permalink
Add support for legacy multiline search options (refs #98)
Browse files Browse the repository at this point in the history
  • Loading branch information
ziima committed Jan 4, 2024
1 parent 0e84e1c commit 278eae5
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions bumpversion/config/files_legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ def read_ini_file(file_path: Path) -> Dict[str, Any]: # noqa: C901
"filename": section_parts[2],
}
file_options.update(options)
if "search" in file_options and isinstance(file_options["search"], list):
file_options["search"] = "\n".join(file_options["search"])
if "replace" in file_options and isinstance(file_options["replace"], list):
file_options["replace"] = "\n".join(file_options["replace"])
bumpversion_options["files"].append(file_options)
Expand All @@ -66,6 +68,8 @@ def read_ini_file(file_path: Path) -> Dict[str, Any]: # noqa: C901
"glob": section_parts[2],
}
file_options.update(options)
if "search" in file_options and isinstance(file_options["search"], list):
file_options["search"] = "\n".join(file_options["search"])
if "replace" in file_options and isinstance(file_options["replace"], list):
file_options["replace"] = "\n".join(file_options["replace"])
bumpversion_options["files"].append(file_options)
Expand Down
8 changes: 8 additions & 0 deletions tests/fixtures/legacy_multiline_search.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[bumpversion]
current_version = 1.0.0

[bumpversion:file:MULTILINE_SEARCH.md]
search = **unreleased**
**v{current_version}**
replace = **unreleased**
**v{new_version}**
11 changes: 11 additions & 0 deletions tests/fixtures/legacy_multiline_search_expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"current_version": "1.0.0",
"files": [
{
"filename": "MULTILINE_SEARCH.md",
"search": "**unreleased**\n**v{current_version}**",
"replace": "**unreleased**\n**v{new_version}**"
}
],
"parts": {}
}
1 change: 1 addition & 0 deletions tests/test_config/test_files_legacy.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def cfg_file(request) -> str:
["conf_file", "expected_file"],
[
param("basic_cfg.cfg", "basic_cfg_expected.json", id="ini basic cfg"),
param("legacy_multiline_search.cfg", "legacy_multiline_search_expected.json", id="multiline search cfg"),
],
)
def test_read_ini_file(conf_file: str, expected_file: str, fixtures_path: Path) -> None:
Expand Down

0 comments on commit 278eae5

Please sign in to comment.