]> 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:

Add special config verbose log case when black is using user-level config (#2861)
[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_example,) = [
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         if tag in version_example and tag != latest_tag:
31             print(
32                 "Please set the version in the ``black --version`` "
33                 "example from ``the_basics.md`` to be the latest one.\n"
34                 f"Expected {latest_tag}, got {tag}.\n"
35             )
36             sys.exit(1)
37
38
39 if __name__ == "__main__":
40     with open("CHANGES.md", encoding="utf-8") as fd:
41         changes = fd.read()
42     with open(
43         os.path.join("docs", "usage_and_configuration", "the_basics.md"),
44         encoding="utf-8",
45     ) as fd:
46         the_basics = fd.read()
47     main(changes, the_basics)