mirror of
https://github.com/apache/impala.git
synced 2025-12-25 02:03:09 -05:00
This adds a Python 3 equivalent to the impala-python virtualenv base on the toolchain Python 3.7.16. This modifies bootstrap_virtualenv.py to support the two different modes. This adds py2-requirements.txt and py3-requirements.txt to allow some differences between the Python 2 and Python 3 virtualenvs. Here are some specific package changes: - allpairs is replaced with allpairspy, as allpairs did not support Python 3. - requests is upgraded slightly, because otherwise is has issues with idna==2.8. - pylint is limited to Python 3, because we are adding it and don't need it on both - flake8 is limited to Python 2, because it will take some work to switch to a version that works on Python 3 - cm_api is limited to Python 2, because it doesn't support Python 3 - pytest-random does not support Python 3 and it is unused, so it is removed - Bump the version of setuptool-scm to support Python 3 This adds impala-pylint, which can be used to do further Python 3 checks via --py3k. This also adds a bin/check-pylint-py3k.sh script to enforce specific py3k checks. The banned py3k warnings are specified in the bin/banned_py3k_warnings.txt. This is currently empty, but this can ratchet up the py3k strictness over time to avoid regressions. This pulls in a new toolchain with the fix for IMPALA-11956 to get Python 3.7.16. Testing: - Hand tested that the allpairs libraries produce the same results - The python3 virtualenv has no influence on regular tests yet Change-Id: Ica4853f440c9a46a79bd5fb8e0a66730b0b4efc0 Reviewed-on: http://gerrit.cloudera.org:8080/19567 Reviewed-by: Joe McDonnell <joemcdonnell@cloudera.com> Tested-by: Joe McDonnell <joemcdonnell@cloudera.com>
141 lines
4.8 KiB
Bash
Executable File
141 lines
4.8 KiB
Bash
Executable File
#!/bin/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.
|
|
|
|
set -euo pipefail
|
|
|
|
BINDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
|
|
|
# To allow incrementally banning individual pylint checks, this uses grep
|
|
# expressions to match banned pylint warnings. The grep expressions are stored
|
|
# in the bin/banned_py3k_warnings.txt file.
|
|
BANNED_PY3K_WARNINGS="${BINDIR}/banned_py3k_warnings.txt"
|
|
|
|
function print_usage {
|
|
echo "check-pylink-py3k.sh : Checks eligible python files for pylint py3k compliance."
|
|
echo "Fails if the python files have py3k warnings that match the patterns in "
|
|
echo "bin/banned_py3k_warnings.txt."
|
|
echo "[--error_output_file] : (optional) Also output the errors to a file"
|
|
echo "[--warning_output_file] : (optional) Also output the warnings to a file"
|
|
}
|
|
|
|
ERROR_OUTPUT_FILE=""
|
|
WARNING_OUTPUT_FILE=""
|
|
while [ -n "$*" ]
|
|
do
|
|
case "$1" in
|
|
--error_output_file)
|
|
ERROR_OUTPUT_FILE="${2-}"
|
|
shift;
|
|
;;
|
|
--warning_output_file)
|
|
WARNING_OUTPUT_FILE="${2-}"
|
|
shift;
|
|
;;
|
|
--help|*)
|
|
print_usage
|
|
exit 1
|
|
;;
|
|
esac
|
|
shift
|
|
done
|
|
|
|
pushd ${IMPALA_HOME} > /dev/null 2>&1
|
|
|
|
OUTPUT_TMP_DIR=$(mktemp -d)
|
|
PYLINT_OUTPUT_FILE="${OUTPUT_TMP_DIR}/pylint_output.txt"
|
|
ERROR_OUTPUT_TMP_FILE="${OUTPUT_TMP_DIR}/error_output_tmp.txt"
|
|
WARNING_OUTPUT_TMP_FILE="${OUTPUT_TMP_DIR}/warning_output_tmp.txt"
|
|
|
|
RETCODE=0
|
|
for file in $(git ls-files '**/*.py'); do
|
|
# Skip the shell entirely (but cover tests/shell)
|
|
if [[ "${file}" =~ "shell/" && ! "${file}" =~ "tests/shell" ]]; then
|
|
continue
|
|
fi
|
|
# For the moment, the focus is on enforcing py3k checks on files that use the
|
|
# impala-python virtualenv. Ignore executable python files that do not
|
|
# use impala-python. In practice, this tends to be scripts used during the
|
|
# build or various scripts for developers in bin.
|
|
FIRST_LINE=$(head -n1 ${file})
|
|
if [[ "${file}: ${FIRST_LINE}" =~ "#!" ]]; then
|
|
if [[ "${FIRST_LINE}" =~ "python3" ]]; then
|
|
>&2 echo "SKIPPING: ${file} is already using python3: ${FIRST_LINE}"
|
|
continue
|
|
fi
|
|
if [[ ! "${FIRST_LINE}" =~ "impala-python" ]]; then
|
|
>&2 echo "SKIPPING: ${file} is not using impala-python: ${FIRST_LINE}"
|
|
continue
|
|
fi
|
|
fi
|
|
|
|
>&2 echo "PROCESSING: ${file}"
|
|
|
|
# -s n (skip score for each file)
|
|
# --exit-zero: don't fail
|
|
impala-pylint -s n --exit-zero --py3k ${file} >> ${PYLINT_OUTPUT_FILE}
|
|
done
|
|
|
|
touch "${ERROR_OUTPUT_TMP_FILE}"
|
|
touch "${WARNING_OUTPUT_TMP_FILE}"
|
|
|
|
# Hitting a banned py3k warning will cause this to return an error
|
|
echo ""
|
|
echo ""
|
|
if grep -f "${BANNED_PY3K_WARNINGS}" "${PYLINT_OUTPUT_FILE}" > /dev/null 2>&1 ; then
|
|
echo "ERROR: Some python files contain these banned pylint warnings:" | \
|
|
tee "${ERROR_OUTPUT_TMP_FILE}"
|
|
grep -f "${BANNED_PY3K_WARNINGS}" "${PYLINT_OUTPUT_FILE}" | \
|
|
tee -a "${ERROR_OUTPUT_TMP_FILE}"
|
|
RETCODE=1
|
|
else
|
|
echo "No errors found" | tee "${ERROR_OUTPUT_TMP_FILE}"
|
|
fi
|
|
|
|
if [[ -n "${ERROR_OUTPUT_FILE}" ]]; then
|
|
cp "${ERROR_OUTPUT_TMP_FILE}" "${ERROR_OUTPUT_FILE}"
|
|
fi
|
|
|
|
# The remaining py3k warnings are interesting, but they are not yet enforced.
|
|
# Pylint produces annoying lines like "************* Module X", so try to filter those out
|
|
echo ""
|
|
echo ""
|
|
if grep -v -e '\*\*\*\*' -f "${BANNED_PY3K_WARNINGS}" \
|
|
"${PYLINT_OUTPUT_FILE}" > /dev/null 2>&1 ; then
|
|
echo "WARNING: Some python files contain these unenforced pylint warnings:" | \
|
|
tee "${WARNING_OUTPUT_TMP_FILE}"
|
|
grep -v -e '\*\*\*\*' -f "${BANNED_PY3K_WARNINGS}" "${PYLINT_OUTPUT_FILE}" | \
|
|
tee -a "${WARNING_OUTPUT_TMP_FILE}"
|
|
|
|
echo "WARNING SUMMARY table:"
|
|
cat "${WARNING_OUTPUT_TMP_FILE}" | grep -v "WARNING" | cut -d: -f4- | \
|
|
sed 's#^ ##' | sort | uniq -c
|
|
else
|
|
echo "No warnings found" | tee "${WARNING_OUTPUT_TMP_FILE}"
|
|
fi
|
|
|
|
if [[ -n "${WARNING_OUTPUT_FILE}" ]]; then
|
|
cp "${WARNING_OUTPUT_TMP_FILE}" "${WARNING_OUTPUT_FILE}"
|
|
fi
|
|
|
|
rm -rf "${OUTPUT_TMP_DIR}"
|
|
|
|
popd > /dev/null 2>&1
|
|
|
|
exit ${RETCODE}
|