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>
This commit is contained in:
parent
e7a92c0e69
commit
e7f6b9f4f7
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user