Skip to content

Commit

Permalink
🧪💅 Output JSON+text reports in MyPy
Browse files Browse the repository at this point in the history
This patch also integrates displaying them in GitHub Actions
job summary.
  • Loading branch information
webknjaz committed Oct 3, 2024
1 parent 4b19be2 commit 47ec42e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 3 deletions.
18 changes: 15 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,13 @@ repos:
- types-requests
args:
- --python-version=3.13
- --txt-report=.tox/.tmp/.test-results/mypy--py-3.13
- --any-exprs-report=.tox/.tmp/.test-results/mypy--py-3.13
- --cobertura-xml-report=.tox/.tmp/.test-results/mypy--py-3.13
- --html-report=.tox/.tmp/.test-results/mypy--py-3.13
- --linecount-report=.tox/.tmp/.test-results/mypy--py-3.13
- --linecoverage-report=.tox/.tmp/.test-results/mypy--py-3.13
- --lineprecision-report=.tox/.tmp/.test-results/mypy--py-3.13
- --txt-report=.tox/.tmp/.test-results/mypy--py-3.13
pass_filenames: false
- id: mypy
alias: mypy-py312
Expand All @@ -229,9 +233,13 @@ repos:
- types-requests
args:
- --python-version=3.12
- --txt-report=.tox/.tmp/.test-results/mypy--py-3.12
- --any-exprs-report=.tox/.tmp/.test-results/mypy--py-3.12
- --cobertura-xml-report=.tox/.tmp/.test-results/mypy--py-3.12
- --html-report=.tox/.tmp/.test-results/mypy--py-3.12
- --linecount-report=.tox/.tmp/.test-results/mypy--py-3.12
- --linecoverage-report=.tox/.tmp/.test-results/mypy--py-3.12
- --lineprecision-report=.tox/.tmp/.test-results/mypy--py-3.12
- --txt-report=.tox/.tmp/.test-results/mypy--py-3.12
pass_filenames: false
- id: mypy
alias: mypy-py311
Expand All @@ -255,9 +263,13 @@ repos:
- types-requests
args:
- --python-version=3.11
- --txt-report=.tox/.tmp/.test-results/mypy--py-3.11
- --any-exprs-report=.tox/.tmp/.test-results/mypy--py-3.11
- --cobertura-xml-report=.tox/.tmp/.test-results/mypy--py-3.11
- --html-report=.tox/.tmp/.test-results/mypy--py-3.11
- --linecount-report=.tox/.tmp/.test-results/mypy--py-3.11
- --linecoverage-report=.tox/.tmp/.test-results/mypy--py-3.11
- --lineprecision-report=.tox/.tmp/.test-results/mypy--py-3.11
- --txt-report=.tox/.tmp/.test-results/mypy--py-3.11
pass_filenames: false

- repo: https://github.com/PyCQA/pylint.git
Expand Down
30 changes: 30 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,33 @@ commands_post =
); \
print("codecov-flags=MyPy", file=gh_output_fd); \
gh_output_fd.close()'
{envpython} \
{[python-cli-options]byte-errors} \
{[python-cli-options]max-isolation} \
{[python-cli-options]warnings-to-errors} \
-c \
'import itertools, os, pathlib, shlex, sys; \
os.getenv("GITHUB_ACTIONS") == "true" or sys.exit(); \
test_results_dir = pathlib.Path(r"{temp_dir}") / ".test-results"; \
text_and_json_reports = itertools.chain( \
test_results_dir.glob("mypy--py-*{/}*.json"), \
test_results_dir.glob("mypy--py-*{/}*.txt"), \
); \
report_contents = { \
report{:} report.read_text() \
for report in text_and_json_reports \
}; \
reports_summary_text_blob = "\n\n".join( \
f"\N\{NUMBER SIGN\}\N\{NUMBER SIGN\} {report_path.parent.name}{:} " \
f"`{report_path.name}`\n\n" \
f"```{report_path.suffix[1:]}\n{report_text}\n```\n" \
for report_path, report_text in report_contents.items() \
); \
gh_summary_fd = open( \
os.environ["GITHUB_STEP_SUMMARY"], encoding="utf-8", mode="a", \
); \
print(reports_summary_text_blob, file=gh_summary_fd); \
gh_summary_fd.close()'
# Print out the output coverage dir and a way to serve html:
{envpython} \
{[python-cli-options]byte-errors} \
Expand Down Expand Up @@ -273,6 +300,9 @@ commands_post =
print(\
f"\nTo open the HTML coverage reports, run\n\n\
\t\{coverage_html_report_open_cmds_blob !s\}\n"\
); \
print(\
f"[*] Find rest of JSON and text reports, are in the same directories."\
)\
' \
{posargs:--all-files}
Expand Down

0 comments on commit 47ec42e

Please sign in to comment.