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

feat(core): add shell_complete implementation for workflows and datasets #2512

Merged
merged 9 commits into from
Dec 20, 2021

Conversation

vigsterkr
Copy link
Contributor

@vigsterkr vigsterkr commented Dec 5, 2021

Description

Using the feature of click's auto-complete implementation when

  • running various renku dataset sub-commands the actual dataset name can be auto-completed

  • running various renku workflow sub-commands the actual workflow name can be auto-completed

  • fix dependency injection

  • Mention in the documentation how to activate for bash, zsh or fish (basically the shells that are supported by click) auto-completion of renku commands

@vigsterkr
Copy link
Contributor Author

currently with this implementation there's a problem with dependency injection, namely:

File "/opt/homebrew/Caskroom/mambaforge/base/envs/renku/bin/renku", line 8, in <module>
    sys.exit(cli())workflow details.
  File "/opt/homebrew/Caskroom/mambaforge/base/envs/renku/lib/python3.9/site-packages/click/core.py", line 1137, in __call__
    return self.main(*args, **kwargs)
  File "/opt/homebrew/Caskroom/mambaforge/base/envs/renku/lib/python3.9/site-packages/renku/cli/exception_handler.py", line 123, in main
    result = super().main(*args, **kwargs)ing through a...
  File "/opt/homebrew/Caskroom/mambaforge/base/envs/renku/lib/python3.9/site-packages/renku/cli/exception_handler.py", line 89, in main
    return super().main(*args, **kwargs) by workflows.
  File "/opt/homebrew/Caskroom/mambaforge/base/envs/renku/lib/python3.9/site-packages/click/core.py", line 1057, in main
    self._main_shell_completion(extra, prog_name, complete_var)
  File "/opt/homebrew/Caskroom/mambaforge/base/envs/renku/lib/python3.9/site-packages/click/core.py", line 1132, in _main_shell_completion
    rv = shell_complete(self, ctx_args, prog_name, complete_var, instruction)
  File "/opt/homebrew/Caskroom/mambaforge/base/envs/renku/lib/python3.9/site-packages/click/shell_completion.py", line 49, in shell_complete
    echo(comp.complete())
  File "/opt/homebrew/Caskroom/mambaforge/base/envs/renku/lib/python3.9/site-packages/click/shell_completion.py", line 291, in complete
    completions = self.get_completions(args, incomplete)
  File "/opt/homebrew/Caskroom/mambaforge/base/envs/renku/lib/python3.9/site-packages/click/shell_completion.py", line 273, in get_completions
    return obj.shell_complete(ctx, incomplete)
  File "/opt/homebrew/Caskroom/mambaforge/base/envs/renku/lib/python3.9/site-packages/click/core.py", line 2401, in shell_complete
    results = self._custom_shell_complete(ctx, self, incomplete)
  File "/opt/homebrew/Caskroom/mambaforge/base/envs/renku/lib/python3.9/site-packages/renku/cli/workflow.py", line 564, in _complete_workflows
    return list(filter(lambda x: x.startswith(incomplete), search_workflows(starts_with=incomplete)))
  File "/opt/homebrew/Caskroom/mambaforge/base/envs/renku/lib/python3.9/site-packages/inject/__init__.py", line 339, in injection_wrapper
    kwargs[param] = instance(cls)
  File "/opt/homebrew/Caskroom/mambaforge/base/envs/renku/lib/python3.9/site-packages/inject/__init__.py", line 402, in instance
    return get_injector_or_die().get_instance(cls)
  File "/opt/homebrew/Caskroom/mambaforge/base/envs/renku/lib/python3.9/site-packages/renku/core/management/command_builder/command.py", line 60, in _patched_get_injector_or_die
    raise inject.InjectorException("No injector is configured")
inject.InjectorException: No injector is configured

@vigsterkr
Copy link
Contributor Author

other than that using eval "$(_RENKU_COMPLETE=zsh_source renku)" for zsh is working pretty great.

@vigsterkr vigsterkr marked this pull request as ready for review December 8, 2021 16:34
@vigsterkr vigsterkr requested a review from a team as a code owner December 8, 2021 16:34
@vigsterkr vigsterkr force-pushed the click-autocomplete branch 2 times, most recently from 8749c7f to d444ec9 Compare December 9, 2021 14:21
@vigsterkr vigsterkr changed the title feat(core): add shell_complete implementation for workflows feat(core): add shell_complete implementation for workflows and datasets Dec 9, 2021
Copy link
Contributor

@m-alisafaee m-alisafaee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a very cool feature! Thanks Viktor! I've used it and have the following comments:

  • It prevents shell completion from working. For example, if I type renku dataset add my-dataset <TAB> to get a list of paths, nothing shows up; instead, it seems that Renku completions is called again. I believe disabling shell completions is not desirable.
  • Installation could be made easier: There is a renku --install-completion command that uses click-completion package to install the completion. Maybe you can check to see what it does and if it's useful here.

@vigsterkr
Copy link
Contributor Author

vigsterkr commented Dec 11, 2021

thanks for the feedback! see my answers below

* It prevents shell completion from working. For example, if I type `renku dataset add my-dataset <TAB>` to get a list of paths, nothing shows up; instead, it seems that Renku completions is called again. I believe disabling shell completions is not desirable.

good catch! this is indeed not good! i've just checked a bit into this. It's actually because of the following reason: the dataset add command click.argument for urls has no type parameter, that's why click doesn't know how to autocomplete it. in other words:

-@click.argument("urls", nargs=-1)
+@click.argument("urls", type=click.Path(exists=True), nargs=-1)

would actually fix the problem. now of course this is semantically not what we want but in this specific case i think it solves our problem. because anyways there would be no sane way to autocomplete a proper url, like http://. or?
of course the click.Path prevents us from actually using proper URLs, like https://raw.githubusercontent.com/selva86/datasets/master/BostonHousing.csv. so i'll look into how to overcome this issue

* Installation could be made easier: There is a `renku --install-completion` command that uses `click-completion` package to install the completion. Maybe you can check to see what it does and if it's useful here.

oh i didn't know about this 🤦 i've just quickly checked and it's not really working for me, but i'll investigate and try to make the whole shell integration installation working with this command and add it to this patch

@vigsterkr
Copy link
Contributor Author

@mohammad-sdsc so i've looked into the whole --install-completion command, which uses https://github.com/click-contrib/click-completion. basically with click 8.0 it is broken, see click-contrib/click-completion#41 and for example in AiiDA they already dropped the dependency: aiidateam/aiida-core#5098

i'd do the same, but we could still keep the command that actually expands the shell's config file with the right command (see the how-to) if we wanna maintain that code-base 🙃

@vigsterkr vigsterkr force-pushed the click-autocomplete branch 3 times, most recently from 39bba61 to c03490b Compare December 14, 2021 17:03
Copy link
Contributor

@m-alisafaee m-alisafaee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works great! Thank you!

@vigsterkr vigsterkr merged commit d6c1fe2 into master Dec 20, 2021
@vigsterkr vigsterkr deleted the click-autocomplete branch December 20, 2021 08:30
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

Successfully merging this pull request may close these issues.

None yet

2 participants