]> git.madduck.net Git - etc/vim.git/blob - scripts/check_version_in_basics_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:

respect magic trailing commas in return types (#3916)
[etc/vim.git] / scripts / check_version_in_basics_example.py
1 """
2 Check that the rev value in the example from ``the_basics.md`` matches
3 the latest version of Black. This saves us from forgetting to update that
4 during the release process.
5 """
6
7 import os
8 import sys
9
10 import commonmark
11 from bs4 import BeautifulSoup
12
13
14 def main(changes: str, the_basics: str) -> None:
15     changes_html = commonmark.commonmark(changes)
16     changes_soup = BeautifulSoup(changes_html, "html.parser")
17     headers = changes_soup.find_all("h2")
18     tags = [header.string for header in headers if header.string != "Unreleased"]
19     latest_tag = tags[0]
20
21     the_basics_html = commonmark.commonmark(the_basics)
22     the_basics_soup = BeautifulSoup(the_basics_html, "html.parser")
23     version_examples = [
24         code_block.string
25         for code_block in the_basics_soup.find_all(class_="language-console")
26         if "$ black --version" in code_block.string
27     ]
28
29     for tag in tags:
30         for version_example in version_examples:
31             if tag in version_example and tag != latest_tag:
32                 print(
33                     "Please set the version in the ``black --version`` "
34                     "examples from ``the_basics.md`` to be the latest one.\n"
35                     f"Expected {latest_tag}, got {tag}.\n"
36                 )
37                 sys.exit(1)
38
39
40 if __name__ == "__main__":
41     with open("CHANGES.md", encoding="utf-8") as fd:
42         changes = fd.read()
43     with open(
44         os.path.join("docs", "usage_and_configuration", "the_basics.md"),
45         encoding="utf-8",
46     ) as fd:
47         the_basics = fd.read()
48     main(changes, the_basics)