diff --git a/Makefile b/Makefile index 78f8f6b4..7059a9be 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/Pipfile b/Pipfile index 6b30ef90..21965c37 100644 --- a/Pipfile +++ b/Pipfile @@ -6,6 +6,7 @@ verify_ssl = true [dev-packages] bandit = "*" black = "==19.10b0" +invoke = "*" isort = "*" pytest = "*" pylint = "*" @@ -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" diff --git a/Pipfile.lock b/Pipfile.lock index c949f6cb..cc93e092 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "ecd83aad2c3783fdaa5581f562d022a6b500b3f3b4beb7c3f63d3d5baff85813" + "sha256": "9574394caac3b437d4357507a93178b38289861241165e4736369a7b4c2a2cbc" }, "pipfile-spec": 6, "requires": { @@ -342,6 +342,15 @@ ], "version": "==3.1.0" }, + "invoke": { + "hashes": [ + "sha256:87b3ef9d72a1667e104f89b159eaf8a514dbf2f3576885b2bbdefe74c3fb2132", + "sha256:93e12876d88130c8e0d7fd6618dd5387d6b36da55ad541481dfa5e001656f134", + "sha256:de3f23bfe669e3db1085789fd859eb8ca8e0c5d9c20811e2407fa042e8a5e15d" + ], + "index": "pypi", + "version": "==1.4.1" + }, "isort": { "hashes": [ "sha256:54da7e92468955c4fceacd0c86bd0ec997b0e1ee80d97f67c35a78b719dccab1", diff --git a/README.md b/README.md index 7703aa2d..219d8cc4 100644 --- a/README.md +++ b/README.md @@ -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/) * [pipenv](https://pypi.org/project/pipenv/) ## Installation @@ -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 diff --git a/tasks.py b/tasks.py new file mode 100644 index 00000000..3ff5f24c --- /dev/null +++ b/tasks.py @@ -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"]))