From 0bdde6a20cc076e3154eb5c2af5b8c022c8a4331 Mon Sep 17 00:00:00 2001 From: Piet Van Reepingen Date: Fri, 11 Oct 2019 16:50:48 +0200 Subject: [PATCH 1/6] Catch exeptions in the only handling Fixes https://github.com/pfalcon/sphinx_selective_exclude/issues/6 --- sphinx_selective_exclude/eager_only.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/sphinx_selective_exclude/eager_only.py b/sphinx_selective_exclude/eager_only.py index 82766c2..5d0cf70 100644 --- a/sphinx_selective_exclude/eager_only.py +++ b/sphinx_selective_exclude/eager_only.py @@ -22,7 +22,7 @@ # import sphinx from docutils.parsers.rst import directives - +from sphinx.util import logging class EagerOnly(sphinx.directives.other.Only): @@ -31,9 +31,13 @@ def run(self, *args): env = self.state.document.settings.env env.app.builder.tags.add('TRUE') #print(repr(self.arguments[0])) - if not env.app.builder.tags.eval_condition(self.arguments[0]): - return [] - + try: + if not env.app.builder.tags.eval_condition(self.arguments[0]): + return [] + except Exception as err: + logger = logging.getLogger(__name__) + logger.warning(('exception while evaluating only directive expression: %s'), err, + location=(self.env.docname, self.lineno)) # Otherwise, do the usual processing nodes = super(EagerOnly, self).run() if len(nodes) == 1: From 960ac15c8826af00be5dc20612263589570a47c3 Mon Sep 17 00:00:00 2001 From: Piet Van Reepingen Date: Mon, 14 Oct 2019 10:22:51 +0200 Subject: [PATCH 2/6] Add raise exception after logging --- sphinx_selective_exclude/eager_only.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sphinx_selective_exclude/eager_only.py b/sphinx_selective_exclude/eager_only.py index 5d0cf70..e5d04b5 100644 --- a/sphinx_selective_exclude/eager_only.py +++ b/sphinx_selective_exclude/eager_only.py @@ -24,6 +24,7 @@ from docutils.parsers.rst import directives from sphinx.util import logging + class EagerOnly(sphinx.directives.other.Only): def run(self, *args): @@ -38,6 +39,7 @@ def run(self, *args): logger = logging.getLogger(__name__) logger.warning(('exception while evaluating only directive expression: %s'), err, location=(self.env.docname, self.lineno)) + raise # Otherwise, do the usual processing nodes = super(EagerOnly, self).run() if len(nodes) == 1: From 2a320e7a8c69b3f1cae5a6d8a10ba50af6ac0c1f Mon Sep 17 00:00:00 2001 From: Piet Van Reepingen Date: Fri, 25 Oct 2019 15:46:25 +0200 Subject: [PATCH 3/6] Add quotes around 'only' and remove superfluous braces --- sphinx_selective_exclude/eager_only.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sphinx_selective_exclude/eager_only.py b/sphinx_selective_exclude/eager_only.py index e5d04b5..4a370fa 100644 --- a/sphinx_selective_exclude/eager_only.py +++ b/sphinx_selective_exclude/eager_only.py @@ -37,7 +37,7 @@ def run(self, *args): return [] except Exception as err: logger = logging.getLogger(__name__) - logger.warning(('exception while evaluating only directive expression: %s'), err, + logger.warning("exception while evaluating 'only' directive expression: %s", err, location=(self.env.docname, self.lineno)) raise # Otherwise, do the usual processing From 3aff2e12b1cdaab9a83e1d36ccd5ef20ad00e10d Mon Sep 17 00:00:00 2001 From: Piet Van Reepingen Date: Mon, 23 Dec 2019 14:18:08 +0100 Subject: [PATCH 4/6] Use sphinx.util.logging.getLogger as suggested --- sphinx_selective_exclude/eager_only.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sphinx_selective_exclude/eager_only.py b/sphinx_selective_exclude/eager_only.py index 4a370fa..cbd357e 100644 --- a/sphinx_selective_exclude/eager_only.py +++ b/sphinx_selective_exclude/eager_only.py @@ -36,7 +36,7 @@ def run(self, *args): if not env.app.builder.tags.eval_condition(self.arguments[0]): return [] except Exception as err: - logger = logging.getLogger(__name__) + logger = sphinx.util.logging.getLogger(__name__) logger.warning("exception while evaluating 'only' directive expression: %s", err, location=(self.env.docname, self.lineno)) raise From 4961e9e13f763fe469341dc707253f1216b0ee56 Mon Sep 17 00:00:00 2001 From: Piet Van Reepingen <52536820+pietvr@users.noreply.github.com> Date: Thu, 15 Sep 2022 18:33:05 +0200 Subject: [PATCH 5/6] Update sphinx_selective_exclude/eager_only.py Co-authored-by: Jasper Craeghs <28319872+JasperCraeghs@users.noreply.github.com> --- sphinx_selective_exclude/eager_only.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/sphinx_selective_exclude/eager_only.py b/sphinx_selective_exclude/eager_only.py index cbd357e..94bcb30 100644 --- a/sphinx_selective_exclude/eager_only.py +++ b/sphinx_selective_exclude/eager_only.py @@ -36,10 +36,9 @@ def run(self, *args): if not env.app.builder.tags.eval_condition(self.arguments[0]): return [] except Exception as err: - logger = sphinx.util.logging.getLogger(__name__) - logger.warning("exception while evaluating 'only' directive expression: %s", err, + logger.critical("Exception while evaluating 'only' directive expression: %r", err, location=(self.env.docname, self.lineno)) - raise + raise err # Otherwise, do the usual processing nodes = super(EagerOnly, self).run() if len(nodes) == 1: From a0ba933321f5653152b65016350894cec541f688 Mon Sep 17 00:00:00 2001 From: Piet Van Reepingen <52536820+pietvr@users.noreply.github.com> Date: Thu, 15 Sep 2022 18:33:13 +0200 Subject: [PATCH 6/6] Update sphinx_selective_exclude/eager_only.py Co-authored-by: Jasper Craeghs <28319872+JasperCraeghs@users.noreply.github.com> --- sphinx_selective_exclude/eager_only.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sphinx_selective_exclude/eager_only.py b/sphinx_selective_exclude/eager_only.py index 94bcb30..92ea4f9 100644 --- a/sphinx_selective_exclude/eager_only.py +++ b/sphinx_selective_exclude/eager_only.py @@ -25,6 +25,9 @@ from sphinx.util import logging +logger = sphinx.util.logging.getLogger(__name__) + + class EagerOnly(sphinx.directives.other.Only): def run(self, *args):