github.com/apache/beam/sdks/v2@v2.48.2/python/scripts/run_pylint_2to3.sh (about) 1 #!/bin/bash 2 # 3 # Licensed to the Apache Software Foundation (ASF) under one or more 4 # contributor license agreements. See the NOTICE file distributed with 5 # this work for additional information regarding copyright ownership. 6 # The ASF licenses this file to You under the Apache License, Version 2.0 7 # (the "License"); you may not use this file except in compliance with 8 # the License. You may obtain a copy of the License at 9 # 10 # http://www.apache.org/licenses/LICENSE-2.0 11 # 12 # Unless required by applicable law or agreed to in writing, software 13 # distributed under the License is distributed on an "AS IS" BASIS, 14 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 # See the License for the specific language governing permissions and 16 # limitations under the License. 17 # 18 19 # This script will run pylint with the --py3k parameter to check for python 20 # 3 compatibility. This script can run on a list of modules provided as 21 # command line arguments. 22 # 23 # The exit-code of the script indicates success or a failure. 24 25 # Check that the script is running in a known directory. 26 if [[ $PWD != *sdks/python* ]]; then 27 echo 'Unable to locate Apache Beam Python SDK root directory' 28 exit 1 29 fi 30 31 # Go to the Apache Beam Python SDK root 32 if [[ $PWD != *sdks/python ]]; then 33 cd $(pwd | sed 's/sdks\/python.*/sdks\/python/') 34 fi 35 36 set -o errexit 37 set -o pipefail 38 39 MODULE=$(ls -d -C apache_beam *.py) 40 41 usage(){ echo "Usage: $0 [MODULE|--help] # The default MODULE is $MODULE"; } 42 43 if test $# -gt 0; then 44 case "$@" in 45 --help) usage; exit 1;; 46 *) MODULE="$*";; 47 esac 48 fi 49 50 # Following generated files are excluded from lint checks. 51 EXCLUDED_GENERATED_FILES=( 52 "apache_beam/io/gcp/internal/clients/bigquery/bigquery_v2_client.py" 53 "apache_beam/io/gcp/internal/clients/bigquery/bigquery_v2_messages.py" 54 "apache_beam/runners/dataflow/internal/clients/dataflow/dataflow_v1b3_client.py" 55 "apache_beam/runners/dataflow/internal/clients/dataflow/dataflow_v1b3_messages.py" 56 "apache_beam/io/gcp/internal/clients/storage/storage_v1_client.py" 57 "apache_beam/io/gcp/internal/clients/storage/storage_v1_messages.py" 58 "apache_beam/coders/proto2_coder_test_messages_pb2.py" 59 ) 60 61 # more portable than shopt -s globstar 62 while IFS= read -d $'\0' -r file ; do 63 EXCLUDED_GENERATED_FILES+=("$file") 64 done < <(find apache_beam/portability/api -type f -name "*pb2*.py" -print0) 65 66 FILES_TO_IGNORE="" 67 for file in "${EXCLUDED_GENERATED_FILES[@]}"; do 68 if test -z "$FILES_TO_IGNORE" 69 then FILES_TO_IGNORE="$(basename $file)" 70 else FILES_TO_IGNORE="$FILES_TO_IGNORE, $(basename $file)" 71 fi 72 done 73 echo "Skipping lint for generated files: $FILES_TO_IGNORE" 74 75 echo "Running pylint --py3k for modules $( printf "%s " "${MODULE}" ):" 76 pylint -j8 $( printf "%s " "${MODULE}" ) \ 77 --ignore-patterns="$FILES_TO_IGNORE" --py3k