Skip to content

Commit

Permalink
customizing versioning
Browse files Browse the repository at this point in the history
  • Loading branch information
mmsaki committed Feb 26, 2023
1 parent 000ec3a commit 2a6db53
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
12 changes: 9 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
[build-system]
requires = ["setuptools", "setuptools_scm", "setuptools-git-versioning"]
build-backend = "setuptools.build_meta"
build-backend = "setuptools.build_meta:__legacy__"

[tool.setuptools-git-versioning]
enabled = true
template = "{tag}"
dev_template= "{tag}.dev{ccount}"
dirty_template = "{tag}.post{ccount}+dirty"
starting_version = "0.0.2"
branch_formatter= "util:format_branch_name"
tag_formatter = "util:format_tag_name"

[project]
name = "timevalue"
version = "0.0.2"
version = "v0.0.2"
description = "A simple Python package for financial valuation"
readme = "README.md"
requires-python = ">=3.7"
Expand All @@ -24,7 +30,7 @@ classifiers = [
maintainers = [
{name = "Meek Msaki", email= "meek.dev3@gmail.com"},
]
dynamic = ["version", "description"]
# dynamic = ["version", "description"]


[project.scripts]
Expand Down
34 changes: 34 additions & 0 deletions util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import re


def format_branch_name(name):
# If branch has name like "bugfix/issue-1234-bug-title", take only "1234" part
pattern = re.compile("^(bugfix|feature)\/issue-(?P<branch>[0-9]+)-\S+")

match = pattern.search(name)
if match:
return match.group("branch")

# function is called even if branch name is not used in a current template
# just left properly named branches intact
if name in ["master", "dev", "main"]:
return name

# fail in case of wrong branch names like "bugfix/issue-unknown"
raise ValueError(f"Wrong branch name: {name}")


def format_tag_name(name):
# If tag has name like "release/1.2.3", take only "1.2.3" part
pattern = re.compile(r"release\/(?P<tag>[^\d.]+)")

match = pattern.search(name)
if match:
return match.group("tag")

# just left properly named tags intact
if name.startswith("v"):
return name

# fail in case of wrong tag names like "release/unknown"
raise ValueError(f"Wrong tag name: {name}")

0 comments on commit 2a6db53

Please sign in to comment.