summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Lechner <david@pybricks.com>2022-03-23 14:18:23 -0500
committerDamien George <damien@micropython.org>2022-03-25 12:13:00 +1100
commite7f6b9f4f76142ecd554106984a8520a0ada9d03 (patch)
treeb61507f4f93eac6e7651a5d988f17fca9f7f67da
parente7a92c0e699a7c95ea322e3105f587ae1a71bedf (diff)
tools/gen-cpydiff: Skip Black fmt comments.
Since cpydiff is code used as documentation, there are cases where we may want to use Black's `fmt: on/off/skip` comments to avoid automatic formatting. However, we don't want these comments to be distracting in the generated documentation. This rewrites the code to omit these comments when generating the docs. Signed-off-by: David Lechner <david@pybricks.com>
-rw-r--r--tools/gen-cpydiff.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/tools/gen-cpydiff.py b/tools/gen-cpydiff.py
index 1d458d3dc..d4c8a5736 100644
--- a/tools/gen-cpydiff.py
+++ b/tools/gen-cpydiff.py
@@ -85,6 +85,16 @@ def readfiles():
class_, desc, cause, workaround, code = [
x.rstrip() for x in list(filter(None, re.split(SPLIT, text)))
]
+
+ # remove black `fmt: on/off/skip` comments
+ code = "".join(
+ # skip comments are inline, so we replace just the comment
+ re.sub(r"\s*# fmt: skip", "", x)
+ for x in code.splitlines(keepends=True)
+ # on/off comments are on their own line, so we omit the entire line
+ if not re.match(r"\s*# fmt: (on|off)\s*", x)
+ )
+
output = Output(test, class_, desc, cause, workaround, code, "", "", "")
files.append(output)
except IndexError: