8

In Sphinx I get a ton of warnings like:

/PATH/FILENAME:LINE: WARNING: duplicate label LABELNAME, other instance in /PATH/FILENAME

It seems to see all section titles as "label"s and there is a bunch of section titles that are used in multiple files. For example we have a one page per release note per version, and in every version there is "Improvements" and "Fixes".

How would one get rid of all of these warnings? Should they just be silenced, or is there a different way for sectioning that you are supposed to use?

One example is the label "gamepad" in desktop.rst and vr-controls.rst

For reference, we still use Sphinx 2.4.4 I haven't seen anything in the changelogs that seemed related.

mzjn
  • 48,958
  • 13
  • 128
  • 248
Julian G
  • 93
  • 1
  • 6
  • Please edit your question to include an example of the reST that cause these warnings. I cannot replicate this issue in Pyramid's docs [Change History](https://docs.pylonsproject.org/projects/pyramid/en/latest/index.html#change-history). – Steve Piercy Jun 29 '20 at 05:26
  • @StevePiercy we actually use a mixture of rst and commonMarkup. I added an example to the question that happens to two rst files. The same issue happens with commonMarkup files as well though. – Julian G Jun 29 '20 at 07:08
  • With Sphinx 2.3.1, I tried adding your two pages to a single-file docs, and it built just fine (except for missing images and `unknown document: ../interact`, of course). However, when I cloned your repo and tried to build the docs, I saw the warnings. First I changed the `conf.py` for Sphinx 1.4+ per https://recommonmark.readthedocs.io/en/latest/. Other than that, I have no idea because I don't use recommonmark. I imagine the issue is the usage of both .rst and .md, instead of just one syntax. I'd suggest choose one. – Steve Piercy Jun 29 '20 at 10:33
  • @StevePiercy fixing the conf.py according to recommonmark docs actually fixed the problem completely. Thank you very much! I don't think I would have ever found that out myself. – Julian G Jun 29 '20 at 17:13
  • 1
    I see the same warning because of the same issue in a project that does not use recommonmark :-( – MarcH Dec 05 '20 at 01:56

3 Answers3

3

As recommonmark is deprecated, use myst-parser instead:

pip install --upgrade myst-parser

# and inside conf.py:
extensions = ['myst_parser', ...]

Though with that setup, I still had the same duplicate label warnings. Turns out I had to remove 'sphinx.ext.autosectionlabel' from my extensions list to resolve the problem.

Abdull
  • 26,371
  • 26
  • 130
  • 172
  • Thank you, removing that extension 'sphinx.ext.autosectionlabel' helps me too. I guess it creates HTML anchors based on the title names. When they are the same on a page, it turns warnings. – Albert May 12 '22 at 14:15
  • Actually, even before that, it creates anchors for the internal :ref: links. – Albert May 12 '22 at 14:53
1

The issue was us still using a deprecated conf.py option for recommonmark. We were still using the option for Sphinx-1.3 and earlier as per recommonmark.readthedocs.io/en/latest/ Changing

from recommonmark.parser import CommonMarkParser

source_parsers = {
    '.md': CommonMarkParser,
}

source_suffix = ['.rst', '.md']

to

extensions = ['recommonmark']

fixed the issue.

Big thanks to @StevePiercy for making me aware of our deprecated config.

Julian G
  • 93
  • 1
  • 6
1

It looks like the sphinx parser parses every .rst file in the folder to create a HTML. When some of these .rst files are included in the main.rst it looks like we are getting this duplicate label messages. To help the parser from not parsing these includes you can try changing the extension from .rst to something else like .rest and then these messages are gone. Make sure that the include now includes the files with the new file extension like .rest as called out before