MCPcopy Index your code
hub / github.com/commitizen-tools/commitizen / update_version_in_files

Function update_version_in_files

commitizen/bump.py:65–112  ·  view source on GitHub ↗

Change old version to the new one in every file given. Note that this version is not the tag formatted one. So for example, your tag could look like `v1.0.0` while your version in the package like `1.0.0`. Returns the list of updated files.

(
    current_version: str,
    new_version: str,
    version_files: Iterable[str],
    *,
    check_consistency: bool,
    encoding: str,
)

Source from the content-addressed store, hash-verified

63
64
65def update_version_in_files(
66 current_version: str,
67 new_version: str,
68 version_files: Iterable[str],
69 *,
70 check_consistency: bool,
71 encoding: str,
72) -> list[str]:
73 """Change old version to the new one in every file given.
74
75 Note that this version is not the tag formatted one.
76 So for example, your tag could look like `v1.0.0` while your version in
77 the package like `1.0.0`.
78
79 Returns the list of updated files.
80 """
81 updated_files = []
82
83 for path, pattern in _resolve_files_and_regexes(version_files, current_version):
84 current_version_found = False
85 bumped_lines = []
86
87 with open(path, encoding=encoding) as version_file:
88 for line in version_file:
89 bumped_line = (
90 line.replace(current_version, new_version)
91 if pattern.search(line)
92 else line
93 )
94
95 current_version_found = current_version_found or bumped_line != line
96 bumped_lines.append(bumped_line)
97
98 if check_consistency and not current_version_found:
99 raise CurrentVersionNotFoundError(
100 f"Current version {current_version} is not found in {path}.\n"
101 "The version defined in commitizen configuration and the ones in "
102 "version_files are possibly inconsistent."
103 )
104
105 bumped_version_file_content = "".join(bumped_lines)
106
107 # Write the file out again
108 with smart_open(path, "w", encoding=encoding) as file:
109 file.write(bumped_version_file_content)
110 updated_files.append(path)
111
112 return updated_files
113
114
115def _resolve_files_and_regexes(

Callers

nothing calls this directly

Calls 3

smart_openFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…