tasks.py 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. c.run("yarn install")
  40. @task
  41. def fmt(c):
  42. """Automatically format the source code, committing it if it is safe to do so."""
  43. status = c.run("git status --porcelain", hide="stdout")
  44. is_clean = status.stdout.strip() == ""
  45. c.run("poetry run black $(find lc scripts stubs tests *.py -name '*.py')")
  46. if is_clean:
  47. date = datetime.now().isoformat()
  48. c.run(f"git commit -a -m 'Automatic formatting commit: {date}'")
  49. else:
  50. print("Uncommitted change exist; skipping commit")
  51. @task
  52. def checkfmt(c):
  53. """Automatically format the source code, committing it if it is safe to do so."""
  54. return c.run(
  55. "poetry run black --check $(find lc scripts stubs tests *.py -name '*.py')"
  56. )
  57. @task
  58. def populate(c, port=8080, host="127.0.0.1"):
  59. """Populate the test database with fake-ish data"""
  60. c.run(
  61. "PYTHONPATH=$(pwd) poetry run python3 ./scripts/populate.py",
  62. env={
  63. "FLASK_APP": "lament-configuration.py",
  64. "LC_APP_PATH": f"http://{host}:{port}",
  65. "LC_DB_PATH": "test.db",
  66. "LC_SECRET_KEY": "TESTING_KEY",
  67. },
  68. )
  69. @task
  70. def tc(c):
  71. """Typecheck with mypy"""
  72. c.run(
  73. "MYPYPATH=$(pwd)/stubs poetry run mypy --check-untyped-defs lc/*.py tests/*.py scripts/*.py"
  74. )
  75. @task
  76. def lint(c):
  77. """Typecheck with mypy"""
  78. c.run("poetry run flake8")
  79. @task(webpack)
  80. def uwsgi(c, sock="lc.sock"):
  81. """Run a uwsgi server"""
  82. c.run(
  83. f"poetry run uwsgi --socket {sock} "
  84. "--module lament-configuration:app "
  85. "--processes 4 --threads 2"
  86. )