Skip to content

Commit fbf85c2

Browse files
committed
Fixed configuration file detection.
Doesn't just stop when it finds one, it checks for the existence of the header.
1 parent 0aea9dc commit fbf85c2

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

bumpversion/config.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ def find_config_file(explicit_file: Union[str, Path, None] = None) -> Union[Path
201201
"""
202202
search_paths = [Path(explicit_file)] if explicit_file else CONFIG_FILE_SEARCH_ORDER
203203
return next(
204-
(config_file for config_file in search_paths if config_file.exists()),
204+
(cfg_file for cfg_file in search_paths if cfg_file.exists() and "bumpversion]" in cfg_file.read_text()),
205205
None,
206206
)
207207

tests/fixtures/basic_cfg.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ tag = true
2323
current_version = "1.0.0"
2424
parse = "(?P<major>\\d+)\\.(?P<minor>\\d+)\\.(?P<patch>\\d+)(\\-(?P<release>[a-z]+))?"
2525
serialize = [
26-
"{major}.{minor}.{patch}-{release}",
27-
"{major}.{minor}.{patch}"
26+
"{major}.{minor}.{patch}-{release}",
27+
"{major}.{minor}.{patch}"
2828
]
2929
[[tool.bumpversion.files]]
3030
filename = "setup.py"

tests/test_config.py

+19-6
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,28 @@ def test_file_keyword_with_suffix_is_accepted(tmp_path: Path, cfg_file: str, cfg
112112

113113

114114
def test_multiple_config_files(tmp_path: Path):
115+
"""If there are multiple config files, the first one with content wins."""
115116
setup_cfg = tmp_path / "setup.cfg"
116-
setup_cfg.write_text("[bumpversion]\n" "current_version: 0.10.2\n" "tag: true\n")
117+
setup_cfg.write_text("[metadata]\nname: just-a-name\n")
117118
bumpversion_cfg = tmp_path / ".bumpversion.cfg"
118-
bumpversion_cfg.write_text("[bumpversion]\n" "current_version: 0.10.2\n" "tag: false\n")
119-
120-
cfg_file = config.find_config_file()
121-
cfg = config.get_configuration(cfg_file)
119+
bumpversion_cfg.write_text("\n")
120+
pyproject_toml = tmp_path / "pyproject.toml"
121+
pyproject_toml.write_text(
122+
"[tool.bumpversion]\n"
123+
'current_version = "0.10.5"\n'
124+
'parse = "(?P<major>\\\\d+)\\\\.(?P<minor>\\\\d+)\\\\.(?P<patch>\\\\d+)(\\\\-(?P<release>[a-z]+))?"\n'
125+
"serialize = [\n"
126+
' "{major}.{minor}.{patch}-{release}",\n'
127+
' "{major}.{minor}.{patch}"\n'
128+
"]\n"
129+
)
130+
with inside_dir(tmp_path):
131+
cfg_file = config.find_config_file()
132+
cfg = config.get_configuration(cfg_file)
122133

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

125138

126139
def test_utf8_message_from_config_file(tmp_path: Path, cfg_file):

0 commit comments

Comments
 (0)