Python

Sphinx - How to highlight text

From getting an odd error to understanding sphinx a bit better.

Table of Contents
  1. Some Context
  2. Back to the error

Error messages can be hard to read. Some errors are just impossible to understand. This is how I felt after getting a failure on CI for opsdroid docs.

The error message that I mean said Inline interpreted text or phrase reference start-string without end-string. and here is the error in all its glory!

python
1Warning, treated as error:
2 [108](https://github.com/opsdroid/opsdroid/runs/941790940#step:5:108)
3/home/runner/work/opsdroid/opsdroid/opsdroid/connector/twitch/__init__.py:docstring of opsdroid.connector.twitch.ConnectorTwitch.twitch_webhook_handler:7:Inline interpreted text or phrase reference start-string without end-string.

After reading through the error, it didn't make much sense. Perhaps, I forgot to close a sentence with a period?

Some Context

We migrated to Sphinx to generate our documentation.

The great thing about Sphinx is that you can use your docstrings to write your documentation, so you don't have to re-write the docs twice.

Opsdroid docstrings are pretty good; we aim to give a lot of information to make it easier for new contributors and new coders to understand the codebase faster.

Before Sphinx, we used to write the docstrings, then write the documentation in markdown. This means that we would repeat the process of writing the documentation. We spent too long on it.

My PR that adds a Twitch Connector to opsdroid uses the docstrings as the main documentation; I tried to highlight code like you would do in markdown - by using the ```.

Back to the error

After looking for the missing punctuation, everything seemed to be in order, but the docs kept failing.

Luckily another maintainer spotted the issue and shown me how to quickly fix the problem.

The problem was that in RST back-ticks (```) are (or can be) used as a reference. To highlight a piece of text, you need to use double back-ticks and finish off with an empty space.

So what you would normally do in markdown won't work in RST.

markdown
1This is my awesome `code`.

This code needs to be written like this instead:

markdown
1This is my awesome ``code`` .

As you can see, understanding the error is hard, and if you never worked with RST you will probably be as puzzled as me. Luckily, Cadair knew about it and helped me solve this issue!

After making the changes, CI passed and everything worked as expected.

I hope this helps you if you ever encounter this error or if you are trying to highlight a piece of text using Sphinx, but is not working.

Webmentions

0 Like 0 Comment

You might also like these

While working on adding tests to Pyscript I came across a use case where I had to check if an example image is always generated the same.

Read More
Python

How to compare two images using NumPy

How to compare two images using NumPy

How to return an attribute from a many-to-many object relationship from a Django Ninja API endpoint.

Read More
Python

Django Ninja Schemas and Many To Many

Django Ninja Schemas and Many To Many

Learn what additional permissions you need to add to your user to get django to run tests with a postgresql database.

Read More
Python

Fix django postgresql permissions denied on tests

Fix django postgresql permissions denied on tests

Python dataclasses are a powerful feature that allow you to refactor and write cleaner code. This introduction will help you get started with Python dataclasses.

Read More
Python

Clean Code with Python Dataclasses

Clean Code with Python Dataclasses