|
| 1 | +""" |
| 2 | +Check changelog entries have the correct filename structure. |
| 3 | +""" |
| 4 | + |
| 5 | +import sys |
| 6 | +from pathlib import Path |
| 7 | + |
| 8 | +VALID_CHANGELOG_TYPES = ["feature", "bugfix", "doc", "removal", "misc"] |
| 9 | +CHANGELOG_DIRECTORY = (Path(__file__).parent.parent / "changes").resolve() |
| 10 | + |
| 11 | + |
| 12 | +def is_int(s: str) -> bool: |
| 13 | + try: |
| 14 | + int(s) |
| 15 | + except ValueError: |
| 16 | + return False |
| 17 | + else: |
| 18 | + return True |
| 19 | + |
| 20 | + |
| 21 | +if __name__ == "__main__": |
| 22 | + print(f"Looking for changelog entries in {CHANGELOG_DIRECTORY}") |
| 23 | + entries = CHANGELOG_DIRECTORY.glob("*") |
| 24 | + entries = [e for e in entries if e.name not in [".gitignore", "README.md"]] |
| 25 | + print(f"Found {len(entries)} entries") |
| 26 | + print() |
| 27 | + |
| 28 | + bad_suffix = [e for e in entries if e.suffix != ".rst"] |
| 29 | + bad_issue_no = [e for e in entries if not is_int(e.name.split(".")[0])] |
| 30 | + bad_type = [e for e in entries if e.name.split(".")[1] not in VALID_CHANGELOG_TYPES] |
| 31 | + |
| 32 | + if len(bad_suffix) or len(bad_issue_no) or len(bad_type): |
| 33 | + if len(bad_suffix): |
| 34 | + print("Changelog entries without .rst suffix") |
| 35 | + print("-------------------------------------") |
| 36 | + print("\n".join([p.name for p in bad_suffix])) |
| 37 | + print() |
| 38 | + if len(bad_issue_no): |
| 39 | + print("Changelog entries without integer issue number") |
| 40 | + print("----------------------------------------------") |
| 41 | + print("\n".join([p.name for p in bad_issue_no])) |
| 42 | + print() |
| 43 | + if len(bad_type): |
| 44 | + print("Changelog entries without valid type") |
| 45 | + print("------------------------------------") |
| 46 | + print("\n".join([p.name for p in bad_type])) |
| 47 | + print(f"Valid types are: {VALID_CHANGELOG_TYPES}") |
| 48 | + print() |
| 49 | + sys.exit(1) |
| 50 | + |
| 51 | + sys.exit(0) |
0 commit comments