Skip to content

Commit

Permalink
docs: Simplify undestanding what's going on
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxymVlasov committed Jan 9, 2025
1 parent 900829c commit 5a84944
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 9 deletions.
42 changes: 35 additions & 7 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
# Notes for contributors

1. Python hooks are supported now too. All you have to do is:
1. add a line to the `console_scripts` array in `entry_points` in `setup.py`
2. Put your python script in the `pre_commit_hooks` folder

Enjoy the clean, valid, and documented code!

* [Run and debug hooks locally](#run-and-debug-hooks-locally)
* [Run hook performance test](#run-hook-performance-test)
* [Run via BASH](#run-via-bash)
Expand All @@ -18,6 +12,7 @@ Enjoy the clean, valid, and documented code!
* [Prepare basic documentation](#prepare-basic-documentation)
* [Add code](#add-code)
* [Finish with the documentation](#finish-with-the-documentation)
* [Work with Python hooks](#work-with-python-hooks)

## Run and debug hooks locally

Expand Down Expand Up @@ -152,5 +147,38 @@ You can use [this PR](https://github.com/antonbabenko/pre-commit-terraform/pull/
### Finish with the documentation
1. Add hook description to [Available Hooks](../README.md#available-hooks).
1. Add the hook description to [Available Hooks](../README.md#available-hooks).
2. Create and populate a new hook section in [Hooks usage notes and examples](../README.md#hooks-usage-notes-and-examples).
### Work with Python hooks
1. [Install `tox`](https://tox.wiki/en/stable/installation.html)
2. To run tests, run:

```bash
tox -qq
```

If there are any issues, copy-paste and run the `python3 ...` command to visualize the pytest coverage report.

3. Before committing any changes (if you do not have `pre-commit` installed locally), run:

```bash
tox r -qq -e pre-commit
```

Make sure that all checks pass.

4. (Optional): If you want to see more explicit MyPy checks, you can run:

```bash
tox r -qq -e pre-commit -- mypy --all-files
```

Then copy-paste and run the `python3 ...` commands to check the strictest MyPy coverage reports.

5. (Optional): You can find all available environments by running:

```bash
tox list
```
3 changes: 3 additions & 0 deletions .github/workflows/reusable-tox.yml
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,8 @@ jobs:
--quiet
--
python -Im pre_commit install-hooks
# Create GHA Job Summary markdown table of the coverage report
# For details: ../../tox.ini '[testenv]' 'commands_post'
- name: >-
Run tox envs: `${{ env.TOXENV }}`
id: tox-run
Expand All @@ -308,6 +310,7 @@ jobs:
&& format('-- {0}', inputs.tox-run-posargs)
|| ''
}}
# Generate nice picture of passed/failed tests in GHA Job Summary
- name: Produce markdown test summary from JUnit
if: >-
!cancelled()
Expand Down
2 changes: 1 addition & 1 deletion pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ doctest_optionflags = ALLOW_UNICODE ELLIPSIS
empty_parameter_set_mark = xfail

faulthandler_timeout = 30

# Make all warnings as errors
filterwarnings =
error

Expand Down
13 changes: 12 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ warnings-to-errors = -Werror
description = Run pytest under {envpython}
dependency_groups =
testing

# In:
# 'tox run -e py -- --lf', 'tox run -- --lf', 'tox run -e py313,py312 -- --lf'
# '{posargs}' == '--lf'
commands =
{envpython} \
{[python-cli-options]byte-errors} \
Expand All @@ -23,6 +27,9 @@ commands =
{tty:--color=yes} \
{posargs:--cov-report=html:{envtmpdir}{/}htmlcov{/}}
commands_post =
# Create GHA Job Summary markdown table of the coverage report
# https://github.blog/news-insights/product-news/supercharging-github-actions-with-job-summaries/
# '-' ignores non-zero exit code
-{envpython} \
{[python-cli-options]byte-errors} \
{[python-cli-options]max-isolation} \
Expand All @@ -38,6 +45,7 @@ commands_post =
cov = coverage.Coverage(); \
cov.load(); \
cov.report(file=gh_summary_fd, output_format="markdown")'
# Find path of coverage & testrun report for next step
{envpython} \
{[python-cli-options]byte-errors} \
{[python-cli-options]max-isolation} \
Expand Down Expand Up @@ -162,7 +170,8 @@ commands =
commands_post =
package = skip


# In 'tox run -e pre-commit -- mypy-py313 --all'
# '{posargs}' == 'mypy-py313 --all'
[testenv:pre-commit]
description =
Run the quality checks under {basepython}; run as
Expand All @@ -183,6 +192,7 @@ commands =
{posargs:--all-files}

# Print out the advice on how to install pre-commit from this env into Git:
# '-' ignores non-zero exit code
-{envpython} \
{[python-cli-options]byte-errors} \
{[python-cli-options]max-isolation} \
Expand Down Expand Up @@ -216,6 +226,7 @@ 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} \
Expand Down

0 comments on commit 5a84944

Please sign in to comment.