tasks.py 2.2 KB

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