click-contrib / sphinx-click

A Sphinx plugin to automatically document click-based applications
MIT License
212 stars 57 forks source link

Click sub-command name renaming not detected #74

Open Querela opened 3 years ago

Querela commented 3 years ago

Hi, I'm using the most current version of Sphinx (3.4.2), Sphinx-Click (latest) and click (7.1.2).

My situation is like this:

Not sure if the example code can reproduce this or if it has to be separate packages (not just modules)...

# packageA modA.cli

import click

@click.group()
def main():
    pass

@main.group()
def subA():
    pass
# packageB modB.cli

import click
from modA.cli import main as submain

@click.group()
def main():
    pass

main.add_command(submain, "submain")  # <-- here I add the commandgroup from packageB and rename the command
# without renaming here, it will show up as `main` in the CLI

@main.group()
def subB():
    pass

I will then call the modB.cli:main() entry point.

Documentation is dead simple:

.. click:: modB.cli:main
  :prog: packageB
  :nested: full
stephenfin commented 3 years ago

Yeah, this isn't something we currently support. I'm not sure how easy it would be to fix this since we don't fully evaluate the application.

Querela commented 3 years ago

Ok. That makes sense and it guards against some side effects. Is it possible to manually rename the command in the docs? (Also complicated probably because of any possible depth.)

stephenfin commented 3 years ago

Unfortunately not, no

Querela commented 3 years ago

Hmm. It's an internal project. And documentation is currently not done automatically. So maybe just manual postprocessing to update the 5-6 occurrences where it is wrong. Or just a notice somewhere. I can't think of any easy solution/fix for now ...

kaczmarj commented 1 year ago

the renamed names are lost in these lines: https://github.com/click-contrib/sphinx-click/blob/aa0d5b7bcda183d20c7b98a9a1c9acf1e003af97/sphinx_click/ext.py#L285-L288

prior to those lines, for a click.Group, lookup is a dictionary that maps the new names to the click.Command objects. those lines return a list that strips away the new names. perhaps the lookup can be maintained, and the commands can be ordered alphabetically using a OrderedDict (or a list of tuples).

this issue is preventing me from using sphinx-click to document my application.

stephenfin commented 1 year ago

I'd welcome a pull request to fix this. Please include tests