tasks.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. from datetime import datetime
  2. from invoke import task
  3. @task
  4. def test(c):
  5. """Run all the provided tests"""
  6. c.run("poetry run python -m pytest tests/*.py -W ignore::DeprecationWarning")
  7. @task
  8. def run(c, port=8080, host="127.0.0.1"):
  9. """Run a debug server locally"""
  10. c.run(
  11. f"poetry run python -m flask run -p {port} -h {host}",
  12. env={"FLASK_APP": "lament-configuration.py"},
  13. )
  14. @task
  15. def install(c):
  16. """Install the listed dependencies into a virtualenv"""
  17. c.run("poetry install")
  18. @task
  19. def fmt(c):
  20. """Automatically format the source code, committing it if it is safe to do so."""
  21. status = c.run("git status --porcelain", hide="stdout")
  22. is_clean = status.stdout.strip() == ""
  23. c.run("poetry run black $(find lc scripts stubs tests *.py -name '*.py')")
  24. if is_clean:
  25. date = datetime.now().isoformat()
  26. c.run(f"git commit -a -m 'Automatic formatting commit: {date}'")
  27. else:
  28. print("Uncommitted change exist; skipping commit")
  29. @task
  30. def checkfmt(c):
  31. """Automatically format the source code, committing it if it is safe to do so."""
  32. return c.run(
  33. "poetry run black --check $(find lc scripts stubs tests *.py -name '*.py')"
  34. )
  35. @task
  36. def populate(c):
  37. """Populate the test database with fake-ish data"""
  38. c.run("PYTHONPATH=$(pwd) poetry run python3 ./scripts/populate.py")
  39. @task
  40. def tc(c):
  41. """Typecheck with mypy"""
  42. c.run("MYPYPATH=$(pwd)/stubs poetry run mypy lc/*.py tests/*.py scripts/*.py")
  43. @task
  44. def uwsgi(c, sock="lc.sock"):
  45. """Run a uwsgi server"""
  46. c.run(
  47. f"poetry run uwsgi --socket {sock} --module lament-configuration:app --processes 4 --threads 2"
  48. )