You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm getting the following warnings in my project :
/home/user/git/fizyka/assets/dzial_1/temat_3/intro.rst:34: WARNING: duplicate label of equation V, other instance in assets/dzial_1/index
How to Reproduce
$ git clone https://github.com/gucio321/fizyka && cd fizyka
$ pip install -r requirements.txt
$ make html
you'll see warnings
Expected behavior
warning about duplicated label shouldn't appear because the label isn't duplicated
The label V is defined at assets/dzial_1/temat_3/intro.rst. It's appeared twice in your project because assets/dzial_1/index.rst includes the file. In other words, both assets/dzial_1/index.rst and assets/dzial_1/temat_3/intro.rst have the same label. It's correct behavior.
hmm, but intor.rst is only used in index.rst so this label isn't duplicated in fact. the intro.rst isn't used in any other way and I'd expect file is not included anywhere warning for it.
Why does sphinx consider it otherway than from assets/dzial_1/index.rst?
Sphinx scans source files from the source directory. So intro.rst is also processed because it has .rst extension. As a result, the label is defined twice. To avoid this behavior, please consider 1) renaming the file to other extensions (like .txt), or 2) setting exclude_patterns up in your conf.py.
renaming the file to other extensions (like .txt),
I don't think it is good solution because:
rst syntax will not work anymore
it is after all rst file, so it should have rst extension
setting exclude_patterns up in your conf.py
it may work but it will be a bit annoing to add a new path each time i'm adding a new chapter/topic
I cannot even understand why it isn't a bug.
is including another rst files non-standard solution?
And why Sphinx scans source files from the source directory.? Shouldn't it scan only the files included anyway?
Reacted by Burlen Loring, red8888, Lukas Mayrhofer, Lukas Heumos, electric-coder and Daniela Remenska
Sphinx treats every file matching source_suffix as a standalone document. When such a file is also used with .. include::, its labels are registered both independently and in the including document. Sphinx cannot safely infer that an included file is only a fragment, because files may intentionally be both standalone documents and included content.
For reusable fragments, exclude them from source discovery with a glob:
exclude_patterns= ["_includes/**"]
Alternatively, use a suffix not listed in source_suffix, such as .inc or .rst.inc. Included content is still parsed as reStructuredText regardless of its filename extension. Syntax highlighters usually let you configure extension aliases.
Since the existing configuration supports this use case and automatic detection would be ambiguous, I am closing this as not planned.
edit: I made a docs PR, #14649, to give tips on how to avoid common issues if you want to give it a review.
Activity
tk0miya commentedon Oct 6, 2021
The label
Vis defined atassets/dzial_1/temat_3/intro.rst. It's appeared twice in your project becauseassets/dzial_1/index.rstincludes the file. In other words, bothassets/dzial_1/index.rstandassets/dzial_1/temat_3/intro.rsthave the same label. It's correct behavior.gucio321 commentedon Oct 7, 2021
hmm, but
intor.rstis only used inindex.rstso this label isn't duplicated in fact. theintro.rstisn't used in any other way and I'd expectfile is not included anywherewarning for it.Why does sphinx consider it otherway than from
assets/dzial_1/index.rst?tk0miya commentedon Oct 9, 2021
Sphinx scans source files from the source directory. So
intro.rstis also processed because it has.rstextension. As a result, the label is defined twice. To avoid this behavior, please consider 1) renaming the file to other extensions (like.txt), or 2) settingexclude_patternsup in your conf.py.gucio321 commentedon Oct 9, 2021
I don't think it is good solution because:
it may work but it will be a bit annoing to add a new path each time i'm adding a new chapter/topic
I cannot even understand why it isn't a bug.
is including another
rstfiles non-standard solution?And why
Sphinx scans source files from the source directory.? Shouldn't it scan only the files included anyway?tk0miya commentedon Oct 10, 2021
This is the current design of Sphinx. Indeed, it would be nice if improved. We'll welcome your contribution :-)
docs: fix macOS sphinx doc issue with duplicate IDs
doc/sphinx/hxtool.py: add optional label argument to SRST directive
doc/sphinx/hxtool.py: add optional label argument to SRST directive
doc/sphinx/hxtool.py: add optional label argument to SRST directive
jdillard commentedon Aug 25, 2026
Sphinx treats every file matching
source_suffixas a standalone document. When such a file is also used with.. include::, its labels are registered both independently and in the including document. Sphinx cannot safely infer that an included file is only a fragment, because files may intentionally be both standalone documents and included content.For reusable fragments, exclude them from source discovery with a glob:
Alternatively, use a suffix not listed in
source_suffix, such as.incor.rst.inc. Included content is still parsed as reStructuredText regardless of its filename extension. Syntax highlighters usually let you configure extension aliases.Since the existing configuration supports this use case and automatic detection would be ambiguous, I am closing this as not planned.
edit: I made a docs PR, #14649, to give tips on how to avoid common issues if you want to give it a review.