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

build(deps): bump shtab from 1.5.8 to 1.7.1 in /ci/builder #30672

Merged
merged 2 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ci/builder/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ ruamel.yaml==0.18.6
ruff==0.0.292
scipy==1.14.1
semver==3.0.0
shtab==1.5.8
shtab==1.7.1
sqlparse==0.5.0
toml==0.10.2
twine==5.1.1
Expand Down
2 changes: 1 addition & 1 deletion ci/test/lint-main/checks/check-new-line.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ files=$(git_files "$@")
# Only binary files are permitted to omit a trailing newline. If you're here to
# exclude a text file that is missing its trailing newline, like an SVG, add
# a trailing newline to the text file instead.
newline_files=$(grep -vE '\.(png|jpe?g|pb|avro|ico|so)$' <<< "$files")
newline_files=$(grep -vE '(_scratch|\.(png|jpe?g|pb|avro|ico|so))$' <<< "$files")

try xargs misc/lint/trailing-newline.sh <<< "$newline_files"
try xargs git --no-pager diff --check "$(git_empty_tree)" <<< "$newline_files"
Expand Down
70 changes: 42 additions & 28 deletions misc/completions/bash/_scratch
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ _shtab_replace_nonword() {
# set default values (called for the initial parser & any subparsers)
_set_parser_defaults() {
local subparsers_var="${prefix}_subparsers[@]"
sub_parsers=${!subparsers_var}
sub_parsers=${!subparsers_var-}

local current_option_strings_var="${prefix}_option_strings[@]"
current_option_strings=${!current_option_strings_var}
Expand All @@ -88,19 +88,19 @@ _set_new_action() {
current_action="${prefix}_$(_shtab_replace_nonword $1)"

local current_action_compgen_var=${current_action}_COMPGEN
current_action_compgen="${!current_action_compgen_var}"
current_action_compgen="${!current_action_compgen_var-}"

local current_action_choices_var="${current_action}_choices[@]"
current_action_choices="${!current_action_choices_var}"
current_action_choices="${!current_action_choices_var-}"

local current_action_nargs_var="${current_action}_nargs"
if [ -n "${!current_action_nargs_var}" ]; then
if [ -n "${!current_action_nargs_var-}" ]; then
current_action_nargs="${!current_action_nargs_var}"
else
current_action_nargs=1
fi

current_action_args_start_index=$(( $word_index + 1 ))
current_action_args_start_index=$(( $word_index + 1 - $pos_only ))

current_action_is_positional=$2
}
Expand All @@ -114,10 +114,20 @@ _set_new_action() {
# ${!x} -> ${hello} -> "world"
_shtab_scratch() {
local completing_word="${COMP_WORDS[COMP_CWORD]}"
local completed_positional_actions
local current_action
local current_action_args_start_index
local current_action_choices
local current_action_compgen
local current_action_is_positional
local current_action_nargs
local current_option_strings
local sub_parsers
COMPREPLY=()

prefix=_shtab_scratch
word_index=0
local prefix=_shtab_scratch
local word_index=0
local pos_only=0 # "--" delimeter not encountered yet
_set_parser_defaults
word_index=1

Expand All @@ -126,34 +136,38 @@ _shtab_scratch() {
while [ $word_index -ne $COMP_CWORD ]; do
local this_word="${COMP_WORDS[$word_index]}"

if [[ -n $sub_parsers && " ${sub_parsers[@]} " =~ " ${this_word} " ]]; then
# valid subcommand: add it to the prefix & reset the current action
prefix="${prefix}_$(_shtab_replace_nonword $this_word)"
_set_parser_defaults
fi

if [[ " ${current_option_strings[@]} " =~ " ${this_word} " ]]; then
# a new action should be acquired (due to recognised option string or
# no more input expected from current action);
# the next positional action can fill in here
_set_new_action $this_word false
fi

if [[ "$current_action_nargs" != "*" ]] && \
[[ "$current_action_nargs" != "+" ]] && \
[[ "$current_action_nargs" != *"..." ]] && \
(( $word_index + 1 - $current_action_args_start_index >= \
$current_action_nargs )); then
$current_action_is_positional && let "completed_positional_actions += 1"
_set_new_action "pos_${completed_positional_actions}" true
if [[ $pos_only = 1 || " $this_word " != " -- " ]]; then
if [[ -n $sub_parsers && " ${sub_parsers[@]} " == *" ${this_word} "* ]]; then
# valid subcommand: add it to the prefix & reset the current action
prefix="${prefix}_$(_shtab_replace_nonword $this_word)"
_set_parser_defaults
fi

if [[ " ${current_option_strings[@]} " == *" ${this_word} "* ]]; then
# a new action should be acquired (due to recognised option string or
# no more input expected from current action);
# the next positional action can fill in here
_set_new_action $this_word false
fi

if [[ "$current_action_nargs" != "*" ]] && \
[[ "$current_action_nargs" != "+" ]] && \
[[ "$current_action_nargs" != *"..." ]] && \
(( $word_index + 1 - $current_action_args_start_index - $pos_only >= \
$current_action_nargs )); then
$current_action_is_positional && let "completed_positional_actions += 1"
_set_new_action "pos_${completed_positional_actions}" true
fi
else
pos_only=1 # "--" delimeter encountered
fi

let "word_index+=1"
done

# Generate the completions

if [[ "${completing_word}" == -* ]]; then
if [[ $pos_only = 0 && "${completing_word}" == -* ]]; then
# optional argument started: use option strings
COMPREPLY=( $(compgen -W "${current_option_strings[*]}" -- "${completing_word}") )
else
Expand Down
30 changes: 19 additions & 11 deletions misc/completions/zsh/_scratch
Original file line number Diff line number Diff line change
Expand Up @@ -90,28 +90,36 @@ _shtab_scratch() {
if ((${_shtab_scratch_options[(I)${(q)one_or_more}*]} + ${_shtab_scratch_options[(I)${(q)remainder}*]} == 0)); then # noqa: E501
_shtab_scratch_options+=(': :_shtab_scratch_commands' '*::: :->scratch')
fi
_arguments -C $_shtab_scratch_options
_arguments -C -s $_shtab_scratch_options

case $state in
scratch)
words=($line[1] "${words[@]}")
(( CURRENT += 1 ))
curcontext="${curcontext%:*:*}:_shtab_scratch-$line[1]:"
case $line[1] in
completion) _arguments -C $_shtab_scratch_completion_options ;;
create) _arguments -C $_shtab_scratch_create_options ;;
destroy) _arguments -C $_shtab_scratch_destroy_options ;;
forward) _arguments -C $_shtab_scratch_forward_options ;;
login) _arguments -C $_shtab_scratch_login_options ;;
mine) _arguments -C $_shtab_scratch_mine_options ;;
push) _arguments -C $_shtab_scratch_push_options ;;
sftp) _arguments -C $_shtab_scratch_sftp_options ;;
ssh) _arguments -C $_shtab_scratch_ssh_options ;;
completion) _arguments -C -s $_shtab_scratch_completion_options ;;
create) _arguments -C -s $_shtab_scratch_create_options ;;
destroy) _arguments -C -s $_shtab_scratch_destroy_options ;;
forward) _arguments -C -s $_shtab_scratch_forward_options ;;
login) _arguments -C -s $_shtab_scratch_login_options ;;
mine) _arguments -C -s $_shtab_scratch_mine_options ;;
push) _arguments -C -s $_shtab_scratch_push_options ;;
sftp) _arguments -C -s $_shtab_scratch_sftp_options ;;
ssh) _arguments -C -s $_shtab_scratch_ssh_options ;;
esac
esac
}



typeset -A opt_args
_shtab_scratch "$@"

if [[ $zsh_eval_context[-1] == eval ]]; then
# eval/source/. command, register function for later
compdef _shtab_scratch -N scratch
else
# autoload from fpath, call function directly
_shtab_scratch "$@"
fi