Skip to content

Conversation

felixxm
Copy link
Member

@felixxm felixxm commented Feb 28, 2023

  • Added black rule to make.bat
  • Added pre-commit hook
  • Update contributing guides

@felixxm felixxm force-pushed the blacken-docs-end branch 3 times, most recently from bd88c7d to 6df4f41 Compare February 28, 2023 19:30
@smithdc1
Copy link
Member

Will the make.bat file be updated as well?

Let me know if you need help with that?

@felixxm felixxm force-pushed the blacken-docs-end branch 5 times, most recently from 7fb4a24 to cfefcc6 Compare February 28, 2023 19:52
@felixxm
Copy link
Member Author

felixxm commented Feb 28, 2023

Will the make.bat file be updated as well?

Let me know if you need help with that?

Yes, it's on my TO-DO list, and yes, I need help 🚑 😉

@felixxm felixxm changed the title Refs #34140 -- Added GitHub action, tox configuration, and makefile rule to run blacken-docs linter. Fixed #34140 -- Reformatted code blocks in docs with blacken-docs. Feb 28, 2023
@smithdc1
Copy link
Member

smithdc1 commented Mar 1, 2023

This is what I've come up with so far. I'm assuming the error code doesn't matter (mkdir will set %ERRORLEVEL% if the folder already exists).

diff --git a/docs/make.bat b/docs/make.bat
index 4743692ca3..1de9089b35 100644
--- a/docs/make.bat
+++ b/docs/make.bat
@@ -35,6 +35,7 @@ if "%1" == "help" (
        echo.  linkcheck  to check all external links for integrity
        echo.  doctest    to run all doctests embedded in the documentation if enabled
        echo.  spelling   to check for typos in documentation
+       echo.  black      to apply the black formatting to code blocks in documentation 
        goto end
 )

@@ -196,4 +197,11 @@ spelling/output.txt.
        goto end
 )

+if "%1" == "black" (
+       mkdir %BUILDDIR%
+       for /f "usebackq tokens=*" %%i in (`dir *.txt /s /b ^| findstr /v /c:"_build" /c:"_theme"`) do (
+               blacken-docs --rst-literal-block %%i
+       )
+       echo "Code blocks reformatted"
+)
+

Running blacken-docs it creates one diff to this PR:

diff --git a/docs/ref/contrib/postgres/search.txt b/docs/ref/contrib/postgres/search.txt
index 699f81bd11..4f481e56a2 100644
--- a/docs/ref/contrib/postgres/search.txt
+++ b/docs/ref/contrib/postgres/search.txt
@@ -343,9 +343,7 @@ Usage example:
     >>> Author.objects.create(name="Katy Stevens")
     >>> Author.objects.create(name="Stephen Keats")
     >>> test = "Katie Stephens"
-    >>> Author.objects.annotate(
-    ...     similarity=TrigramSimilarity("name", test),
-    ... ).filter(
+    >>> Author.objects.annotate(similarity=TrigramSimilarity("name", test),).filter(
     ...     similarity__gt=0.3
     ... ).order_by("-similarity")
     [<Author: Katy Stevens>, <Author: Stephen Keats>]
@@ -366,9 +364,7 @@ Usage example:
     >>> Author.objects.create(name="Katy Stevens")
     >>> Author.objects.create(name="Stephen Keats")
     >>> test = "Kat"
-    >>> Author.objects.annotate(
-    ...     similarity=TrigramWordSimilarity(test, "name"),
-    ... ).filter(
+    >>> Author.objects.annotate(similarity=TrigramWordSimilarity(test, "name"),).filter(
     ...     similarity__gt=0.3
     ... ).order_by("-similarity")
     [<Author: Katy Stevens>]
@@ -401,9 +397,7 @@ Usage example:
     >>> Author.objects.create(name="Katy Stevens")
     >>> Author.objects.create(name="Stephen Keats")
     >>> test = "Katie Stephens"
-    >>> Author.objects.annotate(
-    ...     distance=TrigramDistance("name", test),
-    ... ).filter(
+    >>> Author.objects.annotate(distance=TrigramDistance("name", test),).filter(
     ...     distance__lte=0.7
     ... ).order_by("distance")
     [<Author: Katy Stevens>, <Author: Stephen Keats>]
@@ -424,9 +418,7 @@ Usage example:
     >>> Author.objects.create(name="Katy Stevens")
     >>> Author.objects.create(name="Stephen Keats")
     >>> test = "Kat"
-    >>> Author.objects.annotate(
-    ...     distance=TrigramWordDistance(test, "name"),
-    ... ).filter(
+    >>> Author.objects.annotate(distance=TrigramWordDistance(test, "name"),).filter(
     ...     distance__lte=0.7
     ... ).order_by("distance")
     [<Author: Katy Stevens>]

@felixxm felixxm force-pushed the blacken-docs-end branch from 7d081d2 to d2cd91b Compare March 1, 2023 09:37
@felixxm
Copy link
Member Author

felixxm commented Mar 1, 2023

This is what I've come up with so far. I'm assuming the error code doesn't matter (mkdir will set %ERRORLEVEL% if the folder already exists).

diff --git a/docs/make.bat b/docs/make.bat
index 4743692ca3..1de9089b35 100644
--- a/docs/make.bat
+++ b/docs/make.bat
@@ -35,6 +35,7 @@ if "%1" == "help" (
        echo.  linkcheck  to check all external links for integrity
        echo.  doctest    to run all doctests embedded in the documentation if enabled
        echo.  spelling   to check for typos in documentation
+       echo.  black      to apply the black formatting to code blocks in documentation 
        goto end
 )

@@ -196,4 +197,11 @@ spelling/output.txt.
        goto end
 )

+if "%1" == "black" (
+       mkdir %BUILDDIR%
+       for /f "usebackq tokens=*" %%i in (`dir *.txt /s /b ^| findstr /v /c:"_build" /c:"_theme"`) do (
+               blacken-docs --rst-literal-block %%i
+       )
+       echo "Code blocks reformatted"
+)
+

Thanks, added! Does it save the return code of blacken-docs to the black/output.txt?

Running blacken-docs it creates one diff to this PR:

It seems that you don't use the newest black 🤔 .

@smithdc1
Copy link
Member

smithdc1 commented Mar 1, 2023

Does it save the return code of blacken-docs to the black/output.txt?

No. This calls blacken-docs for every file. So only saves it for the final file. I'm not sure how to pass in a list of files on windows.

It seems that you don't use the newest black 🤔 .

Ahh OK. Quite possibly.

@felixxm
Copy link
Member Author

felixxm commented Mar 1, 2023

Does it save the return code of blacken-docs to the black/output.txt?

No. This calls blacken-docs for every file. So only saves it for the final file. I'm not sure how to pass in a list of files on windows.

I think it's fine, we don't use it in CI so we don't need to capture the return code. I removed mkdir as we don't need it when black/output.txt is not created.

@felixxm felixxm force-pushed the blacken-docs-end branch 2 times, most recently from d73fa08 to 5b420b4 Compare March 1, 2023 09:57
@carltongibson
Copy link
Member

Just a quick confirm that the make.bat looks good.

@felixxm felixxm marked this pull request as ready for review March 1, 2023 10:38
@felixxm felixxm force-pushed the blacken-docs-end branch from 5b420b4 to 68c9e63 Compare March 1, 2023 10:38
@pauloxnet
Copy link
Member

I reviewed the 'makefile' commit and LGTM

Copy link
Member

@carltongibson carltongibson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I think it looks good. (No doubt they'll be tweaks...)

Thanks @felixxm and @smithdc1! 🎁

@felixxm felixxm force-pushed the blacken-docs-end branch from 68c9e63 to 724f726 Compare March 1, 2023 10:50
@felixxm
Copy link
Member Author

felixxm commented Mar 1, 2023

@carltongibson @pauloxnet Thanks 👍

felixxm and others added 3 commits March 1, 2023 13:02
…justed docs.

This adds:
- GitHub actions,
- tox configuration,
- pre-commit hook, and
- makefile rules
to run blacken-docs linter.

Co-authored-by: David Smith <[email protected]>
@felixxm felixxm force-pushed the blacken-docs-end branch from 724f726 to 14459f8 Compare March 1, 2023 12:06
@felixxm
Copy link
Member Author

felixxm commented Mar 1, 2023

I found two small issues when reviewing changes made by blacken-docs and fixed them in the 1st commit.

@felixxm felixxm merged commit 14459f8 into django:main Mar 1, 2023
@felixxm felixxm deleted the blacken-docs-end branch March 1, 2023 12:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants