tasks.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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")
  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={"FLASK_APP": "lament-configuration.py"},
  13. )
  14. @task
  15. def install(c):
  16. """Install the listed dependencies into a virtualenv"""
  17. c.run("poetry install")
  18. @task
  19. def fmt(c):
  20. """Automatically format the source code, committing it if it is safe to do so."""
  21. status = c.run("git status --porcelain", hide="stdout")
  22. is_clean = status.stdout.strip() == ""
  23. c.run("poetry run black $(find . -name '*.py')")
  24. if is_clean:
  25. date = datetime.now().isoformat()
  26. c.run(f"git commit -a -m 'Automatic formatting commit: {date}'")
  27. else:
  28. print("Uncommitted change exist; skipping commit")
  29. @task
  30. def populate(c):
  31. """Populate the test database with fake-ish data"""
  32. c.run("PYTHONPATH=$(pwd) poetry run python3 ./scripts/populate.py")
  33. @task
  34. def tc(c):
  35. """Populate the test database with fake-ish data"""
  36. c.run("MYPYPATH=$(pwd)/stubs poetry run mypy lc/*.py tests/*.py scripts/*.py")