(lines, path)
| 124 | |
| 125 | |
| 126 | def _ensure_license(lines, path): |
| 127 | # 1. Keep/replace existing |
| 128 | insert = get_license_idx(path, lines) |
| 129 | |
| 130 | # 2. After author line(s) |
| 131 | if insert is None: |
| 132 | author_idx = get_author_idx(path, lines) |
| 133 | assert author_idx is not None, f"{author_idx=} for {path=}" |
| 134 | insert = author_idx + 1 |
| 135 | if path_multi_author: |
| 136 | # Figure out where to insert the license: |
| 137 | for insert, line in enumerate(lines[author_idx + 1 :], insert): |
| 138 | if not line.startswith("# "): |
| 139 | break |
| 140 | if lines[insert].startswith(LICENSE_STARTS): |
| 141 | lines[insert] = LICENSE_LINE |
| 142 | else: |
| 143 | lines.insert(insert, LICENSE_LINE) |
| 144 | assert lines.count(LICENSE_LINE) == 1, f"{lines.count(LICENSE_LINE)=} for {path=}" |
| 145 | |
| 146 | |
| 147 | def _ensure_copyright(lines, path): |
no test coverage detected