isort_code.sh 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #!/bin/bash
  2. # Copyright 2021 The 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 -ex
  16. ACTION=${1:---overwrite-in-place}
  17. [[ $ACTION == '--overwrite-in-place' ]] || [[ $ACTION == '--diff' ]]
  18. if [[ $ACTION == '--diff' ]]; then
  19. ACTION="--diff --check"
  20. fi
  21. # Change to root
  22. cd "$(dirname "${0}")/../.."
  23. DIRS=(
  24. 'examples/python'
  25. 'src/python'
  26. 'test'
  27. 'tools'
  28. 'setup.py'
  29. )
  30. VIRTUALENV=isort_virtual_environment
  31. python3 -m virtualenv $VIRTUALENV
  32. PYTHON=${VIRTUALENV}/bin/python
  33. "$PYTHON" -m pip install isort==5.9.2
  34. $PYTHON -m isort $ACTION \
  35. --force-sort-within-sections \
  36. --force-single-line-imports --single-line-exclusions=typing \
  37. --src "examples/python/data_transmission" \
  38. --src "examples/python/async_streaming" \
  39. --src "tools/run_tests/xds_k8s_test_driver" \
  40. --src "src/python/grpcio_tests" \
  41. --src "tools/run_tests" \
  42. --project "examples" \
  43. --project "src" \
  44. --thirdparty "grpc" \
  45. --skip-glob "third_party/*" \
  46. --skip-glob "*/env/*" \
  47. --skip-glob "*pb2*.py" \
  48. --dont-follow-links \
  49. "${DIRS[@]}"