#!/usr/bin/env 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.## define test binaries + versionsFLAKE8_BUILD="flake8"MINIMUM_FLAKE8="3.9.0"RUFF_BUILD="ruff"MINIMUM_RUFF="0.14.0"MINIMUM_MYPY="1.19.1"MYPY_BUILD="mypy"PYTEST_BUILD="pytest"PYTHON_EXECUTABLE="${PYTHON_EXECUTABLE:-python3}"BLACK_BUILD="$PYTHON_EXECUTABLE -m black"function exit_with_usage {set +xecho "lint-python - linter for Python"echo ""echo "usage:"cl_options="[--compile] [--custom-pyspark-error] [--ruff] [--mypy] [--mypy-examples] [--mypy-data]"echo "lint-python $cl_options"echo ""exit 1}# Parse argumentswhile (( "$#" )); docase 1ドル in--compile)COMPILE_TEST=true;;--black)BLACK_TEST=true;;--custom-pyspark-error)PYSPARK_CUSTOM_ERRORS_CHECK_TEST=true;;--flake8)FLAKE8_TEST=true;;--ruff)RUFF_TEST=true;;--mypy)MYPY_TEST=true;;--mypy-examples)MYPY_EXAMPLES_TEST=true;;--mypy-data)MYPY_DATA_TEST=true;;*)echo "Error: 1ドル is not supported"exit_with_usage;;esacshiftdoneif [[ -z "$COMPILE_TEST$BLACK_TEST$PYSPARK_CUSTOM_ERRORS_CHECK_TEST$FLAKE8_TEST$RUFF_TEST$MYPY_TEST$MYPY_EXAMPLES_TEST$MYPY_DATA_TEST" ]]; thenCOMPILE_TEST=truePYSPARK_CUSTOM_ERRORS_CHECK_TEST=trueRUFF_TEST=trueMYPY_TEST=trueMYPY_EXAMPLES_TEST=trueMYPY_DATA_TEST=truefifunction satisfies_min_version {local provided_version="1ドル"local expected_version="2ドル"echo "$("$PYTHON_EXECUTABLE" << EOMtry:from setuptools.extern.packaging import versionexcept ModuleNotFoundError:from packaging import versionprint(version.parse('$provided_version') >= version.parse('$expected_version'))EOM)"}function compile_python_test {local COMPILE_STATUS=local COMPILE_REPORT=if [[ ! "1ドル" ]]; thenecho "No python files found! Something is very wrong -- exiting."exit 1;fi# compileall: https://docs.python.org/3/library/compileall.htmlecho "starting python compilation test..."COMPILE_REPORT=$( ("$PYTHON_EXECUTABLE" -B -mcompileall -q -l -x "[/\\\\][.]git" 1ドル) 2>&1)COMPILE_STATUS=$?if [ $COMPILE_STATUS -ne 0 ]; thenecho "Python compilation failed with the following errors:"echo "$COMPILE_REPORT"echo "$COMPILE_STATUS"exit "$COMPILE_STATUS"elseecho "python compilation succeeded."echofi}function mypy_annotation_test {local MYPY_REPORT=local MYPY_STATUS=echo "starting mypy annotations test..."MYPY_REPORT=$( ($MYPY_BUILD \--python-executable $PYTHON_EXECUTABLE \--namespace-packages \--config-file python/mypy.ini \--cache-dir /tmp/.mypy_cache/ \python/pyspark) 2>&1)MYPY_STATUS=$?if [ "$MYPY_STATUS" -ne 0 ]; thenecho "annotations failed mypy checks:"echo "$MYPY_REPORT"echo "$MYPY_STATUS"exit "$MYPY_STATUS"elseecho "annotations passed mypy checks."echofi}function mypy_data_test {local PYTEST_REPORT=local PYTEST_STATUS=echo "starting mypy data test..."$PYTHON_EXECUTABLE -c "import importlib.util; import sys; \sys.exit(0 if importlib.util.find_spec('pytest_mypy_plugins') else 1)"if [ $? -ne 0 ]; thenecho "pytest-mypy-plugins missing. Skipping for now."returnfiPYTEST_REPORT=$( (MYPYPATH=python $PYTEST_BUILD \-o "python_files=test_*.yml" \--rootdir python \--mypy-only-local-stub \--mypy-ini-file python/mypy.ini \python/pyspark/tests/typing \python/pyspark/sql/tests/typing \python/pyspark/ml/tests/typing \) 2>&1)PYTEST_STATUS=$?if [ "$PYTEST_STATUS" -ne 0 ]; thenecho "annotations failed data checks:"echo "$PYTEST_REPORT"echo "$PYTEST_STATUS"exit "$PYTEST_STATUS"elseecho "annotations passed data checks."echofi}function mypy_examples_test {local MYPY_REPORT=local MYPY_STATUS=echo "starting mypy examples test..."MYPY_REPORT=$( (MYPYPATH=python $MYPY_BUILD \--python-executable $PYTHON_EXECUTABLE \--namespace-packages \--config-file python/mypy.ini \--exclude "mllib/*" \examples/src/main/python/) 2>&1)MYPY_STATUS=$?if [ "$MYPY_STATUS" -ne 0 ]; thenecho "examples failed mypy checks:"echo "$MYPY_REPORT"echo "$MYPY_STATUS"exit "$MYPY_STATUS"elseecho "examples passed mypy checks."echofi}function mypy_test {if ! hash "$MYPY_BUILD" 2> /dev/null; thenecho "The $MYPY_BUILD command was not found. Skipping for now."returnfi_MYPY_VERSION=($($MYPY_BUILD --version))MYPY_VERSION="${_MYPY_VERSION[1]}"EXPECTED_MYPY="$(satisfies_min_version $MYPY_VERSION $MINIMUM_MYPY)"if [[ "$EXPECTED_MYPY" == "False" ]]; thenecho "The minimum mypy version needs to be $MINIMUM_MYPY. Your current version is $MYPY_VERSION. Skipping for now."returnfiif [[ "$MYPY_TEST" == "true" ]]; thenmypy_annotation_testfiif [[ "$MYPY_EXAMPLES_TEST" == "true" ]]; thenmypy_examples_testfiif [[ "$MYPY_DATA_TEST" == "true" ]]; thenmypy_data_testfi}function flake8_test {local FLAKE8_VERSION=local EXPECTED_FLAKE8=local FLAKE8_REPORT=local FLAKE8_STATUS=if ! hash "$FLAKE8_BUILD" 2> /dev/null; thenecho "The flake8 command was not found. Skipping for now."returnfi_FLAKE8_VERSION=($($FLAKE8_BUILD --version))FLAKE8_VERSION="${_FLAKE8_VERSION[0]}"EXPECTED_FLAKE8="$(satisfies_min_version $FLAKE8_VERSION $MINIMUM_FLAKE8)"if [[ "$EXPECTED_FLAKE8" == "False" ]]; thenecho "\The minimum flake8 version needs to be $MINIMUM_FLAKE8. Your current version is $FLAKE8_VERSIONflake8 checks failed."exit 1fiecho "starting $FLAKE8_BUILD test..."FLAKE8_REPORT=$( ($FLAKE8_BUILD --append-config dev/tox.ini --count --show-source --statistics .) 2>&1)FLAKE8_STATUS=$?if [ "$FLAKE8_STATUS" -ne 0 ]; thenecho "flake8 checks failed:"echo "$FLAKE8_REPORT"echo "$FLAKE8_STATUS"exit "$FLAKE8_STATUS"elseecho "flake8 checks passed."echofi}function ruff_test {local RUFF_VERSION=local EXPECTED_RUFF=local RUFF_REPORT=local RUFF_STATUS=if ! hash "$RUFF_BUILD" 2> /dev/null; thenecho "The ruff command was not found. Skipping for now."returnfi_RUFF_VERSION=($($RUFF_BUILD --version))RUFF_VERSION="${_RUFF_VERSION[1]}"EXPECTED_RUFF="$(satisfies_min_version $RUFF_VERSION $MINIMUM_RUFF)"if [[ "$EXPECTED_RUFF" == "False" ]]; thenecho "\The minimum ruff version needs to be $MINIMUM_RUFF. Your current version is $RUFF_VERSIONruff checks failed."exit 1fiecho "starting $RUFF_BUILD test..."RUFF_REPORT=$( ($RUFF_BUILD check) 2>&1)RUFF_STATUS=$?if [ "$RUFF_STATUS" -ne 0 ]; thenecho "ruff checks failed:"echo "$RUFF_REPORT"echo "$RUFF_STATUS"exit "$RUFF_STATUS"elseecho "ruff checks passed."echofiRUFF_REPORT=$( ($RUFF_BUILD format --diff python/pyspark dev python/packaging python/benchmarks) 2>&1)RUFF_STATUS=$?if [ "$RUFF_STATUS" -ne 0 ]; thenecho "ruff format checks failed:"echo "$RUFF_REPORT"echo "$RUFF_STATUS"exit "$RUFF_STATUS"elseecho "ruff format checks passed."echofi}function black_test {local BLACK_REPORT=local BLACK_STATUS=# Skip check if black is not installed.$PYTHON_EXECUTABLE -c 'import black' &> /dev/nullif [ $? -ne 0 ]; thenecho "The Python library providing 'black' module was not found. Skipping black checks for now."echoreturnfiecho "starting black test..."BLACK_REPORT=$( ($BLACK_BUILD --check python/pyspark dev python/packaging python/benchmarks) 2>&1)BLACK_STATUS=$?if [ "$BLACK_STATUS" -ne 0 ]; thenecho "black checks failed:"echo "$BLACK_REPORT"echo "Please run 'dev/reformat-python' script."echo "$BLACK_STATUS"exit "$BLACK_STATUS"elseecho "black checks passed."echofi}function pyspark_custom_errors_check_test {local PYSPARK_CUSTOM_ERRORS_CHECK_REPORT=local PYSPARK_CUSTOM_ERRORS_CHECK_STATUS=echo "starting PySpark custom errors check..."PYSPARK_CUSTOM_ERRORS_CHECK_REPORT=$( "$PYTHON_EXECUTABLE" dev/check_pyspark_custom_errors.py 2>&1 )PYSPARK_CUSTOM_ERRORS_CHECK_STATUS=$?if [ "$PYSPARK_CUSTOM_ERRORS_CHECK_STATUS" -ne 0 ]; thenecho "PySpark custom errors check failed!"echo "$PYSPARK_CUSTOM_ERRORS_CHECK_REPORT"exit "$PYSPARK_CUSTOM_ERRORS_CHECK_STATUS"elseecho "PySpark custom errors check passed."echofi}SCRIPT_DIR="$( cd "$( dirname "0ドル" )" && pwd )"SPARK_ROOT_DIR="$(dirname "${SCRIPT_DIR}")"pushd "$SPARK_ROOT_DIR" &> /dev/nullPYTHON_SOURCE="$(git ls-files '*.py')"if [[ "$COMPILE_TEST" == "true" ]]; thencompile_python_test "$PYTHON_SOURCE"fiif [[ "$BLACK_TEST" == "true" ]]; thenblack_testfiif [[ "$PYSPARK_CUSTOM_ERRORS_CHECK_TEST" == "true" ]]; thenpyspark_custom_errors_check_testfiif [[ "$FLAKE8_TEST" == "true" ]]; thenflake8_testfiif [[ "$RUFF_TEST" == "true" ]]; thenruff_testfiif [[ "$MYPY_TEST" == "true" ]] || [[ "$MYPY_EXAMPLES_TEST" == "true" ]] || [[ "$MYPY_DATA_TEST" == "true" ]]; thenmypy_testfiechoecho "all lint-python tests passed!"popd &> /dev/null
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
1. 开源生态
2. 协作、人、软件
3. 评估模型