changeset 41555:ba7eaff26474

check-py3-compat: manually format and print warnings The warnings mechanism may print to stderr on Python 3. Independent buffering of stdout and stderr can lead to warnings output not being printed properly. This commit traps warnings when executing individual files and prints warnings to stdout so output is deterministic. Differential Revision: https://phab.mercurial-scm.org/D5845
author Gregory Szorc <gregory.szorc@gmail.com>
date Mon, 04 Feb 2019 14:38:23 -0800
parents 01417ca7f2e2
children 9f69ddb807f7
files contrib/check-py3-compat.py
diffstat 1 files changed, 7 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/contrib/check-py3-compat.py	Mon Feb 04 14:25:00 2019 -0800
+++ b/contrib/check-py3-compat.py	Mon Feb 04 14:38:23 2019 -0800
@@ -14,6 +14,7 @@
 import os
 import sys
 import traceback
+import warnings
 
 def check_compat_py2(f):
     """Check Python 3 compatibility for a file with Python 2"""
@@ -91,6 +92,11 @@
         fn = check_compat_py3
 
     for f in sys.argv[1:]:
-        fn(f)
+        with warnings.catch_warnings(record=True) as warns:
+            fn(f)
+
+        for w in warns:
+            print(warnings.formatwarning(w.message, w.category,
+                                         w.filename, w.lineno).rstrip())
 
     sys.exit(0)