contrib/check-py3-compat.py
branchstable
changeset 29605 519bb4f9d3a4
parent 29550 1c22400db72d
child 29751 8faac092bb0c
--- a/contrib/check-py3-compat.py	Sat Jul 02 09:41:40 2016 -0700
+++ b/contrib/check-py3-compat.py	Mon Jul 18 23:28:14 2016 -0500
@@ -61,7 +61,20 @@
                 imp.load_module(name, fh, '', ('py', 'r', imp.PY_SOURCE))
             except Exception as e:
                 exc_type, exc_value, tb = sys.exc_info()
-                frame = traceback.extract_tb(tb)[-1]
+                # We walk the stack and ignore frames from our custom importer,
+                # import mechanisms, and stdlib modules. This kinda/sorta
+                # emulates CPython behavior in import.c while also attempting
+                # to pin blame on a Mercurial file.
+                for frame in reversed(traceback.extract_tb(tb)):
+                    if frame.name == '_call_with_frames_removed':
+                        continue
+                    if 'importlib' in frame.filename:
+                        continue
+                    if 'mercurial/__init__.py' in frame.filename:
+                        continue
+                    if frame.filename.startswith(sys.prefix):
+                        continue
+                    break
 
                 if frame.filename:
                     filename = os.path.basename(frame.filename)