Skip to content

Commit 06ae920

Browse files
authored
Move to invoke task runner (ExpDev07#222)
* add invoke as dev dependency * invoke tasks * add invoke check cmd update pipenv scripts and make commands * optional --diff * lint and test * update docs remove Flask as a project requirement add invoke commands * add lint and test to Pipenv scripts, update docs
1 parent cf6006b commit 06ae920

File tree

5 files changed

+89
-20
lines changed

5 files changed

+89
-20
lines changed

Makefile

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ lint:
2121
pylint $(APP) || true
2222

2323
fmt:
24-
isort --apply --atomic
25-
black . -l 120
24+
invoke fmt
2625

2726
check-fmt:
28-
isort -rc --check
29-
black . --check --diff
27+
invoke check --fmt --sort

Pipfile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ verify_ssl = true
66
[dev-packages]
77
bandit = "*"
88
black = "==19.10b0"
9+
invoke = "*"
910
isort = "*"
1011
pytest = "*"
1112
pylint = "*"
@@ -27,5 +28,7 @@ python_version = "3.8"
2728
[scripts]
2829
dev = "uvicorn app.main:APP --reload"
2930
start = "uvicorn app.main:APP"
30-
fmt = "black . -l 120"
31-
sort = "isort --apply --atomic"
31+
fmt = "invoke fmt"
32+
sort = "invoke sort"
33+
lint = "invoke lint"
34+
test = "invoke test"

Pipfile.lock

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,6 @@ These are the available API wrappers created by the community. They are not nece
391391
You will need the following things properly installed on your computer.
392392

393393
* [Python 3](https://www.python.org/downloads/) (with pip)
394-
* [Flask](https://pypi.org/project/Flask/)
395394
* [pipenv](https://pypi.org/project/pipenv/)
396395

397396
## Installation
@@ -415,32 +414,26 @@ And don't despair if don't get the python setup working on the first try. No one
415414
* Visit your app at [http://localhost:5000](http://localhost:5000).
416415

417416
### Running Tests
417+
> [pytest](https://docs.pytest.org/en/latest/)
418418
419419
```bash
420-
pipenv sync --dev
421-
pipenv shell
422-
make test
420+
pipenv run test
423421
```
424422

423+
425424
### Linting
425+
> [pylint](https://www.pylint.org/)
426426
427427
```bash
428-
pipenv sync --dev
429-
pipenv shell
430-
make lint
428+
pipenv run lint
431429
```
432430

433431
### Formatting
432+
> [black](https://black.readthedocs.io/en/stable/)
434433
435434
```bash
436435
pipenv run fmt
437436
```
438-
or
439-
```bash
440-
pipenv shell
441-
make fmt
442-
```
443-
444437

445438
### Building
446439

tasks.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
"""
2+
tasks.py
3+
--------
4+
Project invoke tasks
5+
6+
Available commands
7+
invoke --list
8+
invoke fmt
9+
invoke sort
10+
invoke check
11+
"""
12+
import invoke
13+
14+
TARGETS_DESCRIPTION = "Paths/directories to format. [default: . ]"
15+
16+
17+
@invoke.task(help={"targets": TARGETS_DESCRIPTION})
18+
def sort(ctx, targets="."):
19+
"""Sort module imports."""
20+
print("sorting imports ...")
21+
args = ["isort", "-rc", "--atomic", targets]
22+
ctx.run(" ".join(args))
23+
24+
25+
@invoke.task(pre=[sort], help={"targets": TARGETS_DESCRIPTION})
26+
def fmt(ctx, targets="."):
27+
"""Format python source code & sort imports."""
28+
print("formatting ...")
29+
args = ["black", targets]
30+
ctx.run(" ".join(args))
31+
32+
33+
@invoke.task
34+
def check(ctx, fmt=False, sort=False, diff=False): # pylint: disable=redefined-outer-name
35+
"""Check code format and import order."""
36+
if not any([fmt, sort]):
37+
fmt = True
38+
sort = True
39+
40+
fmt_args = ["black", "--check", "."]
41+
sort_args = ["isort", "-rc", "--check", "."]
42+
43+
if diff:
44+
fmt_args.append("--diff")
45+
sort_args.append("--diff")
46+
47+
cmd_args = []
48+
if fmt:
49+
cmd_args.extend(fmt_args)
50+
if sort:
51+
if cmd_args:
52+
cmd_args.append("&")
53+
cmd_args.extend(sort_args)
54+
ctx.run(" ".join(cmd_args))
55+
56+
57+
@invoke.task
58+
def lint(ctx):
59+
"""Run linter."""
60+
ctx.run(" ".join(["pylint", "app"]))
61+
62+
63+
@invoke.task
64+
def test(ctx):
65+
"""Run pytest tests."""
66+
ctx.run(" ".join(["pytest", "-v"]))

0 commit comments

Comments
 (0)