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

Click sub-command name renaming not detected #74

Open
Querela opened this issue Jan 13, 2021 · 6 comments
Open

Click sub-command name renaming not detected #74

Querela opened this issue Jan 13, 2021 · 6 comments

Comments

@Querela
Copy link

Querela commented Jan 13, 2021

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:

  • I have a separate package with a click cli, which has a group named main (module modA.cli in package packageA)
  • in another package (module modB.cli in package packageB) I also have a CLI and import the group main from modA.cli as submain
  • I add the submain group to the modB.cli command groups as a subcommand.
    If I now execute packageB I will see the subcommand submain as possible choice. In the generated documentation it however will still appear as main (name from modA.cli I would suppose)

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
Copy link
Member

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
Copy link
Author

Querela commented Jan 14, 2021

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
Copy link
Member

Unfortunately not, no

@Querela
Copy link
Author

Querela commented Jan 15, 2021

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
Copy link

kaczmarj commented Jan 20, 2023

the renamed names are lost in these lines:

if commands is None:
return sorted(lookup.values(), key=lambda item: item.name)
return [lookup[command] for command in commands if command in lookup]

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
Copy link
Member

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

kaczmarj added a commit to SBU-BMI/wsinfer that referenced this issue Jan 22, 2023
This adds auto-generated docs for the wsinfer cli. This commit also
renames the subcommand cli function names, to account for
click-contrib/sphinx-click#74
kaczmarj added a commit to SBU-BMI/wsinfer that referenced this issue Jan 22, 2023
This adds auto-generated docs for the wsinfer cli. This commit also
renames the subcommand cli function names, to account for
click-contrib/sphinx-click#74
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants