Skip to content

Commit

Permalink
Fixed configuration file detection.
Browse files Browse the repository at this point in the history
Doesn't just stop when it finds one, it checks for the existence of the header.
  • Loading branch information
coordt committed Apr 9, 2023
1 parent 0aea9dc commit fbf85c2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
2 changes: 1 addition & 1 deletion bumpversion/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def find_config_file(explicit_file: Union[str, Path, None] = None) -> Union[Path
"""
search_paths = [Path(explicit_file)] if explicit_file else CONFIG_FILE_SEARCH_ORDER
return next(
(config_file for config_file in search_paths if config_file.exists()),
(cfg_file for cfg_file in search_paths if cfg_file.exists() and "bumpversion]" in cfg_file.read_text()),
None,
)

Expand Down
4 changes: 2 additions & 2 deletions tests/fixtures/basic_cfg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ tag = true
current_version = "1.0.0"
parse = "(?P<major>\\d+)\\.(?P<minor>\\d+)\\.(?P<patch>\\d+)(\\-(?P<release>[a-z]+))?"
serialize = [
"{major}.{minor}.{patch}-{release}",
"{major}.{minor}.{patch}"
"{major}.{minor}.{patch}-{release}",
"{major}.{minor}.{patch}"
]
[[tool.bumpversion.files]]
filename = "setup.py"
Expand Down
25 changes: 19 additions & 6 deletions tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,28 @@ def test_file_keyword_with_suffix_is_accepted(tmp_path: Path, cfg_file: str, cfg


def test_multiple_config_files(tmp_path: Path):
"""If there are multiple config files, the first one with content wins."""
setup_cfg = tmp_path / "setup.cfg"
setup_cfg.write_text("[bumpversion]\n" "current_version: 0.10.2\n" "tag: true\n")
setup_cfg.write_text("[metadata]\nname: just-a-name\n")
bumpversion_cfg = tmp_path / ".bumpversion.cfg"
bumpversion_cfg.write_text("[bumpversion]\n" "current_version: 0.10.2\n" "tag: false\n")

cfg_file = config.find_config_file()
cfg = config.get_configuration(cfg_file)
bumpversion_cfg.write_text("\n")
pyproject_toml = tmp_path / "pyproject.toml"
pyproject_toml.write_text(
"[tool.bumpversion]\n"
'current_version = "0.10.5"\n'
'parse = "(?P<major>\\\\d+)\\\\.(?P<minor>\\\\d+)\\\\.(?P<patch>\\\\d+)(\\\\-(?P<release>[a-z]+))?"\n'
"serialize = [\n"
' "{major}.{minor}.{patch}-{release}",\n'
' "{major}.{minor}.{patch}"\n'
"]\n"
)
with inside_dir(tmp_path):
cfg_file = config.find_config_file()
cfg = config.get_configuration(cfg_file)

assert cfg.tag is True
assert cfg.current_version == "0.10.5"
assert cfg.parse == "(?P<major>\\d+)\\.(?P<minor>\\d+)\\.(?P<patch>\\d+)(\\-(?P<release>[a-z]+))?"
assert cfg.serialize == ["{major}.{minor}.{patch}-{release}", "{major}.{minor}.{patch}"]


def test_utf8_message_from_config_file(tmp_path: Path, cfg_file):
Expand Down

0 comments on commit fbf85c2

Please sign in to comment.