-
Notifications
You must be signed in to change notification settings - Fork 17.5k
Fix Breeze2 autocomplete #22695
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
Merged
Merged
Fix Breeze2 autocomplete #22695
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| _Breeze2_completion() { | ||
| local IFS=$'\n' | ||
| local response | ||
|
|
||
| response=$(env COMP_WORDS="${COMP_WORDS[*]}" COMP_CWORD=$COMP_CWORD _BREEZE2_COMPLETE=bash_complete $1) | ||
|
|
||
| for completion in $response; do | ||
| IFS=',' read type value <<< "$completion" | ||
|
|
||
| if [[ $type == 'dir' ]]; then | ||
| COMPREPLY=() | ||
| compopt -o dirnames | ||
| elif [[ $type == 'file' ]]; then | ||
| COMPREPLY=() | ||
| compopt -o default | ||
| elif [[ $type == 'plain' ]]; then | ||
| COMPREPLY+=($value) | ||
| fi | ||
| done | ||
|
|
||
| return 0 | ||
| } | ||
|
|
||
| _Breeze2_completion_setup() { | ||
| complete -o nosort -F _Breeze2_completion Breeze2 | ||
| } | ||
|
|
||
| _Breeze2_completion_setup; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| function _Breeze2_completion; | ||
| set -l response; | ||
|
|
||
| for value in (env _BREEZE2_COMPLETE=fish_complete COMP_WORDS=(commandline -cp) COMP_CWORD=(commandline -t) Breeze2); | ||
| set response $response $value; | ||
| end; | ||
|
|
||
| for completion in $response; | ||
| set -l metadata (string split "," $completion); | ||
|
|
||
| if test $metadata[1] = "dir"; | ||
| __fish_complete_directories $metadata[2]; | ||
| else if test $metadata[1] = "file"; | ||
| __fish_complete_path $metadata[2]; | ||
| else if test $metadata[1] = "plain"; | ||
| echo $metadata[2]; | ||
| end; | ||
| end; | ||
| end; | ||
|
|
||
| complete --no-files --command Breeze2 --arguments "(_Breeze2_completion)"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| #compdef Breeze2 | ||
|
|
||
| _Breeze2_completion() { | ||
| local -a completions | ||
| local -a completions_with_descriptions | ||
| local -a response | ||
| (( ! $+commands[Breeze2] )) && return 1 | ||
|
|
||
| response=("${(@f)$(env COMP_WORDS="${words[*]}" COMP_CWORD=$((CURRENT-1)) _BREEZE2_COMPLETE=zsh_complete Breeze2)}") | ||
|
|
||
| for type key descr in ${response}; do | ||
| if [[ "$type" == "plain" ]]; then | ||
| if [[ "$descr" == "_" ]]; then | ||
| completions+=("$key") | ||
| else | ||
| completions_with_descriptions+=("$key":"$descr") | ||
| fi | ||
| elif [[ "$type" == "dir" ]]; then | ||
| _path_files -/ | ||
| elif [[ "$type" == "file" ]]; then | ||
| _path_files -f | ||
| fi | ||
| done | ||
|
|
||
| if [ -n "$completions_with_descriptions" ]; then | ||
| _describe -V unsorted completions_with_descriptions -U | ||
| fi | ||
|
|
||
| if [ -n "$completions" ]; then | ||
| compadd -U -V unsorted -a completions | ||
| fi | ||
| } | ||
|
|
||
| compdef _Breeze2_completion Breeze2; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -59,7 +59,6 @@ install_requires = | |
| pytest-xdist | ||
| rich | ||
| rich_click | ||
| click_completion | ||
| requests | ||
| psutil | ||
| inputimeout | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you explain this part to me @potiuk? Why do we have to import locally for autocomplete to work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because when autocomplete loads list of methods, it imports
breeze.pyand it has to import it fully to determine list of available options (quite similarly like Airflow parsing dag files to determine the structure of DAG.Therefore we should make sure that very little number of packages need to be imported. There are two reasons:
This is the same thing as the one described by @blag here: #22613 (comment) and why we need to do the same in Airflow when we convert to click + click-rich.
It's also fundamentally the same case as the one described here in Airflow docs for DAG top-level code: https://airflow.apache.org/docs/apache-airflow/stable/best-practices.html?highlight=best%20practices#top-level-python-code