tasks.py 2.4 KB

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