forked from apache/airflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
breeze-complete
475 lines (440 loc) · 15.8 KB
/
breeze-complete
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
#!/usr/bin/env bash
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
# Allowed values for the commands & flags used
# The values here should be synchronized with the ones in
# the ./scripts/ci/libraries/_initialization.sh and it is verified
# Those cannot be made read-only as the breeze-complete must be re-sourceable
_breeze_allowed_python_major_minor_versions="3.7 3.8 3.9"
_breeze_allowed_backends="sqlite mysql postgres mssql"
_breeze_allowed_integrations="cassandra kerberos mongo openldap pinot rabbitmq redis statsd trino all"
_breeze_allowed_generate_constraints_modes="source-providers pypi-providers no-providers"
_breeze_allowed_kubernetes_modes="image"
_breeze_allowed_kubernetes_versions="v1.21.1 v1.20.2"
_breeze_allowed_helm_versions="v3.6.3"
_breeze_allowed_kind_versions="v0.11.1"
_breeze_allowed_mysql_versions="5.7 8"
_breeze_allowed_mssql_versions="2017-latest 2019-latest"
_breeze_allowed_postgres_versions="10 11 12 13"
_breeze_allowed_kind_operations="start stop restart status deploy test shell k9s"
_breeze_allowed_executors="KubernetesExecutor CeleryExecutor LocalExecutor CeleryKubernetesExecutor"
_breeze_allowed_test_types="All Always Core Providers API CLI Integration Other WWW Postgres MySQL Helm Quarantined"
_breeze_allowed_package_formats="both sdist wheel"
_breeze_allowed_installation_methods=". apache-airflow"
_breeze_allowed_platforms="linux/amd64"
# shellcheck disable=SC2034
{
# Default values for the commands & flags used
_breeze_default_backend=$(echo "${_breeze_allowed_backends}" | awk '{print $1}')
_breeze_default_generate_providers_mode=$(echo "${_breeze_allowed_generate_constraints_modes}" | awk '{print $1}')
_breeze_default_kubernetes_mode=$(echo "${_breeze_allowed_kubernetes_modes}" | awk '{print $1}')
_breeze_default_kubernetes_version=$(echo "${_breeze_allowed_kubernetes_versions}" | awk '{print $1}')
_breeze_default_helm_version=$(echo "${_breeze_allowed_helm_versions}" | awk '{print $1}')
_breeze_default_kind_version=$(echo "${_breeze_allowed_kind_versions}" | awk '{print $1}')
_breeze_default_executor=$(echo "${_breeze_allowed_executors}" | awk '{print $1}')
_breeze_default_postgres_version=$(echo "${_breeze_allowed_postgres_versions}" | awk '{print $1}')
_breeze_default_mysql_version=$(echo "${_breeze_allowed_mysql_versions}" | awk '{print $1}')
_breeze_default_mssql_version=$(echo "${_breeze_allowed_mssql_versions}" | awk '{print $1}')
_breeze_default_test_type=$(echo "${_breeze_allowed_test_types}" | awk '{print $1}')
_breeze_default_package_format=$(echo "${_breeze_allowed_package_formats}" | awk '{print $1}')
_breeze_default_platform=$(echo "${_breeze_allowed_platforms}" | awk '{print $1}')
}
_breeze_allowed_install_airflow_versions=$(cat <<-EOF
2.0.2
2.0.1
2.0.0
wheel
sdist
EOF
)
_breeze_allowed_USE_AIRFLOW_VERSION=$(cat <<-EOF
${_breeze_allowed_install_airflow_versions}
none
EOF
)
_breeze_allowed_static_checks=$(cat <<-EOF
all
airflow-config-yaml
airflow-providers-available
airflow-provider-yaml-files-ok
autoflake
base-operator
black
blacken-docs
boring-cyborg
build
build-providers-dependencies
chart-schema-lint
capitalized-breeze
changelog-duplicates
check-apache-license
check-builtin-literals
check-executables-have-shebangs
check-extras-order
check-hooks-apply
check-integrations
check-merge-conflict
check-xml
daysago-import-check
debug-statements
detect-private-key
docstring-params
doctoc
dont-use-safe-filter
end-of-file-fixer
fix-encoding-pragma
flake8
flynt
codespell
forbid-tabs
helm-lint
identity
incorrect-use-of-LoggingMixin
insert-license
isort
json-schema
language-matters
lint-dockerfile
lint-openapi
markdownlint
mermaid
mixed-line-ending
mypy
mypy-helm
no-providers-in-core-examples
no-relative-imports
persist-credentials-disabled
pre-commit-descriptions
pre-commit-hook-names
pretty-format-json
provide-create-sessions
providers-changelogs
providers-init-file
providers-subpackages-init-file
provider-yamls
pydevd
pydocstyle
python-no-log-warn
pyupgrade
restrict-start_date
rst-backticks
setup-order
setup-extra-packages
shellcheck
sort-in-the-wild
sort-spelling-wordlist
stylelint
trailing-whitespace
ui-lint
update-breeze-file
update-extras
update-local-yml-file
update-setup-cfg-file
update-supported-versions
update-versions
vendor-k8s-json-schema
verify-db-migrations-documented
version-sync
www-lint
yamllint
yesqa
EOF
)
_breeze_default_github_repository="apache/airflow"
_breeze_default_github_image_id="latest"
_breeze_short_options="
h p: b: i:
K: V:
l a: t: d:
v y n q f
F P I E: C r
L U X
g: s:
S: N:
"
_breeze_long_options="
help python: backend: integration: platform:
kubernetes-mode: kubernetes-version: helm-version: kind-version:
skip-mounting-local-sources mount-all-local-sources install-airflow-version: install-airflow-reference: db-reset
verbose assume-yes assume-no assume-quit forward-credentials init-script:
force-build-images force-pull-images check-if-base-python-image-updated production-image extras: force-clean-images skip-rebuild-check
build-cache-local build-cache-pulled build-cache-disabled disable-pip-cache
github-repository: github-image-id: generate-constraints-mode:
postgres-version: mysql-version: mssql-version:
version-suffix-for-pypi: version-suffix-for-svn:
additional-extras: additional-python-deps: additional-dev-deps: additional-runtime-deps: image-tag:
disable-mysql-client-installation disable-mssql-client-installation constraints-location: disable-pip-cache install-from-docker-context-files
additional-extras: additional-python-deps: disable-pypi-when-building skip-installing-airflow-providers-from-sources
dev-apt-deps: additional-dev-apt-deps: dev-apt-command: additional-dev-apt-command: additional-dev-apt-env:
runtime-apt-deps: additional-runtime-apt-deps: runtime-apt-command: additional-runtime-apt-command: additional-runtime-apt-env:
load-default-connections load-example-dags
use-packages-from-dist no-rbac-ui package-format: upgrade-to-newer-dependencies installation-method: continue-on-pip-check-failure non-interactive generate-providers-issue
use-airflow-version:
cleanup-docker-context-files prepare-buildx-cache
test-type: preserve-volumes dry-run-docker
executor:
"
_breeze_commands="
shell
build-docs
build-image
prepare-build-cache
cleanup-image
exec
generate-constraints
initialize-local-virtualenv
prepare-airflow-packages
setup-autocomplete
start-airflow
stop
restart
toggle-suppress-cheatsheet
toggle-suppress-asciiart"
_breeze_extra_arg_commands="
docker-compose
kind-cluster
prepare-provider-documentation
prepare-provider-packages
static-check
tests
"
_breeze_help_commands="
flags
help
help-all"
_breeze_all_commands="${_breeze_commands} ${_breeze_extra_arg_commands} ${_breeze_help_commands}"
# Note on OSX bash has no associative arrays (Bash 3.2) so we have to fake it
_breeze_known_values=""
#######################################################################################################
#
# Dynamically set list of values in _breeze_known_values variable depending on the command used
#
# Used variables:
# _breeze_allowed_* for allowed values for the commands
#
# Arguments:
# $1 - command to get known values for
#
# Set variables:
# _breeze_known_values is set to list of known values for the command, separated with space
#
#######################################################################################################
function breeze_complete::get_known_values_breeze() {
case "$1" in
-p | --python)
_breeze_known_values=${_breeze_allowed_python_major_minor_versions}
;;
-b | --backend)
_breeze_known_values=${_breeze_allowed_backends}
;;
-i | --integration)
_breeze_known_values=${_breeze_allowed_integrations}
;;
-K | --kubernetes-mode)
_breeze_known_values=${_breeze_allowed_kubernetes_modes}
;;
-V | --kubernetes-version)
_breeze_known_values=${_breeze_allowed_kubernetes_versions}
;;
--kind-version)
_breeze_known_values=${_breeze_allowed_kind_versions}
;;
--helm-version)
_breeze_known_values=${_breeze_allowed_helm_versions}
;;
static-check)
_breeze_known_values=${_breeze_allowed_static_checks}
;;
-a | --install-airflow-version)
_breeze_known_values=${_breeze_allowed_install_airflow_versions}
;;
--use-airflow-version)
_breeze_known_values=${_breeze_allowed_USE_AIRFLOW_VERSION}
;;
docker-compose)
# shellcheck disable=SC2034
if typeset -f "_docker_compose" >/dev/null; then
_docker_compose
fi
_breeze_known_values=""
;;
--postgres-version)
_breeze_known_values=${_breeze_allowed_postgres_versions}
;;
--mysql-version)
_breeze_known_values=${_breeze_allowed_mysql_versions}
;;
--mssql-version)
_breeze_known_values=${_breeze_allowed_mssql_versions}
;;
-g | --github-repository)
_breeze_known_values="${_breeze_default_github_repository}"
;;
-s | --github-image-id)
_breeze_known_values="${_breeze_default_github_image_id}"
;;
kind-cluster)
_breeze_known_values="${_breeze_allowed_kind_operations}"
;;
tests)
_breeze_known_values="$(find tests -name '*.py')"
;;
--test-type)
_breeze_known_values="${_breeze_allowed_test_types}"
;;
--executor)
_breeze_known_values="${_breeze_allowed_executors}"
;;
--package-format)
_breeze_known_values="${_breeze_allowed_package_formats}"
;;
--installation-method)
_breeze_known_values="${_breeze_allowed_installation_methods}"
;;
--generate-constraints-mode)
_breeze_known_values="${_breeze_allowed_generate_constraints_modes}"
;;
*)
_breeze_known_values=""
;;
esac
}
_breeze_getopt_short_options=""
_breeze_getopt_long_options=""
#######################################################################################################
#
# Retrieves list of short and long options from the constants in the form of EOL separated values
# which is easy to maintain into comma separated list - usable for getopt.
#
# Used variables:
# _breeze_short_options
# _breeze_long_options
#
# Set variables:
# _breeze_getopt_short_options
# _breeze_getopt_long_options
#######################################################################################################
function breeze_complete::_build_options_breeze {
local separator=""
local option
for option in ${_breeze_short_options}
do
_breeze_getopt_short_options="${_breeze_getopt_short_options}${separator}${option}"
separator=","
done
separator=""
for option in ${_breeze_long_options}
do
_breeze_getopt_long_options="${_breeze_getopt_long_options}${separator}${option}"
separator=","
done
}
#######################################################################################################
#
# Returns 0 if word to check is in the list of words
# which is easy to maintain into comma separated list - usable for getopt.
#
# Arguments:
# $1 - space separated list of words
# $2 - word to look for
#
# Return:
# 0 - if the word is found in the list
# 1 - otherwise
#######################################################################################################
function breeze_complete::_listcontains_breeze {
local word
for word in $1; do
[[ ${word} = "$2" ]] && return 0
done
return 1
}
#######################################################################################################
#
# Convert options from the lists passed and add the options to appropriate variables.
# The options are stripped of the trailing colon and if they do have a colon, they are added
# to the options that require an argument. Options are prefixed with the prefix.
#
# Arguments:
# $1 - prefix for the option
# $2 - list of options
#
# Variables modified:
# all_options - space-separated all options
# options_with extra_args - space separate list of options with an extra argument
#######################################################################################################
function breeze_complete::_convert_options {
local option_with_prefix_without_colon
local option
local prefix=$1
for option in $2
do
last_character="${option:$((${#option} - 1)):1}"
option_with_prefix_without_colon=${prefix}${option//:/}
if [[ "${last_character}" == ":" ]]; then
options_with_extra_arguments="${options_with_extra_arguments} ${option_with_prefix_without_colon}"
fi
all_options="${all_options} ${option_with_prefix_without_colon}"
done
}
#######################################################################################################
#
# A completion function for breeze
#
# See: https://www.gnu.org/software/bash/manual/html_node/Programmable-Completion.html#Programmable-Completion
#
#######################################################################################################
function breeze_complete::_comp_breeze {
local all_options=""
local options_with_extra_arguments=""
local currently_typed_string
local previous_command_in_the_command_line
local last_character
breeze_complete::_convert_options "-" "${_breeze_short_options}"
breeze_complete::_convert_options "--" "${_breeze_long_options}"
# Add all Breeze commands to list of all options
all_options="${all_options} ${_breeze_all_commands}"
# Add all Breeze commands with extra args to list of options with extra args
options_with_extra_arguments="${options_with_extra_arguments} ${_breeze_extra_arg_commands}"
# Retrieve typed beginning of current commands used so that we can use it as filter in the compgen utility
currently_typed_string="${COMP_WORDS[${COMP_CWORD}]}"
# if we have already typed more words, then we check what was the last previous command so that
# we can retrieve list of known values matching it.
if [[ ${#COMP_WORDS[@]} -gt 1 ]]; then
previous_command_in_the_command_line="${COMP_WORDS[${COMP_CWORD} - 1]}"
else
previous_command_in_the_command_line=""
fi
# if the previous command is in the list of options with extra args - check what are the known values
if breeze_complete::_listcontains_breeze \
"${options_with_extra_arguments}" "${previous_command_in_the_command_line}"; then
# Set COMPREPLY containing list of valid values matching currently typed string from known values
COMPREPLY=()
breeze_complete::get_known_values_breeze "${previous_command_in_the_command_line}"
while IFS='' read -r line; do COMPREPLY+=("${line}"); done \
< <(compgen -W "${_breeze_known_values}" -- "${currently_typed_string}")
else
# Set COMPREPLY containing list of valid commands/options matching currently typed string
COMPREPLY=()
while IFS='' read -r line; do COMPREPLY+=("${line}"); done \
< <(compgen -W "${all_options}" -- "${currently_typed_string}")
fi
}
breeze_complete::_build_options_breeze
# set autocompletion function for breeze
complete -F breeze_complete::_comp_breeze breeze
complete -F breeze_complete::_comp_breeze ./breeze