|
| 1 | +import textwrap |
| 2 | + |
| 3 | +import re |
| 4 | +from pathlib import Path |
| 5 | + |
| 6 | + |
| 7 | +def get_version(path: Path) -> str: |
| 8 | + """Get version from _version.py""" |
| 9 | + versions = re.findall(r"__version__\s*=\s*['\"](.*?)['\"]", path.read_text(encoding="utf8")) |
| 10 | + if len(versions) != 1: |
| 11 | + raise ValueError(f"Expected one version, but found {versions}") |
| 12 | + return versions[0] |
| 13 | + |
| 14 | + |
| 15 | +def get_in_progress_header(path: Path) -> str: |
| 16 | + """Get 'In progress' header from CHANGELOG.md""" |
| 17 | + in_progress_headers = re.findall( |
| 18 | + r"^## In progress: .*$", path.read_text(encoding="utf8"), re.MULTILINE | re.IGNORECASE |
| 19 | + ) |
| 20 | + if len(in_progress_headers) != 1: |
| 21 | + raise ValueError(f"Expected single 'In progress' header, but found {in_progress_headers}") |
| 22 | + return in_progress_headers[0] |
| 23 | + |
| 24 | +def main(): |
| 25 | + root = Path.cwd() |
| 26 | + |
| 27 | + version_path = root / "openeogeotrellis" / "_version.py" |
| 28 | + expected_version = get_version(version_path) |
| 29 | + expected_version = expected_version.partition("a")[0] |
| 30 | + expected_in_progress_header = f"## In progress: {expected_version}" |
| 31 | + |
| 32 | + changelog_path = root / "CHANGELOG.md" |
| 33 | + in_progress_header = get_in_progress_header(path=changelog_path) |
| 34 | + |
| 35 | + if in_progress_header.lower() != expected_in_progress_header.lower(): |
| 36 | + print( |
| 37 | + textwrap.dedent( |
| 38 | + f"""\ |
| 39 | + Version inconsistency in CHANGELOG.md. |
| 40 | + Expected: |
| 41 | + {expected_in_progress_header} |
| 42 | + but found: |
| 43 | + {in_progress_header} |
| 44 | + """ |
| 45 | + ) |
| 46 | + ) |
| 47 | + return 1 |
| 48 | + return 0 |
| 49 | + |
| 50 | + |
| 51 | +if __name__ == "__main__": |
| 52 | + raise SystemExit(main()) |
0 commit comments