diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 4cfef3a53d79..3e08dd2da2f2 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -24,21 +24,6 @@ jobs: - name: Running pre-commit uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1 - pytype: - runs-on: ubuntu-20.04 - steps: - - name: Checking out repository - uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # v3.5.0 - - name: Setting up python - uses: actions/setup-python@d27e3f3d7c64b4bbf8e4abfb9b63b83e846e0435 # v4.5.0 - - name: Fetching Base Branch - # We have to explicitly fetch the base branch as well - run: git fetch --no-tags --prune --depth=1 origin "${GITHUB_BASE_REF?}:${GITHUB_BASE_REF?}" - - name: Install pytype - run: python3 -m pip install pytype - - name: Run pytype on changed files - run: ./build_tools/pytype/check_diff.sh "${GITHUB_BASE_REF?}" - generated_cmake_files: runs-on: ubuntu-20.04 steps: diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index bb011ad4ec3d..317a560980a1 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -107,6 +107,8 @@ repos: language: fail files: "BUILD$" + # TODO(scotttodd): mypy type checking for Python (https://mypy-lang.org/) + # TODO(scotttodd): enable these checks when they work on Windows # the generator scripts use \ on Windows instead of / diff --git a/build_tools/pytype/check_diff.sh b/build_tools/pytype/check_diff.sh deleted file mode 100755 index c8122448d48a..000000000000 --- a/build_tools/pytype/check_diff.sh +++ /dev/null @@ -1,84 +0,0 @@ -#!/bin/bash -# Copyright 2020 The IREE Authors -# -# Licensed under the Apache License v2.0 with LLVM Exceptions. -# See https://llvm.org/LICENSE.txt for license information. -# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception - -# Uses git diff to run pytype on changed files. -# Example Usage: -# Defaults to comparing against 'main'. -# ./build_tools/pytype/check_diff.sh -# A specific branch can be specified. -# ./build_tools/pytype/check_diff.sh some-other-branch -# Or all python files outside of './third_party/' can be checked. -# ./build_tools/pytype/check_diff.sh all - -DIFF_TARGET="${1:-main}" -echo "Running pycheck against '${DIFF_TARGET?}'" - -if [[ "${DIFF_TARGET?}" = "all" ]]; then - # Exclude third_party files and some directories that we add to .gitignore - FILES=$(find -name "*\.py" \ - -not -path "./third_party/*" \ - -not -path ".venv/*" \ - -not -path "*.venv/*" \ - -not -path "./build/*" \ - -not -path "./build-*/*") -else - FILES=$(git diff --diff-filter=d --name-only "${DIFF_TARGET?}" | grep '.*\.py$' | grep -vP 'lit.cfg.py') -fi - - -# We seperate the python files into multiple pytype calls because otherwise -# Ninja gets confused. See https://github.com/google/pytype/issues/198 -BASE=$(echo "${FILES?}" | \ - grep -vP '^(\./)?integrations/*$' | \ - grep -vP '(\./)?setup\.py$') -INTEGRATIONS=$(echo "${FILES?}" | \ - grep -P '^(\./)?integrations/.*') - -function check_files() { - # $1: previous return code - # $2...: files to check - if [[ -z "${@:2}" ]]; then - echo "No files to check." - echo - return "${1?}" - fi - - # We disable import-error and module-attr because pytype doesn't have access - # to all dependencies and pyi-error because of the way the bindings imports - # work. - # xargs is set to high arg limits to avoid multiple pytype invocations and - # will hard fail if the limits are exceeded. - # See https://github.com/bazelbuild/bazel/issues/12479 - echo "${@:2}" | \ - xargs --max-args 1000000 --max-chars 1000000 \ - python3 -m pytype --disable=import-error,pyi-error,module-attr -j $(nproc) - EXIT_CODE="$?" - echo - if [[ "${EXIT_CODE?}" -gt "${1?}" ]]; then - return "${EXIT_CODE?}" - else - return "${1?}" - fi -} - -MAX_CODE=0 - -echo "Checking .py files outside of integrations/" -check_files "${MAX_CODE?}" "${BASE?}" -MAX_CODE="$?" - -echo "Checking .py files in integrations/.*" -check_files "${MAX_CODE?}" "${INTEGRATIONS?}" -MAX_CODE="$?" - - -if [[ "${MAX_CODE?}" -ne "0" ]]; then - echo "One or more pytype checks failed." - echo "You can view these errors locally by running" - echo " ./build_tools/pytype/check_diff.sh ${DIFF_TARGET?}" - exit "${MAX_CODE?}" -fi diff --git a/build_tools/scripts/lint.sh b/build_tools/scripts/lint.sh index b34a36daade9..8881f65a5b6f 100755 --- a/build_tools/scripts/lint.sh +++ b/build_tools/scripts/lint.sh @@ -51,9 +51,6 @@ echo "***** buildifier *****" ${scripts_dir}/run_buildifier.sh git diff --exit-code -echo "***** pytype *****" -./build_tools/pytype/check_diff.sh - echo "***** Generates CMake files *****" ./build_tools/scripts/generate_cmake_files.sh git add -A