Skip to content

Commit f6fd3f7

Browse files
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 <bernhard.kaindl@cloud.com>
1 parent 7ac38f2 commit f6fd3f7

File tree

2 files changed

+32
-48
lines changed

2 files changed

+32
-48
lines changed

.pre-commit-config.yaml

Lines changed: 22 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
# https://github.com/dexpota/cheatsheets/blob/master/pre-commit
3838
exclude: "^tests/data"
3939
fail_fast: true
40-
default_stages: [commit]
40+
default_stages: [pre-commit]
4141
repos:
4242
- repo: local
4343
hooks:
@@ -47,7 +47,7 @@ repos:
4747
types: [binary]
4848
language: fail
4949
- repo: https://github.com/pre-commit/pre-commit-hooks
50-
rev: v4.6.0
50+
rev: v6.0.0
5151
hooks:
5252
- id: no-commit-to-branch
5353
args: [--branch, master]
@@ -62,76 +62,55 @@ repos:
6262
- isort
6363

6464

65+
- repo: https://github.com/pre-commit/pygrep-hooks
66+
rev: v1.10.0 # Use the ref you want to point at
67+
hooks:
68+
# Enforce that `# type: ignore` annotations always occur with specific codes.
69+
# Sample annotation: # type: ignore[attr-defined,name-defined]
70+
- id: python-check-blanket-type-ignore
71+
72+
6573
- repo: https://github.com/pre-commit/mirrors-mypy
66-
rev: v1.10.0
74+
rev: v1.17.1
6775
hooks:
6876
- id: mypy
6977
additional_dependencies:
78+
- pyfakefs
79+
- pytest_httpserver
7080
- pytest-subprocess
7181
- types-mock
7282
- types-six
7383
- types-toml
7484

7585

7686
- repo: https://github.com/rcmdnk/pyproject-pre-commit
77-
rev: v0.1.9
87+
rev: v0.4.2
7888
hooks:
7989
- id: shellcheck
8090

8191

8292
- repo: https://github.com/igorshubovych/markdownlint-cli
83-
rev: v0.42.0
93+
rev: v0.45.0
8494
hooks:
8595
- id: markdownlint
8696

8797

88-
- repo: https://github.com/pycqa/pylint
89-
rev: v2.17.4
90-
hooks:
91-
- id: pylint
92-
args:
93-
[
94-
-sn, # Don't display the score
95-
--load-plugins=pylint.extensions.eq_without_hash,
96-
--ignore-imports=yes,
97-
"--disable=duplicate-code,line-too-long",
98-
]
99-
log_file: ".git/pre-commit-pylint.log"
100-
additional_dependencies:
101-
- pyfakefs
102-
- six
103-
- mock
104-
- pandas
105-
- pytest_forked
106-
- toml
10798
- repo: local
10899
hooks:
109-
- id: pytype
110-
name: pytype (may take up to two minutes)
111-
entry: sh -c "pytype >/dev/tty"
112-
types: [python]
113-
verbose: true
114-
language: python
115-
language_version: python3.8
116-
require_serial: true
117-
additional_dependencies: [pytype]
118-
- id: pytest
119-
name: Check pytest unit tests pass
100+
- id: tox
101+
name: pytest unit tests and static analysis using tox
120102
types: [python]
121103
# entry: sh -c "pytest -x -rf --new-first --show-capture=all >/dev/tty"
122-
entry: sh -c "tox -e py38-covcombine >/dev/tty"
104+
entry: sh -c "tox -e py311-cov-check-pytype-pyright-lint-mdreport >/dev/tty"
123105
verbose: true
124106
language: python
125107
require_serial: true
126108
pass_filenames: false
127-
- repo: https://github.com/pre-commit/pygrep-hooks
128-
rev: v1.10.0 # Use the ref you want to point at
129-
hooks:
130-
# Enforce that `# type: ignore` annotations always occur with specific codes.
131-
# Sample annotations: # type: ignore[attr-defined] # type: ignore[attr-defined,name-defined]
132-
- id: python-check-blanket-type-ignore
109+
additional_dependencies: [tox]
110+
111+
133112
- repo: https://github.com/pre-commit/pre-commit-hooks
134-
rev: v4.6.0
113+
rev: v6.0.0
135114
hooks:
136115
- id: trailing-whitespace
137116
- id: end-of-file-fixer

pylint_runner.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -227,10 +227,12 @@ def write_results_as_markdown_tables(branch_url, fp, panda_overview, panda_resul
227227
me = os.path.basename(__file__)
228228
mylink = f"[{me}]({branch_url}/{me})"
229229
# https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#multiline-markdown-content
230-
fp.write(f"### PyLint breakdown from {mylink} on **xcp/\\*\\*/*.py**\n")
230+
fp.write(f"### PyLint summary (by {mylink})\n")
231231
fp.write(panda_overview.to_markdown())
232-
fp.write(f"\n### PyLint results from {mylink} on **xcp/\\*\\*/*.py**\n")
233-
fp.write(panda_results.to_markdown())
232+
fp.write("\n")
233+
if not panda_results.empty:
234+
fp.write("### PyLint results\n")
235+
fp.write(panda_results.to_markdown())
234236

235237

236238
if __name__ == "__main__":
@@ -242,7 +244,7 @@ def write_results_as_markdown_tables(branch_url, fp, panda_overview, panda_resul
242244
branch = os.environ.get("GITHUB_HEAD_REF", None) or os.environ.get("GITHUB_REF_NAME", None)
243245
ghblob_url = f"{server_url}/{repository}/blob/{branch}"
244246

245-
# Like the previous run-pylint.sh, check the xcp module by default:
247+
# By default, run pylint on xcp/ and tests/
246248
dirs_to_check = sys.argv[1:] if len(sys.argv) > 1 else ["xcp", "tests"]
247249

248250
# 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
255257
#
256258
pylint_txt = os.environ.get("ENVLOGDIR", ".tox") + "/pylint.txt"
257259

258-
print("Checking:", str(dirs_to_check) + "; Writing report to:", step_summary)
260+
print("Checking:", " ".join(dirs_to_check) + ". Writing report to:", step_summary)
259261
main(dirs_to_check, step_summary, pylint_txt, ghblob_url)
262+
# Show the report
263+
with open(step_summary, "r", encoding="utf-8") as fp:
264+
print(fp.read())

0 commit comments

Comments
 (0)