import sys from invoke import Failure from invoke import task @task def update_deps(c): """Resolves production requirements.""" c.run("pip-compile requirements.in", pty=True) @task def install_deps(c): """Installs dev and production requirements.""" c.run("pip-sync requirements.txt dev-requirements.txt", pty=True) @task def serve_dev(c, debugger=True, reload=True, threads=True, port=8888, host="0.0.0.0"): """Serves the htmx_contact.app locally""" cmd = "flask --app=./htmx_contact:create_app run" cmd += " --debug" if debugger else "" cmd += " --reload" if reload else "" cmd += " --with-threads" if threads else "" cmd += f" --host {host}" if host else "" cmd += f" --port {port}" if port else "" print(cmd) c.run(cmd, pty=True) @task def test(c): """executes test suite""" c.run("pytest -vvv --cov tests/", pty=True) @task def lint(c, verbose=False): """Executes linter checks""" exit_code = 0 c.run("echo 'Checking isort'") try: c.run(f"isort {'-v' if verbose else ''} --check .", pty=True) except Failure: exit_code = 1 c.run("echo 'Lint check black'") try: c.run(f"black {'-v' if verbose else ''} --check .", pty=True) except Failure: exit_code = 1 c.run("echo 'Lint check with ruff'") try: c.run(f"ruff check {'-v' if verbose else ''} .", pty=True) except Failure: exit_code = 1 if exit_code: c.run("echo 'ERROR: failed lint checks' >&2 ") sys.exit(exit_code) @task def delint(c): """Runs code formaters isort, black""" c.run("isort .", pty=True) c.run("black .", pty=True)