(cmd: code_writer_cmd, file: Path)
| 35 | |
| 36 | |
| 37 | def run_file(cmd: code_writer_cmd, file: Path): |
| 38 | content = file.read_text("utf-8") |
| 39 | count = 0 |
| 40 | |
| 41 | def repl_fn(match): |
| 42 | nonlocal count |
| 43 | count += 1 |
| 44 | return code |
| 45 | |
| 46 | content = section_re.sub(repl_fn, content) |
| 47 | if count == 0: |
| 48 | if content: |
| 49 | raise ValueError( |
| 50 | "Expected to find comment '# START GENERATED CYTHON IMPORT' " |
| 51 | f"in cython file {file}, but none found and the file is not " |
| 52 | "empty" |
| 53 | ) |
| 54 | content = code |
| 55 | if count > 1: |
| 56 | raise ValueError( |
| 57 | "Expected to find a single comment '# START GENERATED CYTHON " |
| 58 | f"IMPORT' in cython file {file}, but {count} found" |
| 59 | ) |
| 60 | cmd.write_output_file_from_text(content, file) |
| 61 | |
| 62 | |
| 63 | def run(cmd: code_writer_cmd): |
no test coverage detected