tasks.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. from invoke import task
  2. @task
  3. def run(c, port=8080, host="127.0.0.1"):
  4. """Run a debug server locally"""
  5. c.run(
  6. f"poetry run python -m flask run -p {port} -h {host}",
  7. env={
  8. "FLASK_APP": "baba-yaga.py",
  9. "APP_PATH": f"http://{host}:{port}",
  10. },
  11. )
  12. @task
  13. def install(c):
  14. """Install the listed dependencies into a virtualenv"""
  15. c.run("poetry install")
  16. @task
  17. def fmt(c):
  18. """Automatically format the source code, committing it if it is safe to do so."""
  19. status = c.run("git status --porcelain", hide="stdout")
  20. is_clean = status.stdout.strip() == ""
  21. c.run("poetry run black $(find by *.py -name '*.py')")
  22. if is_clean:
  23. date = datetime.now().isoformat()
  24. c.run(f"git commit -a -m 'Automatic formatting commit: {date}'")
  25. else:
  26. print("Uncommitted change exist; skipping commit")
  27. @task
  28. def checkfmt(c):
  29. """Automatically format the source code, committing it if it is safe to do so."""
  30. return c.run(
  31. "poetry run black --check $(find lc scripts stubs tests *.py -name '*.py')"
  32. )
  33. @task
  34. def tc(c):
  35. """Typecheck with mypy"""
  36. c.run(
  37. "MYPYPATH=$(pwd)/stubs poetry run mypy --check-untyped-defs by/*.py"
  38. )