Skip to content

Commit 51ea69f

Browse files
committed
Fix fallback search pattern in files
Refactor `_contains_change_pattern` method by removing unused `context` parameter. Replace version config usage with `DEFAULT_CONFIG` to provide correct fallback logic. Minor test update to align with changes.
1 parent d201dff commit 51ea69f

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

bumpversion/files.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from pathlib import Path
88
from typing import Dict, List, MutableMapping, Optional
99

10+
from bumpversion.config import DEFAULTS as DEFAULT_CONFIG
1011
from bumpversion.config.models import FileChange
1112
from bumpversion.exceptions import VersionNotFoundError
1213
from bumpversion.ui import get_indented_logger
@@ -129,7 +130,7 @@ def write_file_contents(self, contents: str) -> None:
129130
f.write(contents)
130131

131132
def _contains_change_pattern(
132-
self, search_expression: re.Pattern, raw_search_expression: str, version: Version, context: MutableMapping
133+
self, search_expression: re.Pattern, raw_search_expression: str, version: Version
133134
) -> bool:
134135
"""
135136
Does the file contain the change pattern?
@@ -138,7 +139,6 @@ def _contains_change_pattern(
138139
search_expression: The compiled search expression
139140
raw_search_expression: The raw search expression
140141
version: The version to check, in case it's not the same as the original
141-
context: The context to use
142142
143143
Raises:
144144
VersionNotFoundError: if the version number isn't present in this file.
@@ -155,7 +155,7 @@ def _contains_change_pattern(
155155
# match instead. This is probably the case if environment variables are used.
156156

157157
# check whether `search` isn't customized
158-
search_pattern_is_default = self.file_change.search == self.version_config.search
158+
search_pattern_is_default = self.file_change.search == DEFAULT_CONFIG["search"]
159159

160160
if search_pattern_is_default and contains_pattern(re.compile(re.escape(version.original)), file_contents):
161161
# The original version is present, and we're not looking for something
@@ -195,7 +195,7 @@ def make_file_change(
195195
search_for, raw_search_pattern = self.file_change.get_search_pattern(context)
196196
replace_with = self.version_config.replace.format(**context)
197197

198-
if not self._contains_change_pattern(search_for, raw_search_pattern, current_version, context):
198+
if not self._contains_change_pattern(search_for, raw_search_pattern, current_version):
199199
logger.dedent()
200200
return
201201

tests/test_files.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def test_non_matching_search_does_not_modify_file(self, tmp_path: Path):
6969
"""
7070
# Unreleased
7171
72-
* bullet point A
72+
* bullet point A prep for 1.0.3
7373
7474
# Release v'older' (2019-09-17)
7575

0 commit comments

Comments
 (0)