Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ lint:
pylint $(APP) || true

fmt:
isort --apply --atomic
black . -l 120
invoke fmt

check-fmt:
isort -rc --check
black . --check --diff
invoke check --fmt --sort
7 changes: 5 additions & 2 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ verify_ssl = true
[dev-packages]
bandit = "*"
black = "==19.10b0"
invoke = "*"
isort = "*"
pytest = "*"
pylint = "*"
Expand All @@ -27,5 +28,7 @@ python_version = "3.8"
[scripts]
dev = "uvicorn app.main:APP --reload"
start = "uvicorn app.main:APP"
fmt = "black . -l 120"
sort = "isort --apply --atomic"
fmt = "invoke fmt"
sort = "invoke sort"
lint = "invoke lint"
test = "invoke test"
11 changes: 10 additions & 1 deletion Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 6 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,6 @@ These are the available API wrappers created by the community. They are not nece
You will need the following things properly installed on your computer.

* [Python 3](https://www.python.org/downloads/) (with pip)
* [Flask](https://pypi.org/project/Flask/)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed Flask

* [pipenv](https://pypi.org/project/pipenv/)

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

### Running Tests
> [pytest](https://docs.pytest.org/en/latest/)

```bash
pipenv sync --dev
pipenv shell
make test
pipenv run test
```


### Linting
> [pylint](https://www.pylint.org/)

```bash
pipenv sync --dev
pipenv shell
make lint
pipenv run lint
```

### Formatting
> [black](https://black.readthedocs.io/en/stable/)

```bash
pipenv run fmt
```
or
```bash
pipenv shell
make fmt
```


### Building

Expand Down
66 changes: 66 additions & 0 deletions tasks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
"""
tasks.py
--------
Project invoke tasks

Available commands
invoke --list
invoke fmt
invoke sort
invoke check
"""
import invoke

TARGETS_DESCRIPTION = "Paths/directories to format. [default: . ]"


@invoke.task(help={"targets": TARGETS_DESCRIPTION})
def sort(ctx, targets="."):
"""Sort module imports."""
print("sorting imports ...")
args = ["isort", "-rc", "--atomic", targets]
ctx.run(" ".join(args))


@invoke.task(pre=[sort], help={"targets": TARGETS_DESCRIPTION})
def fmt(ctx, targets="."):
"""Format python source code & sort imports."""
print("formatting ...")
args = ["black", targets]
ctx.run(" ".join(args))


@invoke.task
def check(ctx, fmt=False, sort=False, diff=False): # pylint: disable=redefined-outer-name
"""Check code format and import order."""
if not any([fmt, sort]):
fmt = True
sort = True

fmt_args = ["black", "--check", "."]
sort_args = ["isort", "-rc", "--check", "."]

if diff:
fmt_args.append("--diff")
sort_args.append("--diff")

cmd_args = []
if fmt:
cmd_args.extend(fmt_args)
if sort:
if cmd_args:
cmd_args.append("&")
cmd_args.extend(sort_args)
ctx.run(" ".join(cmd_args))


@invoke.task
def lint(ctx):
"""Run linter."""
ctx.run(" ".join(["pylint", "app"]))


@invoke.task
def test(ctx):
"""Run pytest tests."""
ctx.run(" ".join(["pytest", "-v"]))