[hawkmoth] Re: [PATCH 2/4] hawkmoth: add support for propagating diagnostics

  • From: Bruno Santos <brunomanuelsantos@xxxxxxxxxxxxxxxxxx>
  • To: hawkmoth@xxxxxxxxxxxxx
  • Date: Sun, 28 Apr 2019 19:58:21 +0200

On 16:49:07 2019-04-28, Marius Vlad wrote:

On 4/28/19 12:42 PM, Bruno Santos wrote:
@@ -42,13 +42,35 @@ class CAutoDocDirective(Directive):
     }
     has_content = False
 
+    def __display_parser_diagnostics(self, errors):
+        env = self.state.document.settings.env
+
+        for (severity, filename, lineno, msg) in errors:
+            toprint = '{}:{}: {}'.format(filename, lineno, msg)
+
+            if severity is ErrorLevel.INFO:
+                if env.app.verbosity >= 2:
+                    self.logger.info(toprint,
+                                     location=(env.docname, self.lineno))
+            elif severity is ErrorLevel.WARNING:
+                if env.app.verbosity >= 1:
+                    self.logger.warning(toprint,
+                                        location=(env.docname, 
self.lineno))
+            elif severity is ErrorLevel.ERROR:
+                self.logger.error(toprint, location=(env.docname, 
self.lineno))
+            else:
+                self.logger.critical(toprint,
+                                     location=(env.docname, self.lineno))
+

Minor nit-pick (and to align it to main):

Wouldn't the following be more suitable?

logger.info('{}: {}:{}: {}'.format(severity.name, filename, lineno, msg))

Thanks for the feedback.

Actually no. `severity.name` will resolve to `WARNING`, `ERROR`, etc.
Sphinx already adds `WARNING` by itself. Sadly Sphinx uses a fixed
`WARNING` rather than `%(levelname)s` in their formatter or it would
print different prefixes for different levels instead of printing
`WARNING` for every one.

I'd suggest that's something to ask on the Sphinx side. If we were to
print our own level on top though, we'd see (e.g.) `WARNING: WARNING:`
which is far from pretty.

On the other hand, we could use mimic this in `__main__` and sacrifice
the level information on our side too, but I don't think that's
particularly a good idea.

Cheers,
Bruno

Attachment: signature.asc
Description: PGP signature

Other related posts: