eric7/DebugClients/Python/coverage/report.py

branch
eric7
changeset 8775
0802ae193343
parent 8312
800c432b34c8
child 8929
fcca2fa618bf
--- a/eric7/DebugClients/Python/coverage/report.py	Fri Nov 19 19:28:47 2021 +0100
+++ b/eric7/DebugClients/Python/coverage/report.py	Sat Nov 20 16:47:38 2021 +0100
@@ -2,35 +2,35 @@
 # For details: https://github.com/nedbat/coveragepy/blob/master/NOTICE.txt
 
 """Reporter foundation for coverage.py."""
+
 import sys
 
-from coverage import env
+from coverage.exceptions import CoverageException, NotPython
 from coverage.files import prep_patterns, FnmatchMatcher
-from coverage.misc import CoverageException, NoSource, NotPython, ensure_dir_for_file, file_be_gone
+from coverage.misc import ensure_dir_for_file, file_be_gone
 
 
-def render_report(output_path, reporter, morfs):
-    """Run the provided reporter ensuring any required setup and cleanup is done
+def render_report(output_path, reporter, morfs, msgfn):
+    """Run a one-file report generator, managing the output file.
 
-    At a high level this method ensures the output file is ready to be written to. Then writes the
-    report to it. Then closes the file and deletes any garbage created if necessary.
+    This function ensures the output file is ready to be written to. Then writes
+    the report to it. Then closes the file and cleans up.
+
     """
     file_to_close = None
     delete_file = False
-    if output_path:
-        if output_path == '-':
-            outfile = sys.stdout
-        else:
-            # Ensure that the output directory is created; done here
-            # because this report pre-opens the output file.
-            # HTMLReport does this using the Report plumbing because
-            # its task is more complex, being multiple files.
-            ensure_dir_for_file(output_path)
-            open_kwargs = {}
-            if env.PY3:
-                open_kwargs['encoding'] = 'utf8'
-            outfile = open(output_path, "w", **open_kwargs)
-            file_to_close = outfile
+
+    if output_path == "-":
+        outfile = sys.stdout
+    else:
+        # Ensure that the output directory is created; done here
+        # because this report pre-opens the output file.
+        # HTMLReport does this using the Report plumbing because
+        # its task is more complex, being multiple files.
+        ensure_dir_for_file(output_path)
+        outfile = open(output_path, "w", encoding="utf-8")
+        file_to_close = outfile
+
     try:
         return reporter.report(morfs, outfile=outfile)
     except CoverageException:
@@ -40,7 +40,9 @@
         if file_to_close:
             file_to_close.close()
             if delete_file:
-                file_be_gone(output_path)
+                file_be_gone(output_path)           # pragma: part covered (doesn't return)
+            else:
+                msgfn(f"Wrote {reporter.report_type} to {output_path}")
 
 
 def get_analysis_to_report(coverage, morfs):
@@ -55,11 +57,11 @@
     config = coverage.config
 
     if config.report_include:
-        matcher = FnmatchMatcher(prep_patterns(config.report_include))
+        matcher = FnmatchMatcher(prep_patterns(config.report_include), "report_include")
         file_reporters = [fr for fr in file_reporters if matcher.match(fr.filename)]
 
     if config.report_omit:
-        matcher = FnmatchMatcher(prep_patterns(config.report_omit))
+        matcher = FnmatchMatcher(prep_patterns(config.report_omit), "report_omit")
         file_reporters = [fr for fr in file_reporters if not matcher.match(fr.filename)]
 
     if not file_reporters:
@@ -68,9 +70,6 @@
     for fr in sorted(file_reporters):
         try:
             analysis = coverage._analyze(fr)
-        except NoSource:
-            if not config.ignore_errors:
-                raise
         except NotPython:
             # Only report errors for .py files, and only if we didn't
             # explicitly suppress those errors.
@@ -78,9 +77,15 @@
             # should_be_python() method.
             if fr.should_be_python():
                 if config.ignore_errors:
-                    msg = "Couldn't parse Python file '{}'".format(fr.filename)
+                    msg = f"Couldn't parse Python file '{fr.filename}'"
                     coverage._warn(msg, slug="couldnt-parse")
                 else:
                     raise
+        except Exception as exc:
+            if config.ignore_errors:
+                msg = f"Couldn't parse '{fr.filename}': {exc}".rstrip()
+                coverage._warn(msg, slug="couldnt-parse")
+            else:
+                raise
         else:
             yield (fr, analysis)

eric ide

mercurial