[PATCH] D126855: [clang-tidy] check_clang_tidy.py: Print output nicely in Python 3.

Martin Böhme via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 1 22:28:32 PDT 2022


mboehme created this revision.
Herald added a subscriber: xazax.hun.
Herald added a project: All.
mboehme requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.

In Python 3, `encode()` produces a `bytes`. The way this is printed makes it
very hard to read the clang-tidy output because everything gets jammed onto one
line (newlines are printed as `\n`).

The `encode()` was introduced here:

https://github.com/llvm/llvm-project/commit/a35efc4dcb70658ebd704c28dfeed4cc2bac095b

It seems that this was done to print non-ASCII characters correctly in Python 2,
and this seems worth preserving (though anyone still on Python 2 should really
be migrating).

For the time being, I've simply introduced a version distinction. I'm not sure
if there's a more idiomatic way to do this that works in both Python 2 and
Python 3 -- input welcome!


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D126855

Files:
  clang-tools-extra/test/clang-tidy/check_clang_tidy.py


Index: clang-tools-extra/test/clang-tidy/check_clang_tidy.py
===================================================================
--- clang-tools-extra/test/clang-tidy/check_clang_tidy.py
+++ clang-tools-extra/test/clang-tidy/check_clang_tidy.py
@@ -173,7 +173,10 @@
     print('Running ' + repr(args) + '...')
     clang_tidy_output = try_run(args)
     print('------------------------ clang-tidy output -----------------------')
-    print(clang_tidy_output.encode())
+    if sys.version_info.major >= 3:
+      print(clang_tidy_output);
+    else:
+      print(clang_tidy_output.encode())
     print('\n------------------------------------------------------------------')
 
     diff_output = try_run(['diff', '-u', self.original_file_name, self.temp_file_name], False)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D126855.433654.patch
Type: text/x-patch
Size: 772 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220602/3b6d2456/attachment.bin>


More information about the cfe-commits mailing list