Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Suppress warnings for unfound references with default_role = "any" in Sphinx

I use any as the default role when for building my documentation with Sphinx, which works as intended by automatically linking some marked references and formatting the others as code while avoiding cluttering the docstrings with markup.

Unfortunately, when building the documentation this way, the output is cluttered with warnings for references for which any could not find a target:

WARNING: 'any' reference target not found: […]

Is there any way to suppress these warnings?

So far, the only resource I could find on this manner was this question, which is however specific about an entirely different warning.

like image 945
Wrzlprmft Avatar asked Sep 18 '25 23:09

Wrzlprmft


1 Answers

I filed a feature request for this, which was rejected but yielded a solution nontheless (thanks to Takeshi Komiya):

Add the following to conf.py:

def on_missing_reference(app, env, node, contnode):
    if node['reftype'] == 'any':
        return contnode
    else:
        return None

def setup(app):
    app.connect('missing-reference', on_missing_reference)
like image 98
Wrzlprmft Avatar answered Sep 21 '25 08:09

Wrzlprmft