Deindent Block in Sphinx literalinclude Directive - python-sphinx

I have a block of code in a file that I want to include in an example in Sphinx documentation, using a literalinclude directive.
But that code is in a function, so when I include it, in the example each line is indented by one level more than I'd like.
.. literalinclude:: ../../examples/example.py
:language: python
:lines: 13-42
:tab-width: 0
Produces
import foo
from foo import bar
print("I'm indented too far")
Is there any other way to remove or deindent the literal block?

literalinclude has a dedent option:
.. literalinclude:: ../../examples/example.py
:language: python
:lines: 13-42
:tab-width: 0
:dedent: 4
The option is mentioned under "Additional options" in the literalinclude documentation, but the details are in the documentation for code-block.

Related

cross referencing to doxygenfunction from sphinx

I have a problem with C++ domain. In my index.rst I have
:cpp:func:`Hello()`
In hallo.rst I have the following lines:
.. cpp:function:: Hello
.. doxygenfunction:: Hello
The line with doxygenfunction works and I get the documentation generated for my function.
But the line with cpp:function doesn't work. Instead, I'm trying to generate a link for the Hello() function in the documentation.
I generated my C++ documentation with Sphinx, Doxygen and Breathe.
I don't know if I got your Question right. In the documentation of Breathe it is listed how to link a function.
doxygenfunction
This directive generates the appropriate output for a single function. The function name is required to be unique in the project.
.. doxygenfunction:: <function name>
:project: ...
:path: ...
:outline:
:no-link:
Check out: https://breathe.readthedocs.io/en/latest/directives.html#doxygenfunction
There is also an example page on how to link a single function: https://breathe.readthedocs.io/en/latest/function.html#function-example

How do I get Sphinx code blocks working as tabs?

I have tried the extension sphinx-tabs. I use Python 3.8 and the latest Sphinx ver.
I install with pip and add to conf.py but my code is never displayed properly.
In conf.py I have this:
extensions = ['sphinx_tabs.tabs']
My code is simple:
.. tabs::
.. tab:: tab1
Content for tab one
.. tab:: tab2
Content for tab two
This just produces the text:
tab1
tab2
Both appear to be hyperlinks but do not actually link anywhere.
Two things that are different between your code and mine:
I found I needed extra lines everywhere, and
for code especially, the code-block tag is great! (otherwise just go with tab).
.. tabs::
.. code-tab:: cpp
auto hello = someCPlusPlusFunction();
.. code-tab:: python
howdy = some_python_function()

Is There a tutorial how to suppress Pylint warnings for Squish?

I am trying to suppress Pylint warnings from Squish, but not have same code written in front of the code like is described here: https://kb.froglogic.com/display/KB/Example+-+Using+PyLint+with+Squish+test+scripts+that+use+source%28%29
I would like to know if is a file that I can configure and uploaded into Squish
The article describes the only option, to define the Squish functions and symbols yourself.
However, it is showing what to do in a single file Squish test script file only for sake of simplicity.
You should of course put those Squish function definitions in a separate, re-usable file, and use import to "load" the definitions into your test.py file:
from squish_definitions import *
def main():
...
in squish_definitions.py:
# Trick Pylint and Python IDEs into accepting the
# definitions in this block, whereas upon execution
# none of these definitions will take place:
if -0:
class ApplicationContext:
pass
def startApplication(aut_path_or_name, optional_squishserver_host, optional_squishserver_port):
return ApplicationContext
# etc.
Also, you should generally switch over to using Python's import in favor of Squish's source() function.

How do I use both, :start-after: and :lines:, with literalinclude?

I am trying to use Sphinx’s literalinclude with a code example and want to use both start-after and lines. However, all I am getting is an empty line. Is this a bug? If not, how do I it correctly?
Minimal non-working example
index.rst, the main documentation file:
Behold this example code:
.. literalinclude:: example.py
:start-after: blobfish
:lines: 1
example.py, the example to be included:
# blobfish
this = line is an_example
this = line is another_example
conf.py, because Sphinx needs one:
source_suffix = '.rst'
master_doc = 'index'
I compile by calling sphinx-build . out in the folder containing the above files. There is no error message.
In the output, I want to see the introductory sentence followed by this = line is an_example. However, instead of the latter I only get an empty line. If I change :lines: to :emphasize-lines:, everything is working as expected: The line in question is highlighted and the other line is printed additionally.

How to include external file as Sphinx documentation similar to a code block?

How to include external file as Sphinx documentation similar to a code block?
And how can I make it style the syntax color?
Found it here: http://sphinx-doc.org/markup/code.html
.. literalinclude :: <path/to/file>
:language: <file_language>

Resources