tasks.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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={
  13. "FLASK_APP": "lament-configuration.py",
  14. "LC_APP_PATH": f"http://{host}:{port}",
  15. "LC_DB_PATH": f"test.db",
  16. "LC_SECRET_KEY": f"TESTING_KEY",
  17. },
  18. )
  19. @task
  20. def install(c):
  21. """Install the listed dependencies into a virtualenv"""
  22. c.run("poetry install")
  23. @task
  24. def fmt(c):
  25. """Automatically format the source code, committing it if it is safe to do so."""
  26. status = c.run("git status --porcelain", hide="stdout")
  27. is_clean = status.stdout.strip() == ""
  28. c.run("poetry run black $(find lc scripts stubs tests *.py -name '*.py')")
  29. if is_clean:
  30. date = datetime.now().isoformat()
  31. c.run(f"git commit -a -m 'Automatic formatting commit: {date}'")
  32. else:
  33. print("Uncommitted change exist; skipping commit")
  34. @task
  35. def checkfmt(c):
  36. """Automatically format the source code, committing it if it is safe to do so."""
  37. return c.run(
  38. "poetry run black --check $(find lc scripts stubs tests *.py -name '*.py')"
  39. )
  40. @task
  41. def populate(c):
  42. """Populate the test database with fake-ish data"""
  43. c.run("PYTHONPATH=$(pwd) poetry run python3 ./scripts/populate.py")
  44. @task
  45. def tc(c):
  46. """Typecheck with mypy"""
  47. c.run(
  48. "MYPYPATH=$(pwd)/stubs poetry run mypy --check-untyped-defs lc/*.py tests/*.py scripts/*.py"
  49. )
  50. @task
  51. def uwsgi(c, sock="lc.sock"):
  52. """Run a uwsgi server"""
  53. c.run(
  54. f"poetry run uwsgi --socket {sock} --module lament-configuration:app --processes 4 --threads 2"
  55. )