From 2cb0444b2c54862357b93ec8b905314cc1125510 Mon Sep 17 00:00:00 2001 From: Bernhard Kaindl Date: Mon, 18 Aug 2025 12:00:00 +0200 Subject: [PATCH] commit checks: Consolidate pylint and pytype environments using tox Consolidate the pylint and pytype environments using tox: Other included changes in .pre-commit-config.yaml: - Update hook versions and mypy dependencies - Early checking for blanket type ignore comments Also cleanup the output of the pylint report generator. Signed-off-by: Bernhard Kaindl --- .pre-commit-config.yaml | 65 ++++++++++++++--------------------------- pylint_runner.py | 15 ++++++---- 2 files changed, 32 insertions(+), 48 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 917040ce..ac73ec2b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -37,7 +37,7 @@ # https://github.com/dexpota/cheatsheets/blob/master/pre-commit exclude: "^tests/data" fail_fast: true -default_stages: [commit] +default_stages: [pre-commit] repos: - repo: local hooks: @@ -47,7 +47,7 @@ repos: types: [binary] language: fail - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.6.0 + rev: v6.0.0 hooks: - id: no-commit-to-branch args: [--branch, master] @@ -62,11 +62,21 @@ repos: - isort +- repo: https://github.com/pre-commit/pygrep-hooks + rev: v1.10.0 # Use the ref you want to point at + hooks: + # Enforce that `# type: ignore` annotations always occur with specific codes. + # Sample annotation: # type: ignore[attr-defined,name-defined] + - id: python-check-blanket-type-ignore + + - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.10.0 + rev: v1.17.1 hooks: - id: mypy additional_dependencies: + - pyfakefs + - pytest_httpserver - pytest-subprocess - types-mock - types-six @@ -74,64 +84,33 @@ repos: - repo: https://github.com/rcmdnk/pyproject-pre-commit - rev: v0.1.9 + rev: v0.4.2 hooks: - id: shellcheck - repo: https://github.com/igorshubovych/markdownlint-cli - rev: v0.42.0 + rev: v0.45.0 hooks: - id: markdownlint -- repo: https://github.com/pycqa/pylint - rev: v2.17.4 - hooks: - - id: pylint - args: - [ - -sn, # Don't display the score - --load-plugins=pylint.extensions.eq_without_hash, - --ignore-imports=yes, - "--disable=duplicate-code,line-too-long", - ] - log_file: ".git/pre-commit-pylint.log" - additional_dependencies: - - pyfakefs - - six - - mock - - pandas - - pytest_forked - - toml - repo: local hooks: - - id: pytype - name: pytype (may take up to two minutes) - entry: sh -c "pytype >/dev/tty" - types: [python] - verbose: true - language: python - language_version: python3.8 - require_serial: true - additional_dependencies: [pytype] - - id: pytest - name: Check pytest unit tests pass + - id: tox + name: pytest unit tests and static analysis using tox types: [python] # entry: sh -c "pytest -x -rf --new-first --show-capture=all >/dev/tty" - entry: sh -c "tox -e py38-covcombine >/dev/tty" + entry: sh -c "tox -e py311-cov-check-pytype-pyright-lint-mdreport >/dev/tty" verbose: true language: python require_serial: true pass_filenames: false -- repo: https://github.com/pre-commit/pygrep-hooks - rev: v1.10.0 # Use the ref you want to point at - hooks: - # Enforce that `# type: ignore` annotations always occur with specific codes. - # Sample annotations: # type: ignore[attr-defined] # type: ignore[attr-defined,name-defined] - - id: python-check-blanket-type-ignore + additional_dependencies: [tox] + + - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.6.0 + rev: v6.0.0 hooks: - id: trailing-whitespace - id: end-of-file-fixer diff --git a/pylint_runner.py b/pylint_runner.py index b013f66f..5edb7cfd 100755 --- a/pylint_runner.py +++ b/pylint_runner.py @@ -227,10 +227,12 @@ def write_results_as_markdown_tables(branch_url, fp, panda_overview, panda_resul me = os.path.basename(__file__) mylink = f"[{me}]({branch_url}/{me})" # https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#multiline-markdown-content - fp.write(f"### PyLint breakdown from {mylink} on **xcp/\\*\\*/*.py**\n") + fp.write(f"### PyLint summary (by {mylink})\n") fp.write(panda_overview.to_markdown()) - fp.write(f"\n### PyLint results from {mylink} on **xcp/\\*\\*/*.py**\n") - fp.write(panda_results.to_markdown()) + fp.write("\n") + if not panda_results.empty: + fp.write("### PyLint results\n") + fp.write(panda_results.to_markdown()) if __name__ == "__main__": @@ -242,7 +244,7 @@ def write_results_as_markdown_tables(branch_url, fp, panda_overview, panda_resul branch = os.environ.get("GITHUB_HEAD_REF", None) or os.environ.get("GITHUB_REF_NAME", None) ghblob_url = f"{server_url}/{repository}/blob/{branch}" - # Like the previous run-pylint.sh, check the xcp module by default: + # By default, run pylint on xcp/ and tests/ dirs_to_check = sys.argv[1:] if len(sys.argv) > 1 else ["xcp", "tests"] # https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#adding-a-job-summary @@ -255,5 +257,8 @@ def write_results_as_markdown_tables(branch_url, fp, panda_overview, panda_resul # pylint_txt = os.environ.get("ENVLOGDIR", ".tox") + "/pylint.txt" - print("Checking:", str(dirs_to_check) + "; Writing report to:", step_summary) + print("Checking:", " ".join(dirs_to_check) + ". Writing report to:", step_summary) main(dirs_to_check, step_summary, pylint_txt, ghblob_url) + # Show the report + with open(step_summary, "r", encoding="utf-8") as fp: + print(fp.read())