tasks.py 2.7 KB

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