Skip to content

Commit 47cc2de

Browse files
authored
Merge pull request #175 from jakkdl/examples
2 parents 7e26dc7 + bf8f98b commit 47cc2de

File tree

1 file changed

+50
-20
lines changed

1 file changed

+50
-20
lines changed

README.md

Lines changed: 50 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,54 @@ pip install flake8-trio
6363
- **TRIO911**: Exit, `yield` or `return` from async iterable with no guaranteed checkpoint since possible function entry (yield or function definition)
6464
Checkpoints are `await`, `async for`, and `async with` (on one of enter/exit).
6565

66+
## Examples
67+
### install and run through flake8
68+
```sh
69+
pip install flake8 flake8-trio
70+
flake8 .
71+
```
72+
### install and run with pre-commit
73+
If you use [pre-commit](https://pre-commit.com/), you can use it with flake8_trio by
74+
adding the following to your `.pre-commit-config.yaml`:
75+
76+
```yaml
77+
minimum_pre_commit_version: '2.9.0'
78+
repos:
79+
- repo: https://github.com/Zac-HD/flake8-trio
80+
rev: 23.2.5
81+
hooks:
82+
- id: flake8-trio
83+
# args: [--enable=TRIO, --disable=TRIO9, --autofix=TRIO]
84+
```
85+
86+
This is often considerably faster for large projects, because `pre-commit`
87+
can avoid running `flake8_trio` on unchanged files.
88+
89+
90+
Afterwards, run
91+
```sh
92+
pip install pre-commit flake8-trio
93+
pre-commit run .
94+
```
95+
### install and run as standalone
96+
If inside a git repository, running without arguments will run it against all `*.py` files in the repository.
97+
```sh
98+
pip install flake8-trio
99+
flake8_trio
100+
```
101+
#### with autofixes
102+
```sh
103+
flake8_trio --autofix=TRIO
104+
```
105+
#### specifying source files
106+
```sh
107+
flake8_trio my_python_file.py
108+
```
109+
##### zsh-only
110+
```zsh
111+
flake8_trio **/*.py
112+
```
113+
66114
## Configuration
67115
[You can configure `flake8` with command-line options](https://flake8.pycqa.org/en/latest/user/configuration.html),
68116
but we prefer using a config file. The file needs to start with a section marker `[flake8]` and the following options are then parsed using flake8's config parser, and can be used just like any other flake8 options.
@@ -75,7 +123,7 @@ Comma-separated list of error codes to enable, similar to flake8 --select but is
75123
Comma-separated list of error codes to disable, similar to flake8 --ignore but is additionally more performant as it will disable non-enabled visitors from running instead of just silencing their errors.
76124

77125
### `--autofix`
78-
Comma-separated list of error-codes to enable autofixing for if implemented. Requires running as a standalone program.
126+
Comma-separated list of error-codes to enable autofixing for if implemented. Requires running as a standalone program. Pass `--autofix=TRIO` to enable all autofixes.
79127

80128
### `--error-on-autofix`
81129
Whether to also print an error message for autofixed errors.
@@ -84,7 +132,7 @@ Whether to also print an error message for autofixed errors.
84132
Change the default library to be anyio instead of trio. If trio is imported it will assume both are available and print suggestions with [anyio|trio].
85133

86134
### `no-checkpoint-warning-decorators`
87-
Specify a list of decorators to disable checkpointing checks for, turning off TRIO910 and TRIO911 warnings for functions decorated with any decorator matching any in the list. Matching is done with [fnmatch](https://docs.python.org/3/library/fnmatch.html). Defaults to disabling for `asynccontextmanager`.
135+
Comma-separated list of decorators to disable checkpointing checks for, turning off TRIO910 and TRIO911 warnings for functions decorated with any decorator matching any in the list. Matching is done with [fnmatch](https://docs.python.org/3/library/fnmatch.html). Defaults to disabling for `asynccontextmanager`.
88136

89137
Decorators-to-match must be identifiers or dotted names only (not PEP-614 expressions), and will match against the name only - e.g. `foo.bar` matches `foo.bar`, `foo.bar()`, and `foo.bar(args, here)`, etc.
90138

@@ -136,21 +184,3 @@ async def my_function():
136184

137185
arbitrary_other_function(my_blocking_call=None)
138186
```
139-
140-
141-
### Using flake8_trio with pre-commit
142-
If you use [pre-commit](https://pre-commit.com/), you can use it with flake8_trio by
143-
adding the following to your `.pre-commit-config.yaml`:
144-
145-
```yaml
146-
minimum_pre_commit_version: '2.9.0'
147-
repos:
148-
- repo: https://github.com/Zac-HD/flake8-trio
149-
rev: 23.2.5
150-
hooks:
151-
- id: flake8-trio
152-
# args: [--enable=TRIO, --disable=TRIO9, --autofix=TRIO]
153-
```
154-
155-
This is often considerably faster for large projects, because `pre-commit`
156-
can avoid running `flake8_trio` on unchanged files.

0 commit comments

Comments
 (0)