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

Breeze: Setup Autocomplete for Breeze #19967

Closed
potiuk opened this issue Dec 2, 2021 · 8 comments · Fixed by #20066
Closed

Breeze: Setup Autocomplete for Breeze #19967

potiuk opened this issue Dec 2, 2021 · 8 comments · Fixed by #20066
Assignees
Labels
area:dev-env-Breeze2 Breeze 2 issues kind:task A task that needs to be completed as part of a larger issue

Comments

@potiuk
Copy link
Member

potiuk commented Dec 2, 2021

We should leverage the 'click' functionality to get autocomplete working (https://click.palletsprojects.com/en/8.0.x/shell-completion/#) for ./Breeze2 command. The commands should come from the ./dev/breeze/src/breeze.py.

This might require some hackery approach and might prove to be impossible or difficult, because it is based on entrypotnts and the fact that we want to use Breeze2 command to run Airflow might not be well recognized by shell autocomplete.

But I believe with proper naming of the commands/entrypoints we should be able to achieve it.

The result of this should be short instruction on how to make autocomplete for Breeze2 works (possibly with links to the documentation from click).

@potiuk potiuk changed the title Setup Autocomplete for Breeze Breeze: Setup Autocomplete for Breeze Dec 2, 2021
@Bowrna
Copy link
Contributor

Bowrna commented Dec 6, 2021

I will pick this issue to work on first @potiuk

@uranusjr
Copy link
Member

uranusjr commented Dec 6, 2021

A better approach would be to pre-generate completion scripts, and use pre-commit to keep everything in sync. This would eliminate most of the hacks (at runtime at least; all of those would only need to be able to generate a completion script).

click-completion is another thing to look into that can help this.

@Bowrna
Copy link
Contributor

Bowrna commented Dec 6, 2021

@uranusjr could you explain to me why we have to keep everything in sync using pre-commit?

@uranusjr
Copy link
Member

uranusjr commented Dec 6, 2021

So when someone adds a new command, they can be automatically reminded to regenerate the autocompletion script.

@eladkal eladkal added area:dev-env-Breeze2 Breeze 2 issues kind:task A task that needs to be completed as part of a larger issue labels Dec 6, 2021
@Bowrna
Copy link
Contributor

Bowrna commented Dec 6, 2021

@potiuk I am planning to start this with one actual command and adding autocomplete for that one command and create help docs with that. Am i going in right direction?

@potiuk
Copy link
Member Author

potiuk commented Dec 6, 2021

@uranusjr is right - Click completion is the right approach. And I aggre that the scripts should be automatically generated by .pre-commit.

So when someone adds a new command, they can be automatically reminded to regenerate the autocompletion script.

Not even reminded - the scripts should be automatically regenerated. We have quite a few of those already - for example look here:

- id: update-version
where we take a version and update it in a few places.

In this case as pre-commit we should simply run generation of the scripts whenever the dev/breeze/src/airflow_breeze.py changes.

See how to generate the scripts here: https://click.palletsprojects.com/en/7.x/bashcomplete/#activation-script

Then I think we coud make (or find) the right way to update .zshrc/.bashrc etc with those activation commands (I guess someone had done that).

@Bowrna
Copy link
Contributor

Bowrna commented Dec 7, 2021

@potiuk I have tried the above https://click.palletsprojects.com/en/7.x/bashcomplete/#activation-script script generation part and it works for me. Do I have to add that as the python script that generates autocompletion script in pre_commit like what is there for update-version? (like the one shown below)

entry: ./scripts/ci/pre_commit/pre_commit_update_versions.py

Also, you have mentioned that in pre-commit we should simply run generation of the scripts whenever the dev/breeze/src/airflow_breeze.py changes. How could I find out there are changes in this script file?

The python script functionality would be to regenerate .bash/.zsh/.fsh and update in .zshrc/.bashrc/~/.config/fish/completions/ file

I want to know if the first time generated .bash/.zsh/.fsh should be committed as part of the repository.

@potiuk
Copy link
Member Author

potiuk commented Dec 7, 2021

Yeah. Just add a pre-commiit to generate the files and save them somewhere in ./dev/breeze/autocomplete/ for example. And add instructions to the users to make symbolic links to those scripts from the appropriate ./completions/ directory.

There is no need to check if a file changes. Assuming that precommit generates the same script when you run it twice, pre-commit checks on it's own if the re-generated file changed or not. So it's ok to regenerate the file again and again only to find out that nothing changed (but in pre-commit definition you should specify that pre-commit should run only when the ./airflow_breeze.py changes (because that's where the defintions of click commands are).

This can be done by adding pass_filenames to false: https://pre-commit.com/#hooks-pass_filenames and adding dev/breeze/airflow_breeze.py proper regexp to files parameter of pre-commit https://pre-commit.com/#hooks-files.

If you add the "files" specification, checking if the matching files have chnged is done by pre-commit automatically - in this case if the change that you are commiting contains the dev/breeze/airflow_breeze.py, then the pre-commit hook will run - otherwise it will be skipped.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:dev-env-Breeze2 Breeze 2 issues kind:task A task that needs to be completed as part of a larger issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants