Repository: psf/black

Issue:
Follow-up items for the Jupyter PR
PR #2357 was recently merged :tada: For the sake of getting it merged somewhat quickly and to not tire everyone, we left a few TO-DO items for later. This issue attempts to list 'em so we don't forget :)

- Add documentation about the newly exported `black-jupyter` pre-commit hook 
- Look into whether we should add the Jupyter deps to `Pipfile` or just document the quirk (tox is unaffected)

I probably already forget a few tho, so feel free to edit / comment with more.


Discussion:

Resolving patch:
diff --git a/scripts/__init__.py b/scripts/__init__.py
new file mode 100644
diff --git a/scripts/check_pre_commit_rev_in_example.py b/scripts/check_pre_commit_rev_in_example.py
new file mode 100644
--- /dev/null
+++ b/scripts/check_pre_commit_rev_in_example.py
@@ -0,0 +1,54 @@
+"""
+Check that the rev value in the example pre-commit configuration matches
+the latest version of Black. This saves us from forgetting to update that
+during the release process.
+
+Why can't we just use `rev: stable` and call it a day? Well pre-commit
+won't auto update the hook as you may expect (and for good reasons, some
+technical and some pragmatic). Encouraging bad practice is also just
+not ideal. xref: https://github.com/psf/black/issues/420
+"""
+
+import os
+import sys
+
+import commonmark
+import yaml
+from bs4 import BeautifulSoup
+
+
+def main(changes: str, source_version_control: str) -> None:
+    changes_html = commonmark.commonmark(changes)
+    changes_soup = BeautifulSoup(changes_html, "html.parser")
+    headers = changes_soup.find_all("h2")
+    latest_tag, *_ = [
+        header.string for header in headers if header.string != "Unreleased"
+    ]
+
+    source_version_control_html = commonmark.commonmark(source_version_control)
+    source_version_control_soup = BeautifulSoup(
+        source_version_control_html, "html.parser"
+    )
+    pre_commit_repos = yaml.safe_load(
+        source_version_control_soup.find(class_="language-yaml").string
+    )["repos"]
+
+    for repo in pre_commit_repos:
+        pre_commit_rev = repo["rev"]
+        if not pre_commit_rev == latest_tag:
+            print(
+                "Please set the rev in ``source_version_control.md`` to be the latest "
+                f"one.\nExpected {latest_tag}, got {pre_commit_rev}.\n"
+            )
+            sys.exit(1)
+
+
+if __name__ == "__main__":
+    with open("CHANGES.md", encoding="utf-8") as fd:
+        changes = fd.read()
+    with open(
+        os.path.join("docs", "integrations", "source_version_control.md"),
+        encoding="utf-8",
+    ) as fd:
+        source_version_control = fd.read()
+    main(changes, source_version_control)
diff --git a/src/black/__init__.py b/src/black/__init__.py
--- a/src/black/__init__.py
+++ b/src/black/__init__.py
@@ -977,7 +977,7 @@ def format_ipynb_string(src_contents: str, *, fast: bool, mode: Mode) -> FileCon
     """Format Jupyter notebook.
 
     Operate cell-by-cell, only on code cells, only for Python notebooks.
-    If the ``.ipynb`` originally had a trailing newline, it'll be preseved.
+    If the ``.ipynb`` originally had a trailing newline, it'll be preserved.
     """
     trailing_newline = src_contents[-1] == "\n"
     modified = False


Test patch: