From c35d206b1715654f3658e51a63765f813661a62b Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 29 Apr 2026 16:38:40 +0000 Subject: [PATCH 1/5] Initial plan From fda0362cec2f6ce8d31f07449cbf2fb472cc421a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 29 Apr 2026 16:43:20 +0000 Subject: [PATCH 2/5] Add :hide_err: option to suppress [runpythonerror] in runpython output Agent-Logs-Url: https://github.com/sdpython/sphinx-runpython/sessions/398ae408-14c9-4d08-b0cf-259ba560c7bb Co-authored-by: xadupre <22452781+xadupre@users.noreply.github.com> --- .../ut_runpython/test_runpython_extension.py | 29 +++++++++++++++++++ .../runpython/sphinx_runpython_extension.py | 8 ++++- 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/_unittests/ut_runpython/test_runpython_extension.py b/_unittests/ut_runpython/test_runpython_extension.py index 99d9a77..ed88ba5 100644 --- a/_unittests/ut_runpython/test_runpython_extension.py +++ b/_unittests/ut_runpython/test_runpython_extension.py @@ -218,6 +218,35 @@ def depart_rp_node(self, node): if t1 not in html: raise AssertionError(html) + def test_runpython_hide_err(self): + """ + Test that :hide_err: suppresses [runpythonerror] from the output. + """ + if "enable_disabled_documented_pieces_of_code" in sys.__dict__: + raise AssertionError("this case should not be") + + content = """ + test a directive + ================ + + .. runpython:: + :rst: + :hide_err: + + import warnings + warnings.warn("deprecated", DeprecationWarning) + print("output line") + """.replace(" ", "") + + html = rst2html(content, writer_name="rst") + + if "runpythonerror" in html: + raise AssertionError(f"[runpythonerror] should not appear in output:\n{html}") + if "DeprecationWarning" in html: + raise AssertionError(f"DeprecationWarning should not appear in output:\n{html}") + if "output line" not in html: + raise AssertionError(f"stdout should still appear in output:\n{html}") + def test_runpython_raw(self): """ this test also test the extension runpython diff --git a/sphinx_runpython/runpython/sphinx_runpython_extension.py b/sphinx_runpython/runpython/sphinx_runpython_extension.py index d5a15d6..63c2589 100644 --- a/sphinx_runpython/runpython/sphinx_runpython_extension.py +++ b/sphinx_runpython/runpython/sphinx_runpython_extension.py @@ -559,6 +559,10 @@ class RunPythonDirective(Directive): the script to be stored somewhere in order to retrieve it. * ``:debug:`` if ``:rst:`` is used, it shows some information to help debugging. + * ``:hide_err:`` if present, hides any error or warning output that would + otherwise be appended as ``[runpythonerror]`` in the content. This is + useful when the code produces stderr output (such as deprecation warnings) + that should not appear in the rendered documentation. Option *rst* can be used the following way:: @@ -630,6 +634,7 @@ class RunPythonDirective(Directive): "store_in_file": directives.unchanged, "linenos": directives.unchanged, "debug": directives.unchanged, + "hide_err": directives.unchanged, } has_content = True runpython_class = runpython_node @@ -693,6 +698,7 @@ def run(self): "store": "store" in self.options and self.options["store"] in bool_set_, "restore": "restore" in self.options and self.options["restore"] in bool_set_, + "hide_err": "hide_err" in self.options, } if p["setsysvar"] is not None and len(p["setsysvar"]) == 0: @@ -821,7 +827,7 @@ def run(self): if err is not None: err = err.rstrip(" \n\r\t") content = out - if len(err) > 0: + if len(err) > 0 and not p["hide_err"]: content += "\n[runpythonerror]\n" + err # add member From 520affbb43d1271c5d44a04c1aa3ff182ddb93e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xavier=20Dupr=C3=A9?= Date: Wed, 29 Apr 2026 19:09:03 +0200 Subject: [PATCH 3/5] fix --- _unittests/ut_runpython/test_runpython_extension.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/_unittests/ut_runpython/test_runpython_extension.py b/_unittests/ut_runpython/test_runpython_extension.py index ed88ba5..77e8ed9 100644 --- a/_unittests/ut_runpython/test_runpython_extension.py +++ b/_unittests/ut_runpython/test_runpython_extension.py @@ -241,9 +241,9 @@ def test_runpython_hide_err(self): html = rst2html(content, writer_name="rst") if "runpythonerror" in html: - raise AssertionError(f"[runpythonerror] should not appear in output:\n{html}") - if "DeprecationWarning" in html: - raise AssertionError(f"DeprecationWarning should not appear in output:\n{html}") + raise AssertionError( + f"[runpythonerror] should not appear in output:\n{html}" + ) if "output line" not in html: raise AssertionError(f"stdout should still appear in output:\n{html}") From c6f686ef6dc6cb1d603ce1e695b9cd05c0b98f38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xavier=20Dupr=C3=A9?= Date: Wed, 29 Apr 2026 19:22:57 +0200 Subject: [PATCH 4/5] fix --- CHANGELOGS.rst | 5 +++++ _unittests/ut_runpython/test_runpython_extension.py | 4 ++-- sphinx_runpython/runpython/sphinx_runpython_extension.py | 8 ++++---- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/CHANGELOGS.rst b/CHANGELOGS.rst index 5ab7192..94aa6c3 100644 --- a/CHANGELOGS.rst +++ b/CHANGELOGS.rst @@ -1,6 +1,11 @@ Change Logs =========== +0.4.3 ++++++ + +* :pr:`56`: Add `:hide_err:` option to suppress `[runpythonerror]` from runpython output + 0.4.2 +++++ diff --git a/_unittests/ut_runpython/test_runpython_extension.py b/_unittests/ut_runpython/test_runpython_extension.py index 77e8ed9..0a79898 100644 --- a/_unittests/ut_runpython/test_runpython_extension.py +++ b/_unittests/ut_runpython/test_runpython_extension.py @@ -220,7 +220,7 @@ def depart_rp_node(self, node): def test_runpython_hide_err(self): """ - Test that :hide_err: suppresses [runpythonerror] from the output. + Test that :hide-err: suppresses [runpythonerror] from the output. """ if "enable_disabled_documented_pieces_of_code" in sys.__dict__: raise AssertionError("this case should not be") @@ -231,7 +231,7 @@ def test_runpython_hide_err(self): .. runpython:: :rst: - :hide_err: + :hide-err: import warnings warnings.warn("deprecated", DeprecationWarning) diff --git a/sphinx_runpython/runpython/sphinx_runpython_extension.py b/sphinx_runpython/runpython/sphinx_runpython_extension.py index 63c2589..9d6c54d 100644 --- a/sphinx_runpython/runpython/sphinx_runpython_extension.py +++ b/sphinx_runpython/runpython/sphinx_runpython_extension.py @@ -559,7 +559,7 @@ class RunPythonDirective(Directive): the script to be stored somewhere in order to retrieve it. * ``:debug:`` if ``:rst:`` is used, it shows some information to help debugging. - * ``:hide_err:`` if present, hides any error or warning output that would + * ``:hide-err:`` if present, hides any error or warning output that would otherwise be appended as ``[runpythonerror]`` in the content. This is useful when the code produces stderr output (such as deprecation warnings) that should not appear in the rendered documentation. @@ -634,7 +634,7 @@ class RunPythonDirective(Directive): "store_in_file": directives.unchanged, "linenos": directives.unchanged, "debug": directives.unchanged, - "hide_err": directives.unchanged, + "hide-err": directives.unchanged, } has_content = True runpython_class = runpython_node @@ -698,7 +698,7 @@ def run(self): "store": "store" in self.options and self.options["store"] in bool_set_, "restore": "restore" in self.options and self.options["restore"] in bool_set_, - "hide_err": "hide_err" in self.options, + "hide-err": "hide-err" in self.options, } if p["setsysvar"] is not None and len(p["setsysvar"]) == 0: @@ -827,7 +827,7 @@ def run(self): if err is not None: err = err.rstrip(" \n\r\t") content = out - if len(err) > 0 and not p["hide_err"]: + if len(err) > 0 and not p["hide-err"]: content += "\n[runpythonerror]\n" + err # add member From cbd9f7662e956d088037622ebc967091b5a1c406 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xavier=20Dupr=C3=A9?= Date: Wed, 29 Apr 2026 19:23:46 +0200 Subject: [PATCH 5/5] fix --- _doc/index.rst | 3 +-- sphinx_runpython/__init__.py | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/_doc/index.rst b/_doc/index.rst index 7724d9c..d393840 100644 --- a/_doc/index.rst +++ b/_doc/index.rst @@ -54,7 +54,6 @@ Sources available on Older versions ++++++++++++++ +* `0.4.3 <../v0.4.3/index.html>`_ * `0.4.2 <../v0.4.2/index.html>`_ -* `0.4.1 <../v0.4.1/index.html>`_ -* `0.4.0 <../v0.4.0/index.html>`_ * `0.3.0 <../v0.3.0/index.html>`_ diff --git a/sphinx_runpython/__init__.py b/sphinx_runpython/__init__.py index 104ec78..a8a9b0a 100644 --- a/sphinx_runpython/__init__.py +++ b/sphinx_runpython/__init__.py @@ -1,4 +1,4 @@ -__version__ = "0.4.2" +__version__ = "0.4.3" __author__ = "Xavier Dupré" __github__ = "https://github.com/sdpython/sphinx-runpython" __url__ = "https://sdpython.github.io/doc/sphinx-runpython/dev/"