autosectionlabel: add type for suppress_warnings

This sets the subtype to the filename, which means that you can suppress
warnings for individual paths.

For example for the following warning:

```
path/to/file.rst:5547: WARNING: duplicate label path/to/file:label, other instance in /path/to/file.rst
```

You would add this to `config.py` to suppress all warnings:

```python
extensions = [
    'sphinx.ext.autosectionlabel',
]

autosectionlabel_prefix_document = True

suppress_warnings = [
    'autosectionlabel.*',
]
```

To suppress warnings for the individual file path you would do:

```python
suppress_warnings = [
    'autosectionlabel.path/to/file',
]
```

Fixes: https://github.com/sphinx-doc/sphinx/issues/6371
This commit is contained in:
Gibson Fahnestock 2019-05-15 14:32:24 +01:00
parent c81ae00430
commit 6f7cb4da94
No known key found for this signature in database
GPG Key ID: B01FBB92821C587A
3 changed files with 26 additions and 20 deletions

View File

@ -99,6 +99,7 @@ Features added
* #6306: html: Add a label to search form for accessability purposes * #6306: html: Add a label to search form for accessability purposes
* #6358: The ``rawsource`` property of ``production`` nodes now contains the * #6358: The ``rawsource`` property of ``production`` nodes now contains the
full production rule full production rule
* #6373: Allow suppression of autosectionlabel warnings
Bugs fixed Bugs fixed
---------- ----------

View File

@ -296,25 +296,26 @@ General configuration
Sphinx supports following warning types: Sphinx supports following warning types:
* app.add_node * ``app.add_node``
* app.add_directive * ``app.add_directive``
* app.add_role * ``app.add_role``
* app.add_generic_role * ``app.add_generic_role``
* app.add_source_parser * ``app.add_source_parser``
* download.not_readable * ``download.not_readable``
* image.not_readable * ``image.not_readable``
* ref.term * ``ref.term``
* ref.ref * ``ref.ref``
* ref.numref * ``ref.numref``
* ref.keyword * ``ref.keyword``
* ref.option * ``ref.option``
* ref.citation * ``ref.citation``
* ref.footnote * ``ref.footnote``
* ref.doc * ``ref.doc``
* ref.python * ``ref.python``
* misc.highlighting_failure * ``misc.highlighting_failure``
* toc.secnum * ``toc.secnum``
* epub.unknown_project_files * ``epub.unknown_project_files``
* ``autosectionlabel.*``
You can choose from these types. You can choose from these types.
@ -334,6 +335,10 @@ General configuration
Added ``ref.footnote`` Added ``ref.footnote``
.. versionchanged:: 2.1
Added ``autosectionlabel.*``
.. confval:: needs_sphinx .. confval:: needs_sphinx
If set to a ``major.minor`` version string like ``'1.1'``, Sphinx will If set to a ``major.minor`` version string like ``'1.1'``, Sphinx will

View File

@ -55,7 +55,7 @@ def register_sections_as_label(app, document):
if name in labels: if name in labels:
logger.warning(__('duplicate label %s, other instance in %s'), logger.warning(__('duplicate label %s, other instance in %s'),
name, app.env.doc2path(labels[name][0]), name, app.env.doc2path(labels[name][0]),
location=node) location=node, type='autosectionlabel', subtype=docname)
anonlabels[name] = docname, labelid anonlabels[name] = docname, labelid
labels[name] = docname, labelid, sectname labels[name] = docname, labelid, sectname