check-python-discouraged.sh 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #!/usr/bin/env bash
  2. # Copyright Materialize, Inc. and contributors. All rights reserved.
  3. #
  4. # Use of this software is governed by the Business Source License
  5. # included in the LICENSE file at the root of this repository.
  6. #
  7. # As of the Change Date specified in that file, in accordance with
  8. # the Business Source License, use of this software will be governed
  9. # by the Apache License, Version 2.0.
  10. #
  11. # check-python-discouraged.sh — check discouraged commands.
  12. set -euo pipefail
  13. cd "$(dirname "$0")/../../../.."
  14. . misc/shlib/shlib.bash
  15. if [[ ! "${MZDEV_NO_PYTHON:-}" ]]; then
  16. EXIT_CODE=0
  17. # check whether occurrences of `run("testdrive"` (in a single line or spread across two lines) exist, which are discouraged
  18. # shellcheck disable=SC2016
  19. TD_SINGLE_LINE_MATCHES=$(find misc/python/materialize test -name '*.py' -print0 | xargs -0 awk '/\.run\("testdrive",/ {print FILENAME ":" FNR} {prev_line = $0}')
  20. # shellcheck disable=SC2016
  21. TD_MULTI_LINE_MATCHES=$(find misc/python/materialize test -name '*.py' -print0 | xargs -0 awk '/"testdrive",/ && prev_line ~ /\.run\($/ {print FILENAME ":" FNR} {prev_line = $0}')
  22. TD_MULTI_LINE_MATCHES=$(echo "$TD_MULTI_LINE_MATCHES" | grep -v "misc/python/materialize/mzcompose/composition.py" || true)
  23. if [ -n "$TD_SINGLE_LINE_MATCHES" ] || [ -n "$TD_MULTI_LINE_MATCHES" ]; then
  24. echo "Use \`.run_testdrive_files(\` instead of \`.run(\"testdrive\"\`:"
  25. if [ -n "$TD_SINGLE_LINE_MATCHES" ]; then
  26. echo "$TD_SINGLE_LINE_MATCHES"
  27. fi
  28. if [ -n "$TD_MULTI_LINE_MATCHES" ]; then
  29. echo "$TD_MULTI_LINE_MATCHES"
  30. fi
  31. EXIT_CODE=1
  32. fi
  33. exit $EXIT_CODE
  34. fi
  35. try_status_report