()
| 55 | |
| 56 | |
| 57 | def main() -> int: |
| 58 | missing_header: list[str] = [] |
| 59 | missing_blank_line: list[str] = [] |
| 60 | |
| 61 | for file_path in iter_source_files(): |
| 62 | expected_header = REQUIRED_HEADER_BY_SUFFIX.get(file_path.suffix.lower()) |
| 63 | if expected_header is None: |
| 64 | continue |
| 65 | |
| 66 | if not file_path.exists(): |
| 67 | continue |
| 68 | |
| 69 | try: |
| 70 | with file_path.open("r", encoding="utf-8") as file: |
| 71 | first_line = file.readline().rstrip("\r\n") |
| 72 | second_line = file.readline() |
| 73 | except OSError as exc: |
| 74 | print(f"Failed to read {file_path}: {exc}", file=sys.stderr) |
| 75 | return 1 |
| 76 | |
| 77 | if first_line != expected_header: |
| 78 | missing_header.append(str(file_path.relative_to(REPO_ROOT))) |
| 79 | continue |
| 80 | |
| 81 | # Second line should be either an EOF or a blank line |
| 82 | if second_line and second_line.strip(): |
| 83 | missing_blank_line.append(str(file_path.relative_to(REPO_ROOT))) |
| 84 | |
| 85 | if missing_header: |
| 86 | print("The following files are missing the required copyright header:") |
| 87 | for path in missing_header: |
| 88 | print(f" - {path}") |
| 89 | header_examples = "\n".join(sorted(set(REQUIRED_HEADER_BY_SUFFIX.values()))) |
| 90 | print(f"Run the appropriate script or add the header manually:\n{header_examples}") |
| 91 | |
| 92 | if missing_blank_line: |
| 93 | print("The following files are missing a blank line after the copyright header:") |
| 94 | for path in missing_blank_line: |
| 95 | print(f" - {path}") |
| 96 | print("Ensure there is an empty line separating the header from the rest of the file.") |
| 97 | |
| 98 | if missing_header or missing_blank_line: |
| 99 | return 1 |
| 100 | |
| 101 | return 0 |
| 102 | |
| 103 | |
| 104 | if __name__ == "__main__": |
no test coverage detected