yapf.sh 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/usr/bin/env bash
  2. # Copyright 2021 gRPC authors.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. set -eo pipefail
  16. display_usage() {
  17. cat <<EOF >/dev/stderr
  18. A helper to run yapf formatter.
  19. USAGE: $0 [--diff]
  20. --diff: Do not apply changes, only show the diff
  21. ENVIRONMENT:
  22. XDS_K8S_DRIVER_VENV_DIR: the path to python virtual environment directory
  23. Default: $XDS_K8S_DRIVER_DIR/venv
  24. EXAMPLES:
  25. $0
  26. $0 --diff
  27. EOF
  28. exit 1
  29. }
  30. if [[ "$1" == "-h" || "$1" == "--help" ]]; then
  31. display_usage
  32. fi
  33. SCRIPT_DIR="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
  34. readonly SCRIPT_DIR
  35. readonly XDS_K8S_DRIVER_DIR="${SCRIPT_DIR}/.."
  36. cd "${XDS_K8S_DRIVER_DIR}"
  37. # Relative paths not yet supported by shellcheck.
  38. # shellcheck source=/dev/null
  39. source "${XDS_K8S_DRIVER_DIR}/bin/ensure_venv.sh"
  40. if [[ "$1" == "--diff" ]]; then
  41. readonly MODE="--diff"
  42. else
  43. readonly MODE="--in-place"
  44. readonly VERBOSE="--verbose" # print out file names while processing
  45. fi
  46. exec python -m yapf "${MODE}" ${VERBOSE:-} \
  47. --parallel --recursive --style=../../../setup.cfg \
  48. framework bin tests