Files
tembo/duties.py
2021-11-09 23:55:19 +00:00

62 lines
1.4 KiB
Python

from __future__ import annotations
from duty import duty
import pathlib
import re
PACKAGE_NAME = "tembo"
@duty
def update_deps(ctx, dry: bool = False):
"""
Update the dependencies using Poetry.
Example:
`duty update_deps dry=False`
"""
dry_run = "--dry-run" if dry else ""
ctx.run(
["poetry", "update", dry_run],
title=f"Updating poetry deps {dry_run}",
)
@duty
def coverage(ctx):
"""
Generate a coverage HTML report.
Example:
`duty coverage`
"""
ctx.run(["coverage", "run", "--source", PACKAGE_NAME, "-m", "pytest"])
ctx.run(["coverage", "html"])
@duty
def version(ctx, bump: str = "patch"):
"""
Bump the version using Poetry and update _version.py.
Args:
bump (str, optional) = poetry version flag. Available options are:
patch, minor, major, prepatch, preminor, premajor, prerelease.
Defaults to patch.
Example:
`duty version bump=major`
"""
# bump with poetry
result = ctx.run(["poetry", "version", bump])
new_version = re.search(r"(?:.*)(?:\s)(\d+\.\d+\.\d+)$", result)
print(new_version.group(0))
# update _version.py
version_file = pathlib.Path(PACKAGE_NAME) / "_version.py"
with version_file.open("w", encoding="utf-8") as version_file:
version_file.write(f'__version__ = "{new_version.group(1)}"\n')
print(f"Bumped _version.py to {new_version.group(1)}")