From 9e7b0fa1717532a023cb294371ccb6a51d1c141e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xavier=20Dupr=C3=A9?= Date: Thu, 26 Feb 2026 18:32:20 +0100 Subject: [PATCH 1/4] fix url --- .../gdot/sphinx_gdot_extension.py | 19 ++----------------- sphinx_runpython/sphinx_rst_builder.py | 1 + 2 files changed, 3 insertions(+), 17 deletions(-) diff --git a/sphinx_runpython/gdot/sphinx_gdot_extension.py b/sphinx_runpython/gdot/sphinx_gdot_extension.py index f527be1..f2c763f 100644 --- a/sphinx_runpython/gdot/sphinx_gdot_extension.py +++ b/sphinx_runpython/gdot/sphinx_gdot_extension.py @@ -102,10 +102,7 @@ class GDotDirective(Directive): "process": directives.unchanged, } - _default_url = ( - "https://github.com/sdpython/jyquickhelper/raw/master/src/" - "jyquickhelper/js/vizjs/viz.js" - ) + _default_url = "https://cdnjs.cloudflare.com/ajax/libs/viz.js/1.8.0/viz-lite.js" def run(self): """ @@ -120,19 +117,7 @@ def run(self): bool_set_ = (True, 1, "True", "1", "true", "") process = "process" in self.options and self.options["process"] in bool_set_ if url == "local": - try: - import jyquickhelper - - path = os.path.join( - os.path.dirname(jyquickhelper.__file__), "js", "vizjs", "viz.js" - ) - if not os.path.exists(path): - raise ImportError("jyquickelper needs to be updated to get viz.js.") - url = "local" - except ImportError: - url = GDotDirective._default_url - logger = logging.getLogger("gdot") - logger.warning("[gdot] use %r", url) + url = GDotDirective._default_url info = get_env_state_info(self) docname = info["docname"] diff --git a/sphinx_runpython/sphinx_rst_builder.py b/sphinx_runpython/sphinx_rst_builder.py index 627c359..c7d47e0 100644 --- a/sphinx_runpython/sphinx_rst_builder.py +++ b/sphinx_runpython/sphinx_rst_builder.py @@ -1421,6 +1421,7 @@ def get_outfilename(self, pagename): return f"{self.outdir}/{pagename}.rst".replace("\\", "/") def write_doc(self, docname, doctree): + """wrtie documentation""" destination = StringOutput(encoding="utf-8") self.current_docname = docname self.writer.write(doctree, destination) From cb8e8f2025a5718851a192f7e4b02f0fc7c83c4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xavier=20Dupr=C3=A9?= Date: Thu, 26 Feb 2026 18:34:55 +0100 Subject: [PATCH 2/4] spell --- CHANGELOGS.rst | 2 +- sphinx_runpython/sphinx_rst_builder.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOGS.rst b/CHANGELOGS.rst index 090165f..f231c6b 100644 --- a/CHANGELOGS.rst +++ b/CHANGELOGS.rst @@ -4,7 +4,7 @@ Change Logs 0.4.1 +++++ -* :pr:`42`: excludes failing functions from pybind11 in docassert +* :pr:`42`: excludes failing functions from pybind11 in docassert 0.4.0 +++++ diff --git a/sphinx_runpython/sphinx_rst_builder.py b/sphinx_runpython/sphinx_rst_builder.py index c7d47e0..5b0c02e 100644 --- a/sphinx_runpython/sphinx_rst_builder.py +++ b/sphinx_runpython/sphinx_rst_builder.py @@ -1421,7 +1421,7 @@ def get_outfilename(self, pagename): return f"{self.outdir}/{pagename}.rst".replace("\\", "/") def write_doc(self, docname, doctree): - """wrtie documentation""" + """write documentation""" destination = StringOutput(encoding="utf-8") self.current_docname = docname self.writer.write(doctree, destination) From eca8fbb1cb3d4fcd4e0847abd880443e39ac70c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xavier=20Dupr=C3=A9?= Date: Thu, 26 Feb 2026 19:04:22 +0100 Subject: [PATCH 3/4] fix --- _unittests/ut_docassert/test_docassert.py | 18 ++--- .../gdot/sphinx_gdot_extension.py | 76 ++++++------------- .../runpython/sphinx_runpython_extension.py | 24 +++++- 3 files changed, 53 insertions(+), 65 deletions(-) diff --git a/_unittests/ut_docassert/test_docassert.py b/_unittests/ut_docassert/test_docassert.py index 77fd152..e7ddb08 100644 --- a/_unittests/ut_docassert/test_docassert.py +++ b/_unittests/ut_docassert/test_docassert.py @@ -57,7 +57,7 @@ def __len__(self): for line in lines: if "'onefunction' has no parameter 'c'" in line: nb += 1 - if nb == 0 and "failed to import function" not in str(warn): + if nb == 0 and "failed to import " not in str(warn): raise AssertionError("not the right warning:\n" + "\n".join(lines)) @ignore_warnings(PendingDeprecationWarning) @@ -100,7 +100,7 @@ def __len__(self): for line in lines: if "'onemethod' has no parameter 'c'" in line: nb += 1 - if nb == 0 and "failed to import method" not in str(warn): + if nb == 0 and "failed to import " not in str(warn): raise AssertionError("not the right warning:\n" + "\n".join(lines)) for line in lines: if "'onemethod' has undocumented parameters 'b, self'" in line: @@ -147,8 +147,10 @@ def __len__(self): nb += 1 if "'Estimator' has undocumented parameters" in line: nb += 1 - if nb == 0 and "failed to import class" not in str(warn): - raise AssertionError("not the right warning:\n" + "\n".join(lines)) + if nb == 0 and "failed to import " not in str(warn): + raise AssertionError( + "not the right warning:\n" + "\n".join(lines) + "\n" + str(warn) + ) @ignore_warnings(PendingDeprecationWarning) def test_docassert_html_init2(self): @@ -191,7 +193,7 @@ def __len__(self): nb += 1 if "'Estimator2' has undocumented parameters" in line: nb += 1 - if nb == 0 and "failed to import class" not in str(warn): + if nb == 0 and "failed to import " not in str(warn): raise AssertionError("not the right warning:\n" + "\n".join(lines)) @ignore_warnings(PendingDeprecationWarning) @@ -223,9 +225,7 @@ def __len__(self): with sys_path_append(data): _obj, _name = import_object("clsslk.Estimator3", "class") newstring = ".. autoclass:: clsslk.Estimator3" - html, warn = rst2html( - newstring, return_warnings=True, new_extensions=["numpydoc"] - ) + html, warn = rst2html(newstring, return_warnings=True) self.assertTrue(html is not None) lines = log_capture_string.getvalue().split("\n") @@ -237,7 +237,7 @@ def __len__(self): nb += 1 if "'Estimator3' has undocumented parameters 'fit" in line: nb += 1 - if nb == 0 and "failed to import class" not in str(warn): + if nb == 0 and "failed to import " not in str(warn): raise AssertionError("not the right warning:\n" + "\n".join(lines)) def test_extract_signature(self): diff --git a/sphinx_runpython/gdot/sphinx_gdot_extension.py b/sphinx_runpython/gdot/sphinx_gdot_extension.py index f2c763f..d3f1dcc 100644 --- a/sphinx_runpython/gdot/sphinx_gdot_extension.py +++ b/sphinx_runpython/gdot/sphinx_gdot_extension.py @@ -1,6 +1,5 @@ import os import logging -import shutil from docutils import nodes from docutils.parsers.rst import directives, Directive import sphinx @@ -150,11 +149,13 @@ def run(self): if script or script == "": stdout, stderr, _ = run_python_script(content, process=process) if stderr: + logger = logging.getLogger("gdot") logger.warning("[gdot] a dot graph cannot be draw due to %s", stderr) content = stdout if script: spl = content.split(script) if len(spl) > 2: + logger = logging.getLogger("gdot") logger.warning("[gdot] too many output lines %s", content) content = spl[-1] @@ -285,13 +286,6 @@ def depart_gdot_node_html(self, node): def copy_js_files(app): - try: - import jyquickhelper - - local = True - except ImportError: - local = False - logger = logging.getLogger("gdot") dest = app.config.html_static_path if isinstance(dest, list) and len(dest) > 0: @@ -318,63 +312,41 @@ def copy_js_files(app): # viz.js file_dest = os.path.join(destf, "viz.js") - if os.path.exists(file_dest): - logger.info("[gdot] %r already installed.", file_dest) - else: - if local: - path = os.path.join( - os.path.dirname(jyquickhelper.__file__), "js", "vizjs", "viz.js" + if not os.path.exists(file_dest): + logger.info("[gdot] viz.js, use %r", GDotDirective._default_url) + + try: + content = get_url_content_timeout( + GDotDirective._default_url, output=file_dest, raise_exception=False + ) + except Exception as e: + logger.warning("[gdot] download failed due to %r", e) + content = None + + if content is None: + logger.warning( + "[gdot] unable to download %r to %r", + GDotDirective._default_url, + file_dest, ) - if os.path.exists(path): - # We copy the file to static path. - try: - shutil.copy(path, file_dest) - logger.info("[gdot] copy %r to %r.", path, file_dest) - except PermissionError as e: - logger.warning( - "[gdot] permission error (%r), unable to use local viz.js", e - ) - else: - logger.warning("[gdot] unable to find %r", path) else: - logger.info("[gdot] viz.js, use %r", GDotDirective._default_url) - - file_dest = os.path.join(destf, "require.js") - try: - content = get_url_content_timeout( - GDotDirective._default_url, output=file_dest, raise_exception=False - ) - except Exception as e: - logger.warning("[gdot] download failed due to %r", e) - content = None - - if content is None: - logger.warning( - "[gdot] unable to download %r to %r", - GDotDirective._default_url, - file_dest, - ) - else: - logger.info( - "[gdot] download %r to %r", GDotDirective._default_url, file_dest - ) + logger.info( + "[gdot] download %r to %r", GDotDirective._default_url, file_dest + ) # require.js file_dest = os.path.join(destf, "require.js") - if os.path.exists(file_dest): - logger.info("[gdot] %r already installed.", file_dest) - else: + if not os.path.exists(file_dest): + logger.info("[gdot] download %r", file_dest) try: download_requirejs(destf) except Exception as e: logger.warning("[gdot] download_requirejs failed due to %r", e) - if os.path.exists(file_dest): + if not os.path.exists(file_dest): # It adds # at the bottom of the file. It needs to be at the beginning. # app.add_js_file("require.js", priority=200) - logger.info("[gdot] %r installed.", file_dest) - else: logger.warning("[gdot] %r not installed.", file_dest) diff --git a/sphinx_runpython/runpython/sphinx_runpython_extension.py b/sphinx_runpython/runpython/sphinx_runpython_extension.py index 1c16ec0..978e606 100644 --- a/sphinx_runpython/runpython/sphinx_runpython_extension.py +++ b/sphinx_runpython/runpython/sphinx_runpython_extension.py @@ -372,7 +372,7 @@ def interpret(s): try: out, err = run_cmd(cmd, script_arg, wait=True, change_path=chdir) - return out, err, None + return out, _filter_error(err), None except Exception as ee: if not exception: message = ( # noqa: UP030 @@ -383,7 +383,7 @@ def interpret(s): if exc_path: message += f"\n---EXC--\n{exc_path}" raise RunPythonExecutionError(message) from ee - return str(ee), str(ee), None + return str(ee), _filter_error(str(ee)), None else: if store_in_file: raise NotImplementedError( @@ -446,7 +446,7 @@ def interpret(s): "\n{5}\n--TRACEBACK--\n{6}" ).format(script, params, comment, gout, gerr, ee, excs) raise RunPythonExecutionError(message) from ee - return (gout + "\n" + gerr), (gerr + "\n" + excs), None + return (gout + "\n" + gerr), _filter_error(gerr + "\n" + excs), None if chdir is not None: os.chdir(current) @@ -462,7 +462,23 @@ def interpret(s): for k, v in globs.items() if k.startswith("__runpython__") and k not in avoid } - return gout, gerr, context + return gout, _filter_error(gerr), context + + +def _filter_error(err): + if not err: + return err + out = [ + "use_kernel_func_from_hub", + "is deprecated, use", + "was set in the config but", + ] + if isinstance(err, str): + res = "\n".join([_ for _ in err.split("\n") if all(o not in _ for o in out)]) + return res + bout = [_.encode("utf-8") for _ in out] + res = b"\n".join([_ for _ in err.split(b"\n") if all(o not in _ for o in bout)]) + return res class runpython_node(nodes.Structural, nodes.Element): From a998b35844c834a46bc8e0cb13c66a827e5cfb61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xavier=20Dupr=C3=A9?= Date: Thu, 26 Feb 2026 19:14:37 +0100 Subject: [PATCH 4/4] last --- .../gdot/sphinx_gdot_extension.py | 22 +++++++++++++++++++ .../runpython/sphinx_runpython_extension.py | 2 -- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/sphinx_runpython/gdot/sphinx_gdot_extension.py b/sphinx_runpython/gdot/sphinx_gdot_extension.py index d3f1dcc..b9b7083 100644 --- a/sphinx_runpython/gdot/sphinx_gdot_extension.py +++ b/sphinx_runpython/gdot/sphinx_gdot_extension.py @@ -148,6 +148,28 @@ def run(self): content = "\n".join(self.content) if script or script == "": stdout, stderr, _ = run_python_script(content, process=process) + + if stderr: + out = [ + "use_kernel_func_from_hub", + "is deprecated, use", + "was set in the config but", + "The axis name: batch will not be used", + ] + if isinstance(stderr, str): + stderr = "\n".join( + [_ for _ in stderr.split("\n") if all(o not in _ for o in out)] + ) + else: + bout = [_.encode("utf-8") for _ in out] + stderr = b"\n".join( + [ + _ + for _ in stderr.split(b"\n") + if all(o not in _ for o in bout) + ] + ) + if stderr: logger = logging.getLogger("gdot") logger.warning("[gdot] a dot graph cannot be draw due to %s", stderr) diff --git a/sphinx_runpython/runpython/sphinx_runpython_extension.py b/sphinx_runpython/runpython/sphinx_runpython_extension.py index 978e606..bf8b807 100644 --- a/sphinx_runpython/runpython/sphinx_runpython_extension.py +++ b/sphinx_runpython/runpython/sphinx_runpython_extension.py @@ -470,8 +470,6 @@ def _filter_error(err): return err out = [ "use_kernel_func_from_hub", - "is deprecated, use", - "was set in the config but", ] if isinstance(err, str): res = "\n".join([_ for _ in err.split("\n") if all(o not in _ for o in out)])