Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicate label warning #14

Open
GlenNicholls opened this issue Mar 22, 2022 · 2 comments
Open

Duplicate label warning #14

GlenNicholls opened this issue Mar 22, 2022 · 2 comments

Comments

@GlenNicholls
Copy link

GlenNicholls commented Mar 22, 2022

I am running Sphinx 4.4.0 with sphinx-argparse 0.3.1 and I am seeing the following warning when using subparsers:

/.../api/cli.rst:3: WARNING: duplicate label positional arguments, other instance in /.../api/cli.rst
/.../api/cli.rst:3: WARNING: duplicate label named arguments, other instance in /.../api/cli.rst
/.../api/cli.rst:3: WARNING: duplicate label positional arguments, other instance in /.../api/cli.rst
/.../api/cli.rst:3: WARNING: duplicate label named arguments, other instance in /.../api/cli.rst

In my conf.py, I have enabled sphinx.ext.autosectionlabel for extensions. Here is a MWE of my test case:

import argparse
from pathlib import Path

def clean() -> None:
    pass

def run() -> None:
    pass

def get_argparser() -> argparse.ArgumentParser:
    cwd = Path.cwd().resolve()
    out_dir = cwd / "build"

    parent_parser = argparse.ArgumentParser(add_help=False)
    parent_parser.add_argument(
        "-v",
        "--verbose",
        action="store_true",
        default=False,
        help="Debug log level.",
    )

    parser = argparse.ArgumentParser(
        formatter_class=argparse.ArgumentDefaultsHelpFormatter,
    )
    subparsers = parser.add_subparsers(dest="subparser_name")

    parser.add_argument(
        "--version",
        action="version",
        version="1.0",
        help="Display the version.",
    )

    # Clean workspace parser
    parser_clean = subparsers.add_parser(
        "clean",
        help="Clean workspace and exit.",
        formatter_class=argparse.ArgumentDefaultsHelpFormatter,
    )
    parser_clean.add_argument(
        "path",
        nargs="*",
        default=out_dir,
        type=Path,
        help="Files and/or directories to permanently remove from the workspace.",
    )
    parser_clean.set_defaults(func=clean)

    # Run subparser
    parser_run = subparsers.add_parser(
        "run",
        parents=[parent_parser],
        help="Run.",
        formatter_class=argparse.ArgumentDefaultsHelpFormatter,
    )
    parser_run.add_argument(
        "--no-backup",
        action="store_true",
        default=False,
        help="Do not maintain timestamped artifacts.",
    )
    parser_run.set_defaults(func=run)

    return parser

I am looking at the docs and it states it handles duplicated header names by appending a number X to the anchor name, but it doesn't appear this is working correctly. Either that or the anchor is ignored because I am using sphinx.ext.autosectionlabel?

@GlenNicholls
Copy link
Author

I checked sphinx.ext.autosectionlabel docs and I can use autosectionlabel_prefix_document, but this isn't helpful as I would like to keep the argparse stuff in the same document.

@tdegeus
Copy link

tdegeus commented Feb 16, 2024

I'm getting the same warning. Is there any progress on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants