Skip to content

sphinx-build reports duplicated label #9707

Closed as not planned
Closed as not planned

Description

@gucio321

Describe the bug

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

Your project

https://github.com/gucio321/fizyka

Screenshots

No response

OS

linux - fedora 34

Python version

Python 3.9.7

Sphinx version

4.2.0

Sphinx extensions

extensions = [ "sphinx.ext.githubpages", "sphinxcontrib.images", "myst_parser", "cloud_sptheme.ext.issue_tracker" ]

Extra tools

No response

Additional context

No response

Activity

  1. tk0miya commented on Oct 6, 2021

    @tk0miya
    Member

    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.

  2. gucio321 commented on Oct 7, 2021

    @gucio321
    Author

    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?

  3. tk0miya commented on Oct 9, 2021

    @tk0miya
    Member

    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.

  4. gucio321 commented on Oct 9, 2021

    @gucio321
    Author
    1. 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
    1. 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?

  5. tk0miya commented on Oct 10, 2021

    @tk0miya
    Member

    And why Sphinx scans source files from the source directory.? Shouldn't it scan only the files included anyway?

    This is the current design of Sphinx. Indeed, it would be nice if improved. We'll welcome your contribution :-)

  6. added this to the some future version milestone on Sep 29, 2022
  7. jdillard commented on Aug 25, 2026

    @jdillard
    SponsorMember

    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.

  8. locked as resolved and limited conversation to collaborators on Sep 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions