tasks.py 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. from pathlib import Path
  2. from invoke import task
  3. from jinja2 import Template
  4. @task
  5. def lint(c):
  6. """"""
  7. system = "graph_exploring_tool"
  8. c.run(f"python3 -m black {system}")
  9. c.run(f"python3 -m pylint {system}")
  10. @task(name="docs")
  11. def documentation(c):
  12. """Build the documentation."""
  13. c.run("python3 -m sphinx docs docs/build/html")
  14. @task
  15. def test(c):
  16. """Run all tests under the tests directory."""
  17. c.run("python3 -m unittest discover tests 'test_*' -v")
  18. @task(name="migrate")
  19. def migrate_requirements(c):
  20. """Copy requirements from the requirements.txt file to pyproject.toml."""
  21. lines = Path("requirements.txt").read_text().split("\n")
  22. current = "graph_exploring_tool"
  23. requirements = {current: [], "test": [], "doc": [], "graphical": [], "dev": []}
  24. for line in lines:
  25. if line.startswith("#"):
  26. candidate = line[1:].lower().strip().replace(" ", "_")
  27. if candidate in requirements.keys():
  28. current = candidate
  29. continue
  30. if line.strip() == "" or ("=" in line and "#" in line):
  31. continue
  32. requirements[current].append("".join(line.split()))
  33. template = Template(Path("docs/templates/pyproject.toml").read_text())
  34. Path("pyproject.toml").write_text(template.render(requirements=requirements))
  35. @task
  36. def release(c, version):
  37. """"""
  38. if version not in ["minor", "major", "patch"]:
  39. print("Version can be either major, minor or patch.")
  40. return
  41. from graph_exploring_tool import __version_info__, __version__
  42. _major, _minor, _patch = __version_info__
  43. if version == "patch":
  44. _patch = _patch + 1
  45. elif version == "minor":
  46. _minor = _minor + 1
  47. _patch = 0
  48. elif version == "major":
  49. _major = _major + 1
  50. _minor = 0
  51. _patch = 0
  52. c.run(f"git checkout -b release-{_major}.{_minor}.{_patch} dev")
  53. c.run(f"sed -i 's/{__version__}/{_major}.{_minor}.{_patch}/g' graph_exploring_tool/__init__.py")
  54. print(f"Update the readme for version {_major}.{_minor}.{_patch}.")
  55. input("Press enter when ready.")
  56. c.run(f"git add -u")
  57. c.run(f'git commit -m "Update changelog version {_major}.{_minor}.{_patch}"')
  58. c.run(f"git push --set-upstream origin release-{_major}.{_minor}.{_patch}")
  59. c.run(f"git checkout main")
  60. c.run(f"git merge --no-ff release-{_major}.{_minor}.{_patch}")
  61. c.run(f'git tag -a {_major}.{_minor}.{_patch} -m "Release {_major}.{_minor}.{_patch}"')
  62. c.run(f"git push")
  63. c.run(f"git checkout dev")
  64. c.run(f"git merge --no-ff release-{_major}.{_minor}.{_patch}")
  65. c.run(f"git push")
  66. c.run(f"git branch -d release-{_major}.{_minor}.{_patch}")
  67. c.run(f"git push origin --tags")