Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOGS.rst
Original file line number Diff line number Diff line change
@@ -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
+++++

Expand Down
7 changes: 4 additions & 3 deletions _doc/api/epkg.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 5 additions & 8 deletions _doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/",
Expand Down
1 change: 1 addition & 0 deletions _doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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>`_
25 changes: 11 additions & 14 deletions _unittests/ut_epkg/test_epkg_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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):
Expand Down Expand Up @@ -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)

Expand All @@ -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):
Expand Down Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion sphinx_runpython/__init__.py
Original file line number Diff line number Diff line change
@@ -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/"
Expand Down
8 changes: 4 additions & 4 deletions sphinx_runpython/epkg/sphinx_epkg_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -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': (
Expand All @@ -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
)

Expand Down
3 changes: 1 addition & 2 deletions sphinx_runpython/ext_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/ <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")
Expand Down
10 changes: 5 additions & 5 deletions sphinx_runpython/process_rst.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/",
Expand Down
21 changes: 20 additions & 1 deletion sphinx_runpython/runpython/sphinx_runpython_extension.py
Original file line number Diff line number Diff line change
Expand Up @@ -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::

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"]),
Expand Down Expand Up @@ -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:
Expand Down
Loading