[llvm] [docs] Add more details about Python formatting (PR #66141)

Joel E. Denny via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 13 08:33:50 PDT 2023


================
@@ -113,21 +113,32 @@ section. Python code in the LLVM repository should only use language features
 available in this version of Python.
 
 The Python code within the LLVM repository should adhere to the formatting guidelines
-outlined in `PEP-8 <https://peps.python.org/pep-0008/>`_.
+outlined in `PEP 8 <https://peps.python.org/pep-0008/>`_.
 
 For consistency and to limit churn, code should be automatically formatted with
-the `black <https://github.com/psf/black>`_ utility with its default rules
-(e.g., avoid specifying ``--line-length`` even though it does not default to
-80). The default rules can change between major versions of black. In order to
-avoid unnecessary churn in the formatting rules we currently use black version
-23.x in LLVM.
-
-When contributing a patch unrelated to formatting, use the `darker
-<https://pypi.org/project/darker/>`_ utility with its default rules to format
-any changed Python code. Doing so should ensure the patch will pass the Python
-format checks in LLVM's pre-commit CI, which also uses darker. When
-contributing a patch specifically for reformatting Python files, use black,
-which currently only supports formatting entire files.
+the `black <https://github.com/psf/black>`_ utility, which is PEP 8 compliant.
+Use its default rules. For example, avoid specifying ``--line-length`` even
+though it does not default to 80. The default rules can change between major
+versions of black. In order to avoid unnecessary churn in the formatting rules
+we currently use black version 23.x in LLVM.
+
+When contributing a patch unrelated to formatting, you should format only the
+Python code that the patch modifies. For this purpose, use the `darker
+<https://pypi.org/project/darker/>`_ utility to call black with its default
+rules. Doing so should ensure the patch will pass the Python format checks in
+LLVM's pre-commit CI, which also uses darker. When contributing a patch
+specifically for reformatting Python files, use black, which currently only
+supports formatting entire files.
+
+Here are some quick examples, but see the black and darker documentation for
+details:
+
+.. code-block:: bash
+
+    $ pip install black darker
----------------
jdenny-ornl wrote:

To keep the example simple, does the following seem reasonable?

```
$ pip install black=='23.*' darker
```

https://github.com/llvm/llvm-project/pull/66141


More information about the llvm-commits mailing list