diff --git a/CHANGELOGS.rst b/CHANGELOGS.rst index 16c6741..6a8c824 100644 --- a/CHANGELOGS.rst +++ b/CHANGELOGS.rst @@ -1,6 +1,11 @@ Change Logs =========== +0.4.0 ++++++ + +* :pr:`39`: add option ``:debug:`` to runpython to append rst code to a page + 0.3.0 +++++ diff --git a/_doc/api/epkg.rst b/_doc/api/epkg.rst index f2996ba..7536479 100644 --- a/_doc/api/epkg.rst +++ b/_doc/api/epkg.rst @@ -19,9 +19,10 @@ In *conf.py*: ] epkg_dictionary = { - 'pandoc': 'http://johnmacfarlane.net/pandoc/', # 1 - 'pandas': ('http://pandas.pydata.org/pandas-docs/stable/', # 2 - ('http://pandas.pydata.org/pandas-docs/stable/generated/pandas.{0}.html', 1)), # 3 + 'pandoc': 'https://pandoc.org/', # 1 + 'pandas': ( + 'https://pandas.pydata.org/docs/', # 2 + ('https://pandas.pydata.org/docs/reference/api/pandas.{0}.html', 1)), # 3 } The variable ``epkg_dictionary`` stores the list of url to display. It can be a simple diff --git a/_doc/conf.py b/_doc/conf.py index ac33f9f..d64cbb1 100644 --- a/_doc/conf.py +++ b/_doc/conf.py @@ -123,15 +123,12 @@ ("https://docs.scipy.org/doc/numpy/reference/generated/numpy.{0}.{1}.html", 2), ), "pandas": ( - "https://pandas.pydata.org/pandas-docs/stable/", - ("https://pandas.pydata.org/pandas-docs/stable/generated/pandas.{0}.html", 1), - ( - "https://pandas.pydata.org/pandas-docs/stable/generated/pandas.{0}.{1}.html", - 2, - ), + "https://pandas.pydata.org/docs/reference/index.html", + ("https://pandas.pydata.org/docs/reference/api/pandas.{0}.html", 1), + ("https://pandas.pydata.org/docs/reference/api/pandas.{0}.{1}.html", 2), ), - "pandoc": "https://johnmacfarlane.net/pandoc/", - "Pandoc": "https://johnmacfarlane.net/pandoc/", + "pandoc": "https://pandoc.org/", + "Pandoc": "https://pandoc.org/", "PNG": "https://en.wikipedia.org/wiki/PNG", "pypandoc": "https://github.com/JessicaTegner/pypandoc", "python": "https://www.python.org/", diff --git a/_doc/index.rst b/_doc/index.rst index 0162425..b3b0ad9 100644 --- a/_doc/index.rst +++ b/_doc/index.rst @@ -54,6 +54,7 @@ Sources available on Older versions ++++++++++++++ +* `0.4.0 <../v0.4.0/index.html>`_ * `0.3.0 <../v0.3.0/index.html>`_ * `0.2.0 <../v0.2.0/index.html>`_ * `0.1.0 <../v0.1.0/index.html>`_ diff --git a/_unittests/ut_epkg/test_epkg_extension.py b/_unittests/ut_epkg/test_epkg_extension.py index d9e9185..31876a5 100644 --- a/_unittests/ut_epkg/test_epkg_extension.py +++ b/_unittests/ut_epkg/test_epkg_extension.py @@ -34,7 +34,7 @@ def test_epkg_module(self): if t1 not in html: raise AssertionError(html) - t1 = "https://pandas.pydata.org/pandas-docs/stable/" + t1 = "https://pandas.pydata.org/docs/" if t1 not in html: raise AssertionError(html) @@ -52,11 +52,8 @@ def test_epkg_module_twice(self): ) content = content.replace('u"', '"') - html = rst2html( - content, - writer_name="rst", - ) - self.assertIn("https://pandas.pydata.org/pandas-docs/stable/", html) + html = rst2html(content, writer_name="rst") + self.assertIn("https://pandas.pydata.org/docs/", html) @ignore_warnings(PendingDeprecationWarning) def test_epkg_sub(self): @@ -117,7 +114,9 @@ def pandas_link(input): if t1 in html: raise AssertionError(f"\n**{spl}**\n----\n{html}") - t1 = "https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.to_html.html" + t1 = ( + "https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.to_html.html" + ) if t1 not in html: raise AssertionError(html) @@ -143,13 +142,9 @@ def __call__(self, input): self.assertIn("abeforea", html) self.assertIn("aftera", html) - self.assertNotIn("`", html) - self.assertIn('https://johnmacfarlane.net/pandoc/"', html) - self.assertIn( - "https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.to_html.html", - html, - ) + self.assertIn('https://pandoc.org/"', html) + self.assertIn("https://pandas.pydata.org/docs/reference/api/pandas.", html) @ignore_warnings(PendingDeprecationWarning) def test_epkg_function_string(self): @@ -179,7 +174,9 @@ def test_epkg_function_string(self): if t1 in html: raise AssertionError(f"\n**{spl}**\n----\n{html}") - t1 = "https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.to_html.html" + t1 = ( + "https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.to_html.html" + ) if t1 not in html: raise AssertionError(html) diff --git a/sphinx_runpython/__init__.py b/sphinx_runpython/__init__.py index bc412c6..5280383 100644 --- a/sphinx_runpython/__init__.py +++ b/sphinx_runpython/__init__.py @@ -1,4 +1,4 @@ -__version__ = "0.3.0" +__version__ = "0.4.0" __author__ = "Xavier Dupré" __github__ = "https://github.com/sdpython/sphinx-runpython" __url__ = "https://sdpython.github.io/doc/sphinx-runpython/dev/" diff --git a/sphinx_runpython/epkg/sphinx_epkg_extension.py b/sphinx_runpython/epkg/sphinx_epkg_extension.py index b50bf93..ee29367 100644 --- a/sphinx_runpython/epkg/sphinx_epkg_extension.py +++ b/sphinx_runpython/epkg/sphinx_epkg_extension.py @@ -50,8 +50,8 @@ def epkg_role(role, rawtext, text, lineno, inliner, options=None, content=None): epkg_dictionary = { 'pandas': ( - 'http://pandas.pydata.org/pandas-docs/stable/generated/', - ('http://pandas.pydata.org/pandas-docs/stable/generated/{0}.html', 1) + 'https://pandas.pydata.org/docs/', + ('https://pandas.pydata.org/docs/reference/api/pandas.{0}.html', 1)), ), # 1 for one parameter '*py': ( @@ -72,8 +72,8 @@ def my_custom_links(input): epkg_dictionary = { 'weird_package': ( - 'http://pandas.pydata.org/pandas-docs/stable/generated/', - ('http://pandas.pydata.org/pandas-docs/stable/generated/{0}.html', 1), + 'https://pandas.pydata.org/docs/', + ('https://pandas.pydata.org/docs/reference/api/pandas.{0}.html', 1)), my_custom_links ) diff --git a/sphinx_runpython/ext_helper.py b/sphinx_runpython/ext_helper.py index a99327d..7b8f68f 100644 --- a/sphinx_runpython/ext_helper.py +++ b/sphinx_runpython/ext_helper.py @@ -144,8 +144,7 @@ def _get_data(url): Loads file ``objects.inv`` generated by extension :epkg:`sphinx.ext.intersphinx`. - :param url: url of documentation, example - `https://pandas.pydata.org/docs/ `_ + :param url: url of documentation, example ``https://pandas.pydata.org/docs/`` :return: instance of `InventoryFile` """ url_inv = urljoin(url, "objects.inv") diff --git a/sphinx_runpython/process_rst.py b/sphinx_runpython/process_rst.py index 84748c6..9c0dd03 100644 --- a/sphinx_runpython/process_rst.py +++ b/sphinx_runpython/process_rst.py @@ -44,15 +44,15 @@ ("https://docs.scipy.org/doc/numpy/reference/generated/numpy.{0}.{1}.html", 2), ), "pandas": ( - "https://pandas.pydata.org/pandas-docs/stable/", - ("https://pandas.pydata.org/pandas-docs/stable/generated/pandas.{0}.html", 1), + "https://pandas.pydata.org/docs/", + ("https://pandas.pydata.org/docs/reference/api/pandas.{0}.html", 1), ( - "https://pandas.pydata.org/pandas-docs/stable/generated/pandas.{0}.{1}.html", + "'https://pandas.pydata.org/docs/reference/api/pandas.{0}.{1}.html", 2, ), ), - "pandoc": "https://johnmacfarlane.net/pandoc/", - "Pandoc": "https://johnmacfarlane.net/pandoc/", + "pandoc": "https://pandoc.org/", + "Pandoc": "https://pandoc.org/", "PNG": "https://en.wikipedia.org/wiki/PNG", "pypandoc": "https://github.com/JessicaTegner/pypandoc", "python": "https://www.python.org/", diff --git a/sphinx_runpython/runpython/sphinx_runpython_extension.py b/sphinx_runpython/runpython/sphinx_runpython_extension.py index 6c7d162..1c16ec0 100644 --- a/sphinx_runpython/runpython/sphinx_runpython_extension.py +++ b/sphinx_runpython/runpython/sphinx_runpython_extension.py @@ -541,6 +541,8 @@ class RunPythonDirective(Directive): this trick is needed when the script to executes relies on function such :epkg:`*py:inspect:getsource` which requires the script to be stored somewhere in order to retrieve it. + * ``:debug:`` if ``:rst:`` is used, it shows some information to help + debugging. Option *rst* can be used the following way:: @@ -611,6 +613,7 @@ class RunPythonDirective(Directive): "numpy_precision": directives.unchanged, "store_in_file": directives.unchanged, "linenos": directives.unchanged, + "debug": directives.unchanged, } has_content = True runpython_class = runpython_node @@ -650,6 +653,7 @@ def run(self): "linenos": "linenos" in self.options, "showout": "showout" in self.options, "rst": "rst" in self.options, + "debug": "debug" in self.options, "sin": self.options.get("sin", TITLES[language_code]["In"]), "sout": self.options.get("sout", TITLES[language_code]["Out"]), "sout2": self.options.get("sout2", TITLES[language_code]["Out2"]), @@ -897,9 +901,24 @@ def add_indent(content, nbind): elif len(p["sout"]) > 0: secout += nodes.paragraph(text=p["sout"]) + content_rows = content.replace("\r", "").split("\n") + + if p["debug"]: + full_content = "\n".join( + f" {i+1:05d}: {row}" for i, row in enumerate(content_rows) + ) + content_rows.extend(["", f"*n_rows: {len(content_rows)}*"]) + for i, row in enumerate(content_rows): + if set(row) in ({"+"}, {"="}, {"-"}): + title = content_rows[i - 1] + content_rows.append(f"* *{i}:{title}*") + content_rows.extend( + ["", "", ".. code-block:: text", "", full_content, ""] + ) + try: if p["sphinx"]: - st = StringList(content.replace("\r", "").split("\n")) + st = StringList(content_rows) nested_parse_with_titles(self.state, st, secout) dt = None else: