Eli S Eli S - 5 months ago 42
Python Question

linking to source code file in sphinx

I am documenting a python module in Sphinx. I have a source code file full of examples of the use of my module. I'd like to reference this file. It is too long to inline as continuous code. Is there a way to create a link to the full source file, formatted in a code-friendly way (ie literal or with line numbers)?



Python 3 does this. For example, the argparse docs link to the source code (near the top of the page, where it says "Source code"). You can see how they do it by looking at the source for the docs (linked from the first link, down at the bottom of the left had column).

I assume they're using standard Sphinx, but I am having a hard time finding :source: in their docs...

Update - see mzjn's comment - it's defined here.