tasks.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. from invoke import task
  2. @task
  3. def js(c):
  4. """Build our JavaScript"""
  5. c.run("yarn install")
  6. c.run("yarn build")
  7. @task(js)
  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": "baba-yaga.py",
  14. "APP_PATH": f"http://{host}:{port}",
  15. },
  16. )
  17. @task
  18. def install(c):
  19. """Install the listed dependencies into a virtualenv"""
  20. c.run("poetry install")
  21. @task
  22. def fmt(c):
  23. """Automatically format the source code, committing it if it is safe to do so."""
  24. status = c.run("git status --porcelain", hide="stdout")
  25. is_clean = status.stdout.strip() == ""
  26. c.run("poetry run black $(find by *.py -name '*.py')")
  27. if is_clean:
  28. date = datetime.now().isoformat()
  29. c.run(f"git commit -a -m 'Automatic formatting commit: {date}'")
  30. else:
  31. print("Uncommitted change exist; skipping commit")
  32. @task
  33. def checkfmt(c):
  34. """Automatically format the source code, committing it if it is safe to do so."""
  35. return c.run(
  36. "poetry run black --check $(find lc scripts stubs tests *.py -name '*.py')"
  37. )
  38. @task
  39. def tc(c):
  40. """Typecheck with mypy"""
  41. c.run(
  42. "MYPYPATH=$(pwd)/stubs poetry run mypy --check-untyped-defs by/*.py"
  43. )