diff --git a/.github/workflows/buildAndTest.yml b/.github/workflows/buildAndTest.yml index 711f19a49e..99903f794b 100644 --- a/.github/workflows/buildAndTest.yml +++ b/.github/workflows/buildAndTest.yml @@ -8,13 +8,6 @@ on: types: [assigned, opened, synchronize, reopened] workflow_dispatch: -defaults: - run: - # This is already the default, except when running inside another Docker - # image, which is the case here. So set it up globally to avoid - # repeating elsewhere. - shell: bash - env: # Run apt package manager in the CI in non-interactive mode. # Otherwise, on Ubuntu 20.04 the installation of tzdata asking question @@ -53,11 +46,8 @@ jobs: run: | pip install cmake numpy psutil pybind11 rich pkginfo lit PyYAML - - name: Install Ninja - run: sudo apt-get install -y ninja-build - - - name: Install lld and clang (for aiecc) - run: sudo apt-get install -y clang lld + - name: Install packages + run: sudo apt-get install -y ninja-build clang lld - name: Get MLIR id: mlir-wheels @@ -68,7 +58,6 @@ jobs: echo "MLIR_DIR=$PWD/mlir" | tee -a $GITHUB_OUTPUT - name: Ccache for C++ compilation - # https://github.com/hendrikmuhs/ccache-action/releases/tag/v1.2.9 uses: hendrikmuhs/ccache-action@ca3acd2731eef11f1572ccb126356c2f9298d35e with: # Since there are now several compilation jobs running in parallel, @@ -139,7 +128,9 @@ jobs: ninja check-tutorials ninja check-reference-designs - clang-tidy: + clang-tidy-pylint: + + name: Python and C/C++ Lint runs-on: ubuntu-22.04 @@ -205,7 +196,6 @@ jobs: run: | git fetch origin main git diff -U0 origin/main | clang-tidy-diff -p1 -path build -export-fixes fixes.yml - cat fixes.yml - name: Post clang-tidy requests env: @@ -214,7 +204,7 @@ jobs: PULL_REQUEST_ID="$(jq "if (.issue.number != null) then .issue.number else .number end" < "$GITHUB_EVENT_PATH")" echo $PULL_REQUEST_ID - GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} python utils/git/clang-tidy-pr.py \ + GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }} python utils/git/clang_tidy_pr.py \ --clang-tidy-fixes fixes.yml \ --pull-request-id "$PULL_REQUEST_ID" \ --repository "$GITHUB_REPOSITORY" \ @@ -222,9 +212,141 @@ jobs: --request-changes "false" \ --suggestions-per-comment 10 + # You can feed the pylintrc path to ciborow/action-pylint + # but it doesn't seem to work. + - name: Copy pylintrcs + run: | + cp .pylintrc python/.pylintrc + cp .pylintrc test/python/.pylintrc + cp .pylintrc tutorials/.pylintrc + cp .pylintrc reference_designs/.pylintrc + cp .pylintrc utils/.pylintrc + + # You can just do this wholesale at the root (not use workdir) + # but it'll take too long because it picks up + # the stuff in the build directory. + - uses: dciborow/action-pylint@0.1.0 + env: + PYTHONPATH: build/python + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + reporter: github-pr-review + # GitHub Status Check won't become failure with warning. + level: warning + filter_mode: diff_context + workdir: python + glob_pattern: "**/*.py" + + - uses: dciborow/action-pylint@0.1.0 + env: + PYTHONPATH: build/python + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + reporter: github-pr-review + level: warning + filter_mode: diff_context + workdir: test/python + glob_pattern: "**/*.py" + + - uses: dciborow/action-pylint@0.1.0 + env: + PYTHONPATH: build/python + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + reporter: github-pr-review + level: warning + filter_mode: diff_context + workdir: tutorials + glob_pattern: "**/*.py" + + - uses: dciborow/action-pylint@0.1.0 + env: + PYTHONPATH: build/python + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + reporter: github-pr-review + level: warning + filter_mode: diff_context + workdir: reference_designs + glob_pattern: "**/*.py" + + - uses: dciborow/action-pylint@0.1.0 + env: + PYTHONPATH: build/python + with: + github_token: ${{ secrets.GITHUB_TOKEN }} + reporter: github-pr-review + level: warning + filter_mode: diff_context + workdir: utils + glob_pattern: "**/*.py" + + formatting: + + name: Python and C/C++ Formatting + + runs-on: ubuntu-latest + + permissions: + contents: write + pull-requests: write + + steps: + - name: Get the project repository + uses: actions/checkout@v3 + with: + fetch-depth: 2 + submodules: "true" + + - name: Install clang-format + uses: aminya/setup-cpp@v1 + with: + clangformat: 17.0.1 + + - name: Setup Python env + uses: actions/setup-python@v4 + with: + python-version: '3.11' + + - name: Install black + run: pip install black[jupyter] + + - name: Run git-clang-format + id: git-clang-format + run: | + git fetch origin main + # git clang-format returns an error if changes made? + git clang-format origin/main || true + + - name: Check C/C++ format + uses: reviewdog/action-suggester@v1 + with: + tool_name: clang-format + level: error + fail_on_error: true + cleanup: true + + - name: Run black format + if: success() || failure() + id: black-format + run: | + # FORMATTED=0 + black --exclude python/compiler/aiecc/main.py . || true + black -l 10000 python/compiler/aiecc/main.py || true + # FORMATTED=$(git status -s -uno | wc -l | xargs) + # echo "FORMATTED=$FORMATTED" | tee -a $GITHUB_OUTPUT + + - name: Check Python format + if: success() || failure() + uses: reviewdog/action-suggester@v1 + with: + tool_name: black + level: error + fail_on_error: true + code-coverage: - name: Code Coverage + name: C/C++ test code coverage runs-on: ubuntu-latest @@ -248,10 +370,7 @@ jobs: pip install cmake numpy psutil pybind11 rich lit - name: Install Ninja - run: sudo apt-get install -y ninja-build - - - name: Install llvm-cov - run: sudo apt-get install -y clang lld llvm + run: sudo apt-get install -y ninja-build clang lld llvm - name: Get changed files id: changed-files @@ -269,7 +388,6 @@ jobs: - name: Ccache for C++ compilation if: steps.changed-files.outputs.changed-files != '' - # https://github.com/hendrikmuhs/ccache-action/releases/tag/v1.2.9 uses: hendrikmuhs/ccache-action@ca3acd2731eef11f1572ccb126356c2f9298d35e with: key: ${{ runner.os }}-${{ matrix.ubuntu_version }}-${{ steps.get-llvm-commit-hash.outputs.hash }}-code-cov @@ -335,95 +453,3 @@ jobs: body-path: /home/runner/work/mlir-aie/mlir-aie/build_release/report/index.html edit-mode: replace - CppFormatting: - - runs-on: ubuntu-latest - - permissions: - contents: write - pull-requests: write - - steps: - - name: Get the project repository - uses: actions/checkout@v3 - with: - fetch-depth: 2 - submodules: "true" - - - name: Install clang-format - uses: aminya/setup-cpp@v1 - with: - clangformat: 17.0.1 - - - name: Setup Python env - uses: actions/setup-python@v4 - with: - python-version: '3.11' - - - name: Run git-clang-format - id: git-clang-format - run: | - git fetch origin main - FORMATTED=0 - git clang-format origin/main || FORMATTED=$? - echo "FORMATTED=$FORMATTED" | tee -a $GITHUB_OUTPUT - - - name: Annotate diff changes using reviewdog - if: steps.git-clang-format.outputs.FORMATTED != '0' - uses: reviewdog/action-suggester@v1 - with: - tool_name: clang-format - - - name: Fail - if: steps.git-clang-format.outputs.FORMATTED != '0' - run: | - exit 1 - - - PythonFormatting: - - runs-on: ubuntu-latest - - permissions: - contents: write - pull-requests: write - - steps: - - name: Get the project repository - uses: actions/checkout@v3 - with: - fetch-depth: 2 - submodules: "true" - - - name: Install clang-format - uses: aminya/setup-cpp@v1 - with: - clangformat: 17.0.1 - - - name: Setup Python env - uses: actions/setup-python@v4 - with: - python-version: '3.11' - - - name: Install black - run: pip install black - - - name: Run black format - id: black-format - run: | - FORMATTED=0 - black . || FORMATTED=$? - FORMATTED=$($FORMATTED || git status -s -uno | wc -l | xargs) - echo "FORMATTED=$FORMATTED" | tee -a $GITHUB_OUTPUT - git diff - - - name: Annotate diff changes using reviewdog - if: steps.black-format.outputs.FORMATTED != '0' - uses: reviewdog/action-suggester@v1 - with: - tool_name: black - - - name: Fail - if: steps.black-format.outputs.FORMATTED != '0' - run: | - exit 1 diff --git a/.pylintrc b/.pylintrc new file mode 100644 index 0000000000..3bf50480f7 --- /dev/null +++ b/.pylintrc @@ -0,0 +1,58 @@ +[MAIN] + +py-version=3.9 + +[BASIC] + +argument-naming-style=snake_case +attr-naming-style=snake_case +bad-names=foo, + bar, + baz, + toto, + tutu, + tata + +class-attribute-naming-style=snake_case +class-const-naming-style=UPPER_CASE +class-naming-style=PascalCase +const-naming-style=UPPER_CASE +docstring-min-length=-1 +function-naming-style=snake_case +include-naming-hint=yes +inlinevar-naming-style=snake_case +method-naming-style=snake_case +module-naming-style=snake_case +variable-naming-style=snake_case + +[CLASSES] + +valid-classmethod-first-arg=cls +valid-metaclass-classmethod-first-arg=mcs + +[IMPORTS] + +allow-wildcard-with-all=no + +[SIMILARITIES] + +# Minimum lines number of a similarity. +min-similarity-lines=4 + +[STRING] + +# This flag controls whether inconsistent-quotes generates a warning when the +# character used as a quote delimiter is used inconsistently within a module. +check-quote-consistency=yes + +# This flag controls whether the implicit-str-concat should generate a warning +# on implicit string concatenation in sequences defined over several lines. +check-str-concat-over-line-jumps=yes + +[MESSAGES CONTROL] + +# C0116: Missing function or method docstring (missing-function-docstring) +# C0114: Missing module docstring (missing-module-docstring) +# E0402: Attempted relative import beyond top-level package (relative-beyond-top-level) +# C0115: Missing class docstring (missing-class-docstring) +disable=C0116,C0114,E0402,C0115 \ No newline at end of file diff --git a/python/util.py b/python/util.py index 423baa7118..3dfa55399c 100644 --- a/python/util.py +++ b/python/util.py @@ -62,10 +62,10 @@ def infer_mlir_type( elif 2 ** 63 <= py_val < 2 ** 64: return T.ui64() else: - raise RuntimeError(f"Nonrepresentable integer {py_val}.") + raise RuntimeError(f'Nonrepresentable integer {py_val}.') elif isinstance(py_val, float): if ( - abs(py_val) == float("inf") + abs(py_val) == float('inf') or abs(py_val) == 0.0 or py_val != py_val # NaN or np.finfo(np.float32).min <= abs(py_val) <= np.finfo(np.float32).max @@ -78,7 +78,7 @@ def infer_mlir_type( return RankedTensorType.get(py_val.shape, dtype) else: raise NotImplementedError( - f"Unsupported Python value {py_val=} with type {type(py_val)}" + f'Unsupported Python value {py_val=} with type {type(py_val)}' ) @@ -119,3 +119,7 @@ def mlir_mod_ctx( ip = InsertionPoint(module.body) stack.enter_context(ip) yield MLIRContext(context, module) + + +def bad_function_with_list_default_args(a=[]): + return a[0] diff --git a/test/python/aie_ops.py b/test/python/aie_ops.py index c8fd622ed3..217737e3a6 100644 --- a/test/python/aie_ops.py +++ b/test/python/aie_ops.py @@ -268,3 +268,8 @@ def test_module_context(): test_module_context() + + +def second_bad_function_with_unused_stuff(a): + b = 1 + return 2 diff --git a/utils/git/clang-tidy-pr.py b/utils/git/clang_tidy_pr.py similarity index 99% rename from utils/git/clang-tidy-pr.py rename to utils/git/clang_tidy_pr.py index 2bd0e9c240..2d31ba0105 100644 --- a/utils/git/clang-tidy-pr.py +++ b/utils/git/clang_tidy_pr.py @@ -535,7 +535,7 @@ def main(): github_api_timeout = 10 warning_comment_prefix = ( - ":warning: `Clang-Tidy` found issue(s) with the introduced code" + "# :warning: `Clang-Tidy` found issue(s) with the introduced code" ) diff_lines_per_file = get_diff_lines_per_file( diff --git a/utils/requirements.txt b/utils/requirements.txt index 6ce53a69db..c6160d72d7 100644 --- a/utils/requirements.txt +++ b/utils/requirements.txt @@ -3,3 +3,4 @@ rich pybind11 numpy cmake +pylint \ No newline at end of file