Patchwork D5845: check-py3-compat: manually format and print warnings

login
register
mail settings
Submitter phabricator
Date Feb. 4, 2019, 11:38 p.m.
Message ID <153e21d3bb4c1119d6560d87080cb2b7@localhost.localdomain>
Download mbox | patch
Permalink /patch/38421/
State Not Applicable
Headers show

Comments

phabricator - Feb. 4, 2019, 11:38 p.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHGba7eaff26474: check-py3-compat: manually format and print warnings (authored by indygreg, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D5845?vs=13772&id=13799

REVISION DETAIL
  https://phab.mercurial-scm.org/D5845

AFFECTED FILES
  contrib/check-py3-compat.py

CHANGE DETAILS




To: indygreg, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/contrib/check-py3-compat.py b/contrib/check-py3-compat.py
--- a/contrib/check-py3-compat.py
+++ b/contrib/check-py3-compat.py
@@ -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)