Skip to content

Commit f64355c

Browse files
authored
Add option debug to runpython (#39)
* Add option debug to runpython * readme * version * links * update it
1 parent eb0f880 commit f64355c

10 files changed

Lines changed: 57 additions & 38 deletions

File tree

‎CHANGELOGS.rst‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
Change Logs
22
===========
33

4+
0.4.0
5+
+++++
6+
7+
* :pr:`39`: add option ``:debug:`` to runpython to append rst code to a page
8+
49
0.3.0
510
+++++
611

‎_doc/api/epkg.rst‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ In *conf.py*:
1919
]
2020

2121
epkg_dictionary = {
22-
'pandoc': 'http://johnmacfarlane.net/pandoc/', # 1
23-
'pandas': ('http://pandas.pydata.org/pandas-docs/stable/', # 2
24-
('http://pandas.pydata.org/pandas-docs/stable/generated/pandas.{0}.html', 1)), # 3
22+
'pandoc': 'https://pandoc.org/', # 1
23+
'pandas': (
24+
'https://pandas.pydata.org/docs/', # 2
25+
('https://pandas.pydata.org/docs/reference/api/pandas.{0}.html', 1)), # 3
2526
}
2627

2728
The variable ``epkg_dictionary`` stores the list of url to display. It can be a simple

‎_doc/conf.py‎

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -123,15 +123,12 @@
123123
("https://docs.scipy.org/doc/numpy/reference/generated/numpy.{0}.{1}.html", 2),
124124
),
125125
"pandas": (
126-
"https://pandas.pydata.org/pandas-docs/stable/",
127-
("https://pandas.pydata.org/pandas-docs/stable/generated/pandas.{0}.html", 1),
128-
(
129-
"https://pandas.pydata.org/pandas-docs/stable/generated/pandas.{0}.{1}.html",
130-
2,
131-
),
126+
"https://pandas.pydata.org/docs/reference/index.html",
127+
("https://pandas.pydata.org/docs/reference/api/pandas.{0}.html", 1),
128+
("https://pandas.pydata.org/docs/reference/api/pandas.{0}.{1}.html", 2),
132129
),
133-
"pandoc": "https://johnmacfarlane.net/pandoc/",
134-
"Pandoc": "https://johnmacfarlane.net/pandoc/",
130+
"pandoc": "https://pandoc.org/",
131+
"Pandoc": "https://pandoc.org/",
135132
"PNG": "https://en.wikipedia.org/wiki/PNG",
136133
"pypandoc": "https://github.com/JessicaTegner/pypandoc",
137134
"python": "https://www.python.org/",

‎_doc/index.rst‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ Sources available on
5454
Older versions
5555
++++++++++++++
5656

57+
* `0.4.0 <../v0.4.0/index.html>`_
5758
* `0.3.0 <../v0.3.0/index.html>`_
5859
* `0.2.0 <../v0.2.0/index.html>`_
5960
* `0.1.0 <../v0.1.0/index.html>`_

‎_unittests/ut_epkg/test_epkg_extension.py‎

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def test_epkg_module(self):
3434
if t1 not in html:
3535
raise AssertionError(html)
3636

37-
t1 = "https://pandas.pydata.org/pandas-docs/stable/"
37+
t1 = "https://pandas.pydata.org/docs/"
3838
if t1 not in html:
3939
raise AssertionError(html)
4040

@@ -52,11 +52,8 @@ def test_epkg_module_twice(self):
5252
)
5353
content = content.replace('u"', '"')
5454

55-
html = rst2html(
56-
content,
57-
writer_name="rst",
58-
)
59-
self.assertIn("https://pandas.pydata.org/pandas-docs/stable/", html)
55+
html = rst2html(content, writer_name="rst")
56+
self.assertIn("https://pandas.pydata.org/docs/", html)
6057

6158
@ignore_warnings(PendingDeprecationWarning)
6259
def test_epkg_sub(self):
@@ -117,7 +114,9 @@ def pandas_link(input):
117114
if t1 in html:
118115
raise AssertionError(f"\n**{spl}**\n----\n{html}")
119116

120-
t1 = "https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.to_html.html"
117+
t1 = (
118+
"https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.to_html.html"
119+
)
121120
if t1 not in html:
122121
raise AssertionError(html)
123122

@@ -143,13 +142,9 @@ def __call__(self, input):
143142

144143
self.assertIn("abeforea", html)
145144
self.assertIn("aftera", html)
146-
147145
self.assertNotIn("`", html)
148-
self.assertIn('https://johnmacfarlane.net/pandoc/"', html)
149-
self.assertIn(
150-
"https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.to_html.html",
151-
html,
152-
)
146+
self.assertIn('https://pandoc.org/"', html)
147+
self.assertIn("https://pandas.pydata.org/docs/reference/api/pandas.", html)
153148

154149
@ignore_warnings(PendingDeprecationWarning)
155150
def test_epkg_function_string(self):
@@ -179,7 +174,9 @@ def test_epkg_function_string(self):
179174
if t1 in html:
180175
raise AssertionError(f"\n**{spl}**\n----\n{html}")
181176

182-
t1 = "https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.to_html.html"
177+
t1 = (
178+
"https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.to_html.html"
179+
)
183180
if t1 not in html:
184181
raise AssertionError(html)
185182

‎sphinx_runpython/__init__.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = "0.3.0"
1+
__version__ = "0.4.0"
22
__author__ = "Xavier Dupré"
33
__github__ = "https://github.com/sdpython/sphinx-runpython"
44
__url__ = "https://sdpython.github.io/doc/sphinx-runpython/dev/"

‎sphinx_runpython/epkg/sphinx_epkg_extension.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ def epkg_role(role, rawtext, text, lineno, inliner, options=None, content=None):
5050
5151
epkg_dictionary = {
5252
'pandas': (
53-
'http://pandas.pydata.org/pandas-docs/stable/generated/',
54-
('http://pandas.pydata.org/pandas-docs/stable/generated/{0}.html', 1)
53+
'https://pandas.pydata.org/docs/',
54+
('https://pandas.pydata.org/docs/reference/api/pandas.{0}.html', 1)),
5555
),
5656
# 1 for one parameter
5757
'*py': (
@@ -72,8 +72,8 @@ def my_custom_links(input):
7272
7373
epkg_dictionary = {
7474
'weird_package': (
75-
'http://pandas.pydata.org/pandas-docs/stable/generated/',
76-
('http://pandas.pydata.org/pandas-docs/stable/generated/{0}.html', 1),
75+
'https://pandas.pydata.org/docs/',
76+
('https://pandas.pydata.org/docs/reference/api/pandas.{0}.html', 1)),
7777
my_custom_links
7878
)
7979

‎sphinx_runpython/ext_helper.py‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,7 @@ def _get_data(url):
144144
Loads file ``objects.inv`` generated by
145145
extension :epkg:`sphinx.ext.intersphinx`.
146146
147-
:param url: url of documentation, example
148-
`https://pandas.pydata.org/docs/ <https://pandas.pydata.org/docs/>`_
147+
:param url: url of documentation, example ``https://pandas.pydata.org/docs/``
149148
:return: instance of `InventoryFile`
150149
"""
151150
url_inv = urljoin(url, "objects.inv")

‎sphinx_runpython/process_rst.py‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@
4444
("https://docs.scipy.org/doc/numpy/reference/generated/numpy.{0}.{1}.html", 2),
4545
),
4646
"pandas": (
47-
"https://pandas.pydata.org/pandas-docs/stable/",
48-
("https://pandas.pydata.org/pandas-docs/stable/generated/pandas.{0}.html", 1),
47+
"https://pandas.pydata.org/docs/",
48+
("https://pandas.pydata.org/docs/reference/api/pandas.{0}.html", 1),
4949
(
50-
"https://pandas.pydata.org/pandas-docs/stable/generated/pandas.{0}.{1}.html",
50+
"'https://pandas.pydata.org/docs/reference/api/pandas.{0}.{1}.html",
5151
2,
5252
),
5353
),
54-
"pandoc": "https://johnmacfarlane.net/pandoc/",
55-
"Pandoc": "https://johnmacfarlane.net/pandoc/",
54+
"pandoc": "https://pandoc.org/",
55+
"Pandoc": "https://pandoc.org/",
5656
"PNG": "https://en.wikipedia.org/wiki/PNG",
5757
"pypandoc": "https://github.com/JessicaTegner/pypandoc",
5858
"python": "https://www.python.org/",

‎sphinx_runpython/runpython/sphinx_runpython_extension.py‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,8 @@ class RunPythonDirective(Directive):
541541
this trick is needed when the script to executes relies on
542542
function such :epkg:`*py:inspect:getsource` which requires
543543
the script to be stored somewhere in order to retrieve it.
544+
* ``:debug:`` if ``:rst:`` is used, it shows some information to help
545+
debugging.
544546
545547
Option *rst* can be used the following way::
546548
@@ -611,6 +613,7 @@ class RunPythonDirective(Directive):
611613
"numpy_precision": directives.unchanged,
612614
"store_in_file": directives.unchanged,
613615
"linenos": directives.unchanged,
616+
"debug": directives.unchanged,
614617
}
615618
has_content = True
616619
runpython_class = runpython_node
@@ -650,6 +653,7 @@ def run(self):
650653
"linenos": "linenos" in self.options,
651654
"showout": "showout" in self.options,
652655
"rst": "rst" in self.options,
656+
"debug": "debug" in self.options,
653657
"sin": self.options.get("sin", TITLES[language_code]["In"]),
654658
"sout": self.options.get("sout", TITLES[language_code]["Out"]),
655659
"sout2": self.options.get("sout2", TITLES[language_code]["Out2"]),
@@ -897,9 +901,24 @@ def add_indent(content, nbind):
897901
elif len(p["sout"]) > 0:
898902
secout += nodes.paragraph(text=p["sout"])
899903

904+
content_rows = content.replace("\r", "").split("\n")
905+
906+
if p["debug"]:
907+
full_content = "\n".join(
908+
f" {i+1:05d}: {row}" for i, row in enumerate(content_rows)
909+
)
910+
content_rows.extend(["", f"*n_rows: {len(content_rows)}*"])
911+
for i, row in enumerate(content_rows):
912+
if set(row) in ({"+"}, {"="}, {"-"}):
913+
title = content_rows[i - 1]
914+
content_rows.append(f"* *{i}:{title}*")
915+
content_rows.extend(
916+
["", "", ".. code-block:: text", "", full_content, ""]
917+
)
918+
900919
try:
901920
if p["sphinx"]:
902-
st = StringList(content.replace("\r", "").split("\n"))
921+
st = StringList(content_rows)
903922
nested_parse_with_titles(self.state, st, secout)
904923
dt = None
905924
else:

0 commit comments

Comments
 (0)