tasks.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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": "test.db",
  16. "LC_SECRET_KEY": "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. "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": "test.db",
  28. "LC_SECRET_KEY": "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, port=8080, host="127.0.0.1"):
  54. """Populate the test database with fake-ish data"""
  55. c.run(
  56. "PYTHONPATH=$(pwd) poetry run python3 ./scripts/populate.py",
  57. env={
  58. "FLASK_APP": "lament-configuration.py",
  59. "LC_APP_PATH": f"http://{host}:{port}",
  60. "LC_DB_PATH": "test.db",
  61. "LC_SECRET_KEY": "TESTING_KEY",
  62. },
  63. )
  64. @task
  65. def tc(c):
  66. """Typecheck with mypy"""
  67. c.run(
  68. "MYPYPATH=$(pwd)/stubs poetry run mypy --check-untyped-defs lc/*.py tests/*.py scripts/*.py"
  69. )
  70. @task
  71. def lint(c):
  72. """Typecheck with mypy"""
  73. c.run("poetry run flake8")
  74. @task
  75. def uwsgi(c, sock="lc.sock"):
  76. """Run a uwsgi server"""
  77. c.run(
  78. f"poetry run uwsgi --socket {sock} "
  79. "--module lament-configuration:app "
  80. "--processes 4 --threads 2"
  81. )