tasks.py 1.8 KB

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