#34140 closed Cleanup/optimization (fixed)
Format python code blocks in documentation files
Reported by: | Paolo Melchiorre | Owned by: | Joseph V Zammit |
---|---|---|---|
Component: | Documentation | Version: | dev |
Severity: | Normal | Keywords: | format, black, snippet, example |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Now that we use Black for formatting the Django code, I think it would help a lot to format the Python code blocks present in the documentation with Black as well.
This would help those learning Django to find consistency between the code format that is present in the documentation and that present in the GIT repository.
It would also help the volunteers contributing to the documentation to have a clear guideline on the format of the sample Python code and an automatic formatter that relieves them of the worry of making mistakes.
I only know the Adam's blacken-docs to achieve the goal but if I know others I invite them to propose them.
Change History (20)
comment:1 by , 2 years ago
comment:2 by , 2 years ago
Hi Paolo, what does this involve? I see these steps:
- Install blacken-docs on my local and run it against current docs.
- Manually inspect the result. If things look good move to step 3.
- Add blacken-docs to the docs pre-commit configuration, as suggested here.
- Add blacken-docs to the current docs CI steps. (I might have questions on this.)
Does this make sense? Am I missing something?
comment:3 by , 2 years ago
Hi Joseph, yes I think these are the steps to do, and if others, as I hope, would agree, we can merge it.
Feel free to open a PR and then add the URL here.
comment:4 by , 2 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:5 by , 2 years ago
Hi Paolo, and whoever can guide me on this. I opened a PR with some initial work I put into this. Why "initial"? I feel there are some questions that need to be answered. All in the PR here:
https://github.com/django/django/pull/16261
Thanks!
comment:7 by , 2 years ago
Triage Stage: | Unreviewed → Accepted |
---|
I think we should probably do this. +1
This sounds like a really good idea!
We have added the mentioned pre-commit hook "blacken-docs" Read the Docs codebase. It has worked really well -- aside from "cosmetic" changes, it also fixed a couple of wrong indentations.
Here is the result: https://github.com/readthedocs/readthedocs.org/pull/9672
Perhaps blacken-docs lacks a good option to switch off black'ening for a certain code segment. But so far, we haven't had that issue. It's worth running it on the entire documentation project to check that there isn't any segments that are intentionally non-conformative with black.