detect `rev:` lines or reformat the file
(
path: str,
rev_infos: list[RevInfo | None],
retry: bool = False,
)
| 117 | |
| 118 | |
| 119 | def _original_lines( |
| 120 | path: str, |
| 121 | rev_infos: list[RevInfo | None], |
| 122 | retry: bool = False, |
| 123 | ) -> tuple[list[str], list[int]]: |
| 124 | """detect `rev:` lines or reformat the file""" |
| 125 | with open(path, newline='') as f: |
| 126 | original = f.read() |
| 127 | |
| 128 | lines = original.splitlines(True) |
| 129 | idxs = [i for i, line in enumerate(lines) if REV_LINE_RE.match(line)] |
| 130 | if len(idxs) == len(rev_infos): |
| 131 | return lines, idxs |
| 132 | elif retry: |
| 133 | raise AssertionError('could not find rev lines') |
| 134 | else: |
| 135 | with open(path, 'w') as f: |
| 136 | f.write(yaml_dump(yaml_load(original))) |
| 137 | return _original_lines(path, rev_infos, retry=True) |
| 138 | |
| 139 | |
| 140 | def _write_new_config(path: str, rev_infos: list[RevInfo | None]) -> None: |
no test coverage detected