chore: update duties.py

This commit is contained in:
2021-11-21 14:17:10 +00:00
parent e5d2b28252
commit 562de606c4

View File

@@ -66,22 +66,21 @@ def coverage(ctx):
@duty @duty
def version(ctx, bump: str = "patch"): def bump(ctx, version: str = "patch"):
""" """
Bump the version using Poetry and update _version.py. Bump the version using Poetry and update _version.py.
Args: Args:
ctx: The context instance (passed automatically). ctx: The context instance (passed automatically).
bump (str, optional) = poetry version flag. Available options are: version (str, optional) = poetry version flag. Available options are:
patch, minor, major, prepatch, preminor, premajor, prerelease. patch, minor, major. Defaults to patch.
Defaults to patch.
Example: Example:
`duty version bump=major` `duty bump version=major`
""" """
# bump with poetry # bump with poetry
result = ctx.run(["poetry", "version", bump]) result = ctx.run(["poetry", "version", version])
new_version = re.search(r"(?:.*)(?:\s)(\d+\.\d+\.\d+)$", result) new_version = re.search(r"(?:.*)(?:\s)(\d+\.\d+\.\d+)$", result)
print(new_version.group(0)) print(new_version.group(0))
@@ -126,6 +125,22 @@ def build(ctx):
shutil.rmtree(extracted_path) shutil.rmtree(extracted_path)
@duty
def release(ctx, version: str = "patch") -> None:
"""
Prepare package for a new release.
Will run bump, build, export. Manual running of publish is required afterwards.
Args:
ctx: The context instance (passed automatically).
version (str): poetry version flag. Available options are: patch, minor, major.
"""
print(ctx.run(["duty", "bump", f"version={version}"]))
ctx.run(["duty", "build"])
ctx.run(["duty", "export"])
@duty @duty
def export(ctx): def export(ctx):
""" """
@@ -328,6 +343,8 @@ def update_changelog(
marker: str, marker: str,
version_regex: str, version_regex: str,
commit_style: str, commit_style: str,
planned_tag: str,
last_released: str,
) -> None: ) -> None:
""" """
Update the given changelog file in place. Update the given changelog file in place.
@@ -347,8 +364,9 @@ def update_changelog(
if len(changelog.versions_list) == 1: if len(changelog.versions_list) == 1:
last_version = changelog.versions_list[0] last_version = changelog.versions_list[0]
print(last_version.planned_tag)
if last_version.planned_tag is None: if last_version.planned_tag is None:
planned_tag = "0.1.0" planned_tag = planned_tag
last_version.tag = planned_tag last_version.tag = planned_tag
last_version.url += planned_tag last_version.url += planned_tag
last_version.compare_url = last_version.compare_url.replace("HEAD", planned_tag) last_version.compare_url = last_version.compare_url.replace("HEAD", planned_tag)
@@ -356,7 +374,9 @@ def update_changelog(
with open(inplace_file, "r") as changelog_file: with open(inplace_file, "r") as changelog_file:
lines = changelog_file.read().splitlines() lines = changelog_file.read().splitlines()
last_released = _latest(lines, re.compile(version_regex)) # last_released = _latest(lines, re.compile(version_regex))
last_released = last_released
print(last_released)
if last_released: if last_released:
changelog.versions_list = _unreleased(changelog.versions_list, last_released) changelog.versions_list = _unreleased(changelog.versions_list, last_released)
rendered = template.render(changelog=changelog, inplace=True) rendered = template.render(changelog=changelog, inplace=True)
@@ -366,26 +386,39 @@ def update_changelog(
changelog_file.write("\n".join(lines).rstrip("\n") + "\n") changelog_file.write("\n".join(lines).rstrip("\n") + "\n")
@duty # @duty
def changelog(ctx): def changelog(planned_tag, last_released):
""" """
Update the changelog in-place with latest commits. Update the changelog in-place with latest commits.
Arguments: Arguments:
ctx: The context instance (passed automatically). ctx: The context instance (passed automatically).
""" """
ctx.run( # print(
update_changelog, # ctx.run(
kwargs={ # update_changelog,
"inplace_file": "CHANGELOG.md", # kwargs={
"marker": "<!-- insertion marker -->", # "inplace_file": "CHANGELOG.md",
"version_regex": r"^## \[v?(?P<version>[^\]]+)", # "marker": "<!-- insertion marker -->",
"commit_style": "angular", # "version_regex": r"^## \[v?(?P<version>[^\]]+)",
}, # "commit_style": "angular",
title="Updating changelog", # },
pty=True, # title="Updating changelog",
# pty=True,
# )
# )
update_changelog(
inplace_file="CHANGELOG.md",
marker="<!-- insertion marker -->",
version_regex=r"^## \[v?(?P<version>[^\]]+)",
commit_style="angular",
planned_tag=planned_tag,
last_released=last_released
) )
def rm_tree(directory: pathlib.Path): def rm_tree(directory: pathlib.Path):
""" """
Recursively delete a directory and all its contents. Recursively delete a directory and all its contents.
@@ -447,3 +480,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
{{ render_version(version) }} {{ render_version(version) }}
{%- endfor -%} {%- endfor -%}
""" """
if __name__ == "__main__":
changelog("1.0.1", "1.0.0")