From f28d2be2e716ab21efbcb693fe3e3dcf358c4e7a Mon Sep 17 00:00:00 2001 From: Scott Todd Date: Mon, 3 Jun 2024 10:45:03 -0700 Subject: [PATCH 1/2] Remove pytype lint check. Could also remove `pytype: disable=` annotations and related comments. --- .github/workflows/lint.yml | 15 ------ .pre-commit-config.yaml | 2 + build_tools/pytype/check_diff.sh | 84 -------------------------------- build_tools/scripts/lint.sh | 3 -- 4 files changed, 2 insertions(+), 102 deletions(-) delete mode 100755 build_tools/pytype/check_diff.sh diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index c72d05962e4e..6e5d61bcb408 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -47,21 +47,6 @@ jobs: git diff --exit-code exit "${EXIT_CODE?}" - 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 0406c803e887..1cec51f78a13 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -94,6 +94,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 From 52601580802cd9b06e972bd770eae5f10595eda0 Mon Sep 17 00:00:00 2001 From: Scott Todd Date: Fri, 7 Jun 2024 14:17:10 -0700 Subject: [PATCH 2/2] Fix merge - remove buildifier lint step. --- .github/workflows/lint.yml | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 6e5d61bcb408..3e08dd2da2f2 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -24,29 +24,6 @@ jobs: - name: Running pre-commit uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1 - buildifier: - runs-on: ubuntu-20.04 - steps: - - name: Checking out repository - uses: actions/checkout@8f4b7f84864484a7bf31766abe9204da3cbe65b3 # v3.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: Downloading Buildifier - run: | - mkdir -p "${HOME?}/bin" - wget https://github.com/bazelbuild/buildtools/releases/download/4.0.1/buildifier -O "${HOME?}/bin/buildifier" - chmod +x "${HOME?}/bin/buildifier" - echo "${HOME?}/bin" >> $GITHUB_PATH - - name: Running buildifier on changed files - run: | - # Fail if the script fails (unfixable lint warnings) or it creates a - # diff (fixable lint warnings or formatting). - EXIT_CODE=0 - ./build_tools/scripts/run_buildifier.sh "${GITHUB_BASE_REF?}" || EXIT_CODE=1 - git diff --exit-code - exit "${EXIT_CODE?}" - generated_cmake_files: runs-on: ubuntu-20.04 steps: