tasks.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 . -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 populate(c):
  31. """Populate the test database with fake-ish data"""
  32. c.run("PYTHONPATH=$(pwd) poetry run python3 ./scripts/populate.py")
  33. @task
  34. def tc(c):
  35. """Populate the test database with fake-ish data"""
  36. c.run("MYPYPATH=$(pwd)/stubs poetry run mypy lc/*.py tests/*.py scripts/*.py")
  37. @task
  38. def uwsgi(c, sock="lc.sock"):
  39. """Run a uwsgi server"""
  40. c.run(
  41. f"poetry run uwsgi --socket {sock} --module lament-configuration:app --processes 4 --threads 2"
  42. )