Visitar URL original
fix url (#44) · sdpython/sphinx-runpython@163e255 · GitHub
Skip to content

Commit 163e255

Browse files
authored
fix url (#44)
* fix url * spell * fix
1 parent fb4052e commit 163e255

5 files changed

Lines changed: 57 additions & 83 deletions

File tree

‎CHANGELOGS.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Change Logs
44
0.4.1
55
+++++
66

7-
* :pr:`42`: excludes failing functions from pybind11 in docassert
7+
* :pr:`42`: excludes failing functions from pybind11 in docassert
88

99
0.4.0
1010
+++++

‎_unittests/ut_docassert/test_docassert.py‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def __len__(self):
5757
for line in lines:
5858
if "'onefunction' has no parameter 'c'" in line:
5959
nb += 1
60-
if nb == 0 and "failed to import function" not in str(warn):
60+
if nb == 0 and "failed to import " not in str(warn):
6161
raise AssertionError("not the right warning:\n" + "\n".join(lines))
6262

6363
@ignore_warnings(PendingDeprecationWarning)
@@ -100,7 +100,7 @@ def __len__(self):
100100
for line in lines:
101101
if "'onemethod' has no parameter 'c'" in line:
102102
nb += 1
103-
if nb == 0 and "failed to import method" not in str(warn):
103+
if nb == 0 and "failed to import " not in str(warn):
104104
raise AssertionError("not the right warning:\n" + "\n".join(lines))
105105
for line in lines:
106106
if "'onemethod' has undocumented parameters 'b, self'" in line:
@@ -147,8 +147,10 @@ def __len__(self):
147147
nb += 1
148148
if "'Estimator' has undocumented parameters" in line:
149149
nb += 1
150-
if nb == 0 and "failed to import class" not in str(warn):
151-
raise AssertionError("not the right warning:\n" + "\n".join(lines))
150+
if nb == 0 and "failed to import " not in str(warn):
151+
raise AssertionError(
152+
"not the right warning:\n" + "\n".join(lines) + "\n" + str(warn)
153+
)
152154

153155
@ignore_warnings(PendingDeprecationWarning)
154156
def test_docassert_html_init2(self):
@@ -191,7 +193,7 @@ def __len__(self):
191193
nb += 1
192194
if "'Estimator2' has undocumented parameters" in line:
193195
nb += 1
194-
if nb == 0 and "failed to import class" not in str(warn):
196+
if nb == 0 and "failed to import " not in str(warn):
195197
raise AssertionError("not the right warning:\n" + "\n".join(lines))
196198

197199
@ignore_warnings(PendingDeprecationWarning)
@@ -223,9 +225,7 @@ def __len__(self):
223225
with sys_path_append(data):
224226
_obj, _name = import_object("clsslk.Estimator3", "class")
225227
newstring = ".. autoclass:: clsslk.Estimator3"
226-
html, warn = rst2html(
227-
newstring, return_warnings=True, new_extensions=["numpydoc"]
228-
)
228+
html, warn = rst2html(newstring, return_warnings=True)
229229
self.assertTrue(html is not None)
230230

231231
lines = log_capture_string.getvalue().split("\n")
@@ -237,7 +237,7 @@ def __len__(self):
237237
nb += 1
238238
if "'Estimator3' has undocumented parameters 'fit" in line:
239239
nb += 1
240-
if nb == 0 and "failed to import class" not in str(warn):
240+
if nb == 0 and "failed to import " not in str(warn):
241241
raise AssertionError("not the right warning:\n" + "\n".join(lines))
242242

243243
def test_extract_signature(self):

‎sphinx_runpython/gdot/sphinx_gdot_extension.py‎

Lines changed: 26 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import os
22
import logging
3-
import shutil
43
from docutils import nodes
54
from docutils.parsers.rst import directives, Directive
65
import sphinx
@@ -102,10 +101,7 @@ class GDotDirective(Directive):
102101
"process": directives.unchanged,
103102
}
104103

105-
_default_url = (
106-
"https://github.com/sdpython/jyquickhelper/raw/master/src/"
107-
"jyquickhelper/js/vizjs/viz.js"
108-
)
104+
_default_url = "https://cdnjs.cloudflare.com/ajax/libs/viz.js/1.8.0/viz-lite.js"
109105

110106
def run(self):
111107
"""
@@ -120,19 +116,7 @@ def run(self):
120116
bool_set_ = (True, 1, "True", "1", "true", "")
121117
process = "process" in self.options and self.options["process"] in bool_set_
122118
if url == "local":
123-
try:
124-
import jyquickhelper
125-
126-
path = os.path.join(
127-
os.path.dirname(jyquickhelper.__file__), "js", "vizjs", "viz.js"
128-
)
129-
if not os.path.exists(path):
130-
raise ImportError("jyquickelper needs to be updated to get viz.js.")
131-
url = "local"
132-
except ImportError:
133-
url = GDotDirective._default_url
134-
logger = logging.getLogger("gdot")
135-
logger.warning("[gdot] use %r", url)
119+
url = GDotDirective._default_url
136120

137121
info = get_env_state_info(self)
138122
docname = info["docname"]
@@ -165,11 +149,13 @@ def run(self):
165149
if script or script == "":
166150
stdout, stderr, _ = run_python_script(content, process=process)
167151
if stderr:
152+
logger = logging.getLogger("gdot")
168153
logger.warning("[gdot] a dot graph cannot be draw due to %s", stderr)
169154
content = stdout
170155
if script:
171156
spl = content.split(script)
172157
if len(spl) > 2:
158+
logger = logging.getLogger("gdot")
173159
logger.warning("[gdot] too many output lines %s", content)
174160
content = spl[-1]
175161

@@ -300,13 +286,6 @@ def depart_gdot_node_html(self, node):
300286

301287

302288
def copy_js_files(app):
303-
try:
304-
import jyquickhelper
305-
306-
local = True
307-
except ImportError:
308-
local = False
309-
310289
logger = logging.getLogger("gdot")
311290
dest = app.config.html_static_path
312291
if isinstance(dest, list) and len(dest) > 0:
@@ -333,63 +312,41 @@ def copy_js_files(app):
333312

334313
# viz.js
335314
file_dest = os.path.join(destf, "viz.js")
336-
if os.path.exists(file_dest):
337-
logger.info("[gdot] %r already installed.", file_dest)
338-
else:
339-
if local:
340-
path = os.path.join(
341-
os.path.dirname(jyquickhelper.__file__), "js", "vizjs", "viz.js"
315+
if not os.path.exists(file_dest):
316+
logger.info("[gdot] viz.js, use %r", GDotDirective._default_url)
317+
318+
try:
319+
content = get_url_content_timeout(
320+
GDotDirective._default_url, output=file_dest, raise_exception=False
321+
)
322+
except Exception as e:
323+
logger.warning("[gdot] download failed due to %r", e)
324+
content = None
325+
326+
if content is None:
327+
logger.warning(
328+
"[gdot] unable to download %r to %r",
329+
GDotDirective._default_url,
330+
file_dest,
342331
)
343-
if os.path.exists(path):
344-
# We copy the file to static path.
345-
try:
346-
shutil.copy(path, file_dest)
347-
logger.info("[gdot] copy %r to %r.", path, file_dest)
348-
except PermissionError as e:
349-
logger.warning(
350-
"[gdot] permission error (%r), unable to use local viz.js", e
351-
)
352-
else:
353-
logger.warning("[gdot] unable to find %r", path)
354332
else:
355-
logger.info("[gdot] viz.js, use %r", GDotDirective._default_url)
356-
357-
file_dest = os.path.join(destf, "require.js")
358-
try:
359-
content = get_url_content_timeout(
360-
GDotDirective._default_url, output=file_dest, raise_exception=False
361-
)
362-
except Exception as e:
363-
logger.warning("[gdot] download failed due to %r", e)
364-
content = None
365-
366-
if content is None:
367-
logger.warning(
368-
"[gdot] unable to download %r to %r",
369-
GDotDirective._default_url,
370-
file_dest,
371-
)
372-
else:
373-
logger.info(
374-
"[gdot] download %r to %r", GDotDirective._default_url, file_dest
375-
)
333+
logger.info(
334+
"[gdot] download %r to %r", GDotDirective._default_url, file_dest
335+
)
376336

377337
# require.js
378338
file_dest = os.path.join(destf, "require.js")
379-
if os.path.exists(file_dest):
380-
logger.info("[gdot] %r already installed.", file_dest)
381-
else:
339+
if not os.path.exists(file_dest):
340+
logger.info("[gdot] download %r", file_dest)
382341
try:
383342
download_requirejs(destf)
384343
except Exception as e:
385344
logger.warning("[gdot] download_requirejs failed due to %r", e)
386345

387-
if os.path.exists(file_dest):
346+
if not os.path.exists(file_dest):
388347
# It adds <script async="defer" src="_static/require.js"></script>
389348
# at the bottom of the file. It needs to be at the beginning.
390349
# app.add_js_file("require.js", priority=200)
391-
logger.info("[gdot] %r installed.", file_dest)
392-
else:
393350
logger.warning("[gdot] %r not installed.", file_dest)
394351

395352

‎sphinx_runpython/runpython/sphinx_runpython_extension.py‎

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ def interpret(s):
372372

373373
try:
374374
out, err = run_cmd(cmd, script_arg, wait=True, change_path=chdir)
375-
return out, err, None
375+
return out, _filter_error(err), None
376376
except Exception as ee:
377377
if not exception:
378378
message = ( # noqa: UP030
@@ -383,7 +383,7 @@ def interpret(s):
383383
if exc_path:
384384
message += f"\n---EXC--\n{exc_path}"
385385
raise RunPythonExecutionError(message) from ee
386-
return str(ee), str(ee), None
386+
return str(ee), _filter_error(str(ee)), None
387387
else:
388388
if store_in_file:
389389
raise NotImplementedError(
@@ -446,7 +446,7 @@ def interpret(s):
446446
"\n{5}\n--TRACEBACK--\n{6}"
447447
).format(script, params, comment, gout, gerr, ee, excs)
448448
raise RunPythonExecutionError(message) from ee
449-
return (gout + "\n" + gerr), (gerr + "\n" + excs), None
449+
return (gout + "\n" + gerr), _filter_error(gerr + "\n" + excs), None
450450

451451
if chdir is not None:
452452
os.chdir(current)
@@ -462,7 +462,23 @@ def interpret(s):
462462
for k, v in globs.items()
463463
if k.startswith("__runpython__") and k not in avoid
464464
}
465-
return gout, gerr, context
465+
return gout, _filter_error(gerr), context
466+
467+
468+
def _filter_error(err):
469+
if not err:
470+
return err
471+
out = [
472+
"use_kernel_func_from_hub",
473+
"is deprecated, use",
474+
"was set in the config but",
475+
]
476+
if isinstance(err, str):
477+
res = "\n".join([_ for _ in err.split("\n") if all(o not in _ for o in out)])
478+
return res
479+
bout = [_.encode("utf-8") for _ in out]
480+
res = b"\n".join([_ for _ in err.split(b"\n") if all(o not in _ for o in bout)])
481+
return res
466482

467483

468484
class runpython_node(nodes.Structural, nodes.Element):

‎sphinx_runpython/sphinx_rst_builder.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1421,6 +1421,7 @@ def get_outfilename(self, pagename):
14211421
return f"{self.outdir}/{pagename}.rst".replace("\\", "/")
14221422

14231423
def write_doc(self, docname, doctree):
1424+
"""write documentation"""
14241425
destination = StringOutput(encoding="utf-8")
14251426
self.current_docname = docname
14261427
self.writer.write(doctree, destination)

0 commit comments

Comments
 (0)