Skip to content

Commit 92fbec7

Browse files
MaxymVlasovyermulnikwebknjaz
authored
docs: Simplify undestanding what's going on (#750)
--------- Co-authored-by: George L. Yermulnik <[email protected]> Co-authored-by: 🇺🇦 Sviatoslav Sydorenko (Святослав Сидоренко) <[email protected]>
1 parent a98f23c commit 92fbec7

File tree

4 files changed

+53
-9
lines changed

4 files changed

+53
-9
lines changed

.github/CONTRIBUTING.md

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
# Notes for contributors
22

3-
1. Python hooks are supported now too. All you have to do is:
4-
1. add a line to the `console_scripts` array in `entry_points` in `setup.py`
5-
2. Put your python script in the `pre_commit_hooks` folder
6-
7-
Enjoy the clean, valid, and documented code!
8-
93
* [Run and debug hooks locally](#run-and-debug-hooks-locally)
104
* [Run hook performance test](#run-hook-performance-test)
115
* [Run via BASH](#run-via-bash)
@@ -18,6 +12,7 @@ Enjoy the clean, valid, and documented code!
1812
* [Prepare basic documentation](#prepare-basic-documentation)
1913
* [Add code](#add-code)
2014
* [Finish with the documentation](#finish-with-the-documentation)
15+
* [Contributing to Python code](#contributing-to-python-code)
2116

2217
## Run and debug hooks locally
2318

@@ -152,5 +147,38 @@ You can use [this PR](https://github.com/antonbabenko/pre-commit-terraform/pull/
152147
153148
### Finish with the documentation
154149
155-
1. Add hook description to [Available Hooks](../README.md#available-hooks).
150+
1. Add the hook description to [Available Hooks](../README.md#available-hooks).
156151
2. Create and populate a new hook section in [Hooks usage notes and examples](../README.md#hooks-usage-notes-and-examples).
152+
153+
## Contributing to Python code
154+
155+
1. [Install `tox`](https://tox.wiki/en/stable/installation.html)
156+
2. To run tests, run:
157+
158+
```bash
159+
tox -qq
160+
```
161+
162+
The easiest way to find out what parts of the code base are left uncovered, is to copy-paste and run the `python3 ...` command that will open the HTML report, so you can inspect it visually.
163+
164+
3. Before committing any changes (if you do not have `pre-commit` installed locally), run:
165+
166+
```bash
167+
tox r -qq -e pre-commit
168+
```
169+
170+
Make sure that all checks pass.
171+
172+
4. (Optional): If you want to limit the checks to MyPy only, you can run:
173+
174+
```bash
175+
tox r -qq -e pre-commit -- mypy --all-files
176+
```
177+
178+
Then copy-paste and run the `python3 ...` commands to inspect the strictest MyPy coverage reports visually.
179+
180+
5. (Optional): You can find all available `tox` environments by running:
181+
182+
```bash
183+
tox list
184+
```

.github/workflows/reusable-tox.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,9 @@ jobs:
297297
--quiet
298298
--
299299
python -Im pre_commit install-hooks
300+
# Create GHA Job Summary markdown table of the coverage report
301+
# But only for 'pytest' env in 'tox'.
302+
# For details: ../../tox.ini '[testenv:pytest]' 'commands_post'
300303
- name: >-
301304
Run tox envs: `${{ env.TOXENV }}`
302305
id: tox-run
@@ -313,6 +316,7 @@ jobs:
313316
&& format('-- {0}', inputs.tox-run-posargs)
314317
|| ''
315318
}}
319+
# Generate nice SVG image of passed/failed tests in GHA Job Summary
316320
- name: Produce markdown test summary from JUnit
317321
if: >-
318322
!cancelled()

pytest.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ doctest_optionflags = ALLOW_UNICODE ELLIPSIS
4343
empty_parameter_set_mark = xfail
4444

4545
faulthandler_timeout = 30
46-
46+
# Turn all warnings into errors
4747
filterwarnings =
4848
error
4949

tox.ini

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ warnings-to-errors = -Werror
1414
description = Run pytest under {envpython}
1515
dependency_groups =
1616
testing
17+
18+
# In:
19+
# 'tox run -e py -- --lf', 'tox run -- --lf', 'tox run -e py313,py312 -- --lf'
20+
# '{posargs}' (positional arguments) == '--lf'
1721
commands =
1822
{envpython} \
1923
{[python-cli-options]byte-errors} \
@@ -23,6 +27,9 @@ commands =
2327
{tty:--color=yes} \
2428
{posargs:--cov-report=html:{envtmpdir}{/}htmlcov{/}}
2529
commands_post =
30+
# Create GHA Job Summary markdown table of the coverage report
31+
# https://github.blog/news-insights/product-news/supercharging-github-actions-with-job-summaries/
32+
# a leading '-' suppresses non-zero return codes
2633
-{envpython} \
2734
{[python-cli-options]byte-errors} \
2835
{[python-cli-options]max-isolation} \
@@ -38,6 +45,7 @@ commands_post =
3845
cov = coverage.Coverage(); \
3946
cov.load(); \
4047
cov.report(file=gh_summary_fd, output_format="markdown")'
48+
# Expose the coverage & test run XML report paths into GHA
4149
{envpython} \
4250
{[python-cli-options]byte-errors} \
4351
{[python-cli-options]max-isolation} \
@@ -165,7 +173,9 @@ commands =
165173
commands_post =
166174
package = skip
167175

168-
176+
# In:
177+
# 'tox run -e pre-commit -- mypy-py313 --all'
178+
# '{posargs}' == 'mypy-py313 --all'
169179
[testenv:pre-commit]
170180
description =
171181
Run the quality checks under {basepython}; run as
@@ -186,6 +196,7 @@ commands =
186196
{posargs:--all-files}
187197

188198
# Print out the advice on how to install pre-commit from this env into Git:
199+
# a leading '-' suppresses non-zero return codes
189200
-{envpython} \
190201
{[python-cli-options]byte-errors} \
191202
{[python-cli-options]max-isolation} \
@@ -219,6 +230,7 @@ commands_post =
219230
); \
220231
print("codecov-flags=MyPy", file=gh_output_fd); \
221232
gh_output_fd.close()'
233+
# Publish available MyPy-produced text and JSON reports wrapped as Markdown code blocks, to a GHA job summary
222234
{envpython} \
223235
{[python-cli-options]byte-errors} \
224236
{[python-cli-options]max-isolation} \

0 commit comments

Comments
 (0)