MCPcopy Index your code
hub / github.com/pre-commit/pre-commit / _write_new_config

Function _write_new_config

pre_commit/commands/autoupdate.py:140–159  ·  view source on GitHub ↗
(path: str, rev_infos: list[RevInfo | None])

Source from the content-addressed store, hash-verified

138
139
140def _write_new_config(path: str, rev_infos: list[RevInfo | None]) -> None:
141 lines, idxs = _original_lines(path, rev_infos)
142
143 for idx, rev_info in zip(idxs, rev_infos):
144 if rev_info is None:
145 continue
146 match = REV_LINE_RE.match(lines[idx])
147 assert match is not None
148 new_rev_s = yaml_dump({'rev': rev_info.rev}, default_style=match[3])
149 new_rev = new_rev_s.split(':', 1)[1].strip()
150 if rev_info.frozen is not None:
151 comment = f' # frozen: {rev_info.frozen}'
152 elif match[5].strip().startswith('# frozen:'):
153 comment = ''
154 else:
155 comment = match[5]
156 lines[idx] = f'{match[1]}rev:{match[2]}{new_rev}{comment}{match[6]}'
157
158 with open(path, 'w', newline='') as f:
159 f.write(''.join(lines))
160
161
162def autoupdate(

Callers 1

autoupdateFunction · 0.85

Calls 3

yaml_dumpFunction · 0.90
_original_linesFunction · 0.85
matchMethod · 0.45

Tested by

no test coverage detected