]> git.madduck.net Git - etc/vim.git/blob - scripts/check_pre_commit_rev_in_example.py

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Mitigate deprecation of aiohttp's `@middleware` decorator (#3259)
[etc/vim.git] / scripts / check_pre_commit_rev_in_example.py
1 """
2 Check that the rev value in the example pre-commit configuration matches
3 the latest version of Black. This saves us from forgetting to update that
4 during the release process.
5
6 Why can't we just use `rev: stable` and call it a day? Well pre-commit
7 won't auto update the hook as you may expect (and for good reasons, some
8 technical and some pragmatic). Encouraging bad practice is also just
9 not ideal. xref: https://github.com/psf/black/issues/420
10 """
11
12 import os
13 import sys
14
15 import commonmark
16 import yaml
17 from bs4 import BeautifulSoup
18
19
20 def main(changes: str, source_version_control: str) -> None:
21     changes_html = commonmark.commonmark(changes)
22     changes_soup = BeautifulSoup(changes_html, "html.parser")
23     headers = changes_soup.find_all("h2")
24     latest_tag, *_ = [
25         header.string for header in headers if header.string != "Unreleased"
26     ]
27
28     source_version_control_html = commonmark.commonmark(source_version_control)
29     source_version_control_soup = BeautifulSoup(
30         source_version_control_html, "html.parser"
31     )
32     pre_commit_repos = yaml.safe_load(
33         source_version_control_soup.find(class_="language-yaml").string
34     )["repos"]
35
36     for repo in pre_commit_repos:
37         pre_commit_rev = repo["rev"]
38         if not pre_commit_rev == latest_tag:
39             print(
40                 "Please set the rev in ``source_version_control.md`` to be the latest "
41                 f"one.\nExpected {latest_tag}, got {pre_commit_rev}.\n"
42             )
43             sys.exit(1)
44
45
46 if __name__ == "__main__":
47     with open("CHANGES.md", encoding="utf-8") as fd:
48         changes = fd.read()
49     with open(
50         os.path.join("docs", "integrations", "source_version_control.md"),
51         encoding="utf-8",
52     ) as fd:
53         source_version_control = fd.read()
54     main(changes, source_version_control)