tasks.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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):
  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 lint(c):
  64. """Typecheck with mypy"""
  65. c.run("poetry run flake8")
  66. @task
  67. def uwsgi(c, sock="lc.sock"):
  68. """Run a uwsgi server"""
  69. c.run(
  70. f"poetry run uwsgi --socket {sock} "
  71. "--module lament-configuration:app "
  72. "--processes 4 --threads 2"
  73. )