question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Inputing also ".rst" files

See original GitHub issue

If we ever want to also input “.rst” files, it’s really easy to read them in, and convert them to .py files.

I just came across some code lying on my disk since a while (probably copy-pasted from Internet):

from docutils.core import publish_doctree

doctree = publish_doctree(open('input.rst').read())

def is_code_block(node):
    return (node.tagname == 'literal_block')

code_blocks = doctree.traverse(condition=is_code_block)
source_code = [block.astext() for block in code_blocks]

with open('output.py', 'w') as f:
    f.write('\n######################\n\n'.join(source_code[2:]))

So we should keep in mind that it’s probably a low cost feature that might make users happy.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
larsonercommented, Jun 30, 2020

Yes we already do it – I’m saying that this might be a problem / conflict if we implement a “run all RST” feature

0reactions
bdicecommented, Nov 1, 2020

@larsoner Excellent response! This helped explain a lot of the parts that I didn’t know. I am interested in pursuing this concept further, especially if there is interest from other sphinx-gallery users. I’m probably going to work on enabling sphinx-gallery for a project first, so I can get more familiar with its usage and features.

@lucyleeow Good question. I use standard Sphinx-style, NumPy-style, and Google-style docstrings in different projects, so I would want to support all of them, but I think that should be possible. I would guess that there’s a layer/stage of the process at which all example code snippets are handled the same way and could be detected/executed without needing to specialize for different formats/tools, but I am not super familiar with the internals of these packages.

Read more comments on GitHub >

github_iconTop Results From Across the Web

13. Example .rst File — EdX Style Guide documentation
This file contains examples of .rst formatting. ... grading problems (also called *custom JavaScript problems* or *JS input problems*) allow you to create...
Read more >
Quick reStructuredText - Docutils
Inline Markup. Inline markup allows words and phrases within text to have character styles (like italics and boldface) and functionality (like hyperlinks). ...
Read more >
Sphinx and RST syntax guide (0.9.3) - Thomas-Cokelaer.info
This page describes some of the RST and Sphinx syntax. It is based on resource found at Sphinx ... What are directives; Inserting...
Read more >
RST File Format- reStructuredText File
It is a text file written in the reStructuredText markup language that applies styles and formatting to plain text documents for generation of...
Read more >
reStructuredText Primer - Sphinx documentation
It is also possible to replace or expand upon some of this inline markup with roles. ... For example, the file sketch/spam.rst could...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found