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

Joel E. Denny via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 12 13:54:20 PDT 2023


https://github.com/jdenny-ornl created https://github.com/llvm/llvm-project/pull/66141:

Describe the darker utility.  Make it clear that black/darker's default rules should be used.

See ongoing discussion at
<https://discourse.llvm.org/t/rfc-document-and-standardize-python-code-style/68257>.

>From 427133bfaac38de94f815de9d71f281c6e03ff61 Mon Sep 17 00:00:00 2001
From: "Joel E. Denny" <jdenny.ornl at gmail.com>
Date: Tue, 12 Sep 2023 16:49:54 -0400
Subject: [PATCH] [docs] Add more details about Python formatting

Describe the darker utility.  Make it clear that black/darker's
default rules should be used.

See ongoing discussion at
<https://discourse.llvm.org/t/rfc-document-and-standardize-python-code-style/68257>.
---
 llvm/docs/CodingStandards.rst | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/llvm/docs/CodingStandards.rst b/llvm/docs/CodingStandards.rst
index 9d87142b0984fda..55aa64688967a8b 100644
--- a/llvm/docs/CodingStandards.rst
+++ b/llvm/docs/CodingStandards.rst
@@ -115,10 +115,19 @@ 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/>`_.
 
-For consistency and to limit churn, code should be automatically formatted with the
-`black <https://github.com/psf/black>`_ utility. Black allows changing the formatting
-rules based on major version. In order to avoid unnecessary churn in the formatting rules
-we currently use black version 23.x in LLVM.
+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.
 
 Mechanical Source Issues
 ========================



More information about the llvm-commits mailing list