summaryrefslogtreecommitdiff
path: root/tools/indent.py
diff options
context:
space:
mode:
authorwhitespace <nobody@nobody>2020-10-07 17:22:26 -0400
committerQuentin Young <qlyoung@nvidia.com>2020-10-07 17:22:26 -0400
commit701a01920eee5431d2052aad92aefbdf50ac2139 (patch)
tree2bf2339327241f59593b9583b060ebb347db1cea /tools/indent.py
parentbd407b54d26981f30a95bc316ea2ed965d070c53 (diff)
*: reformat python files
We are now using black. Signed-off-by: Quentin Young <qlyoung@nvidia.com>
Diffstat (limited to 'tools/indent.py')
-rwxr-xr-xtools/indent.py39
1 files changed, 22 insertions, 17 deletions
diff --git a/tools/indent.py b/tools/indent.py
index d2c41e1865..61a0fd4454 100755
--- a/tools/indent.py
+++ b/tools/indent.py
@@ -6,42 +6,47 @@ import sys, re, subprocess, os
# find all DEFUNs
defun_re = re.compile(
- r'^((DEF(UN(|_ATTR|_CMD_(ELEMENT|FUNC_(DECL|TEXT))|_DEPRECATED|_NOSH|_HIDDEN|SH(|_ATTR|_DEPRECATED|_HIDDEN))?|PY|PY_ATTR|PY_HIDDEN)|ALIAS)\s*\(.*?)^(?=\s*\{)',
- re.M | re.S)
-define_re = re.compile(
- r'((^#\s*define[^\n]+[^\\]\n)+)',
- re.M | re.S)
+ r"^((DEF(UN(|_ATTR|_CMD_(ELEMENT|FUNC_(DECL|TEXT))|_DEPRECATED|_NOSH|_HIDDEN|SH(|_ATTR|_DEPRECATED|_HIDDEN))?|PY|PY_ATTR|PY_HIDDEN)|ALIAS)\s*\(.*?)^(?=\s*\{)",
+ re.M | re.S,
+)
+define_re = re.compile(r"((^#\s*define[^\n]+[^\\]\n)+)", re.M | re.S)
# find clang-format control that we just inserted
clean_re = re.compile(
- r'^.*/\* \$FRR indent\$ \*/\s*\n\s*/\* clang-format (on|off) \*/\s*\n',
- re.M)
+ r"^.*/\* \$FRR indent\$ \*/\s*\n\s*/\* clang-format (on|off) \*/\s*\n", re.M
+)
+
def wrap_file(fn):
- with open(fn, 'r') as fd:
+ with open(fn, "r") as fd:
text = fd.read()
- repl = r'/* $FRR indent$ */\n/* clang-format off */\n' + \
- r'\1' + \
- r'/* $FRR indent$ */\n/* clang-format on */\n'
+ repl = (
+ r"/* $FRR indent$ */\n/* clang-format off */\n"
+ + r"\1"
+ + r"/* $FRR indent$ */\n/* clang-format on */\n"
+ )
# around each DEFUN, insert an indent-on/off comment
text = defun_re.sub(repl, text)
text = define_re.sub(repl, text)
- ci = subprocess.Popen(['clang-format'], stdin = subprocess.PIPE, stdout = subprocess.PIPE)
+ ci = subprocess.Popen(
+ ["clang-format"], stdin=subprocess.PIPE, stdout=subprocess.PIPE
+ )
stdout, ign = ci.communicate(text)
ci.wait()
if ci.returncode != 0:
- raise IOError('clang-format returned %d' % (ci.returncode))
+ raise IOError("clang-format returned %d" % (ci.returncode))
# remove the bits we inserted above
- final = clean_re.sub('', stdout)
+ final = clean_re.sub("", stdout)
- tmpname = fn + '.indent'
- with open(tmpname, 'w') as ofd:
+ tmpname = fn + ".indent"
+ with open(tmpname, "w") as ofd:
ofd.write(final)
os.rename(tmpname, fn)
-if __name__ == '__main__':
+
+if __name__ == "__main__":
for fn in sys.argv[1:]:
wrap_file(fn)