From da449222615ebc55c556d1f924b6988bc71a613c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pasternak?= Date: Tue, 19 Apr 2022 13:26:27 +0200 Subject: [PATCH] Optional GITHASH directive for version_pattern Optionally add GIT hash to your version number. --- CHANGELOG.md | 4 ++++ README.md | 24 ++++++++++++++++++++++++ src/bumpver/v2patterns.py | 3 +++ src/bumpver/v2version.py | 2 ++ src/bumpver/version.py | 1 + 5 files changed, 34 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c4933fd..2ac6960 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog for https://github.com/mbarkhau/bumpver +## **unreleased** + +- Add ``GITHASH`` to ``version_pattern`` (@mpasternak) + ## BumpVer 2022.1116 - Fix: [incorrect version comparison when updating from vcs tag][gh_i174]. diff --git a/README.md b/README.md index 3c982f2..a6ff5cc 100644 --- a/README.md +++ b/README.md @@ -412,6 +412,30 @@ INFO - New Version: v2020.1060 +__version__ = "v2020.1060" ``` +#### Add git hash to version string + +In case you want to build a package straight from your git repository, without making a release first, +you can explictly add git hash to the version number using ``GITHASH`` version part in ``setup.cfg``. + +Let's say your ``setup.cfg`` looks like this: + +```ini +[bumpver] +... +version_pattern = "YYYY.BUILD[-TAG][GITHASH]" +... +``` + +Then, to update all configured files, you need to execute this command: + +```shell +$ bumpver update --no-commit --no-tag --set-version="v202202.1085.8+ged2c3aaf" +``` + +This will modify your source tree, but won't commit or tag aything, so you can build your +packages with that version number. Then, remember to reset local changes after (by +typing ``git reset --hard``) as standard bumpver behaviour with such version number +makes not much sense. ### Searching for Patterns with `grep` diff --git a/src/bumpver/v2patterns.py b/src/bumpver/v2patterns.py index a923cb9..21c209c 100644 --- a/src/bumpver/v2patterns.py +++ b/src/bumpver/v2patterns.py @@ -82,6 +82,7 @@ PART_PATTERNS = { 'BLD' : r"[1-9][0-9]*", 'TAG' : r"preview|final|alpha|beta|post|rc", 'PYTAG': r"post|rc|a|b", + 'GITHASH' : r"\.[0-9]+\+.*", 'NUM' : r"[0-9]+", 'INC0' : r"[0-9]+", 'INC1' : r"[1-9][0-9]*", @@ -109,6 +110,7 @@ PATTERN_PART_FIELDS = { 'BLD' : 'bid', 'TAG' : 'tag', 'PYTAG': 'pytag', + 'GITHASH' : 'githash', 'NUM' : 'num', 'INC0' : 'inc0', 'INC1' : 'inc1', @@ -208,6 +210,7 @@ PART_FORMATS: typ.Dict[str, FormatterFunc] = { 'BLD' : _fmt_bld, 'TAG' : _fmt_num, 'PYTAG': _fmt_num, + 'GITHASH' : _fmt_num, 'NUM' : _fmt_num, 'INC0' : _fmt_num, 'INC1' : _fmt_num, diff --git a/src/bumpver/v2version.py b/src/bumpver/v2version.py index 6b572f3..ebbab53 100644 --- a/src/bumpver/v2version.py +++ b/src/bumpver/v2version.py @@ -223,6 +223,7 @@ def parse_field_values_to_vinfo(field_values: FieldValues) -> version.V2VersionI tag = fvals.get('tag' ) or "" pytag = fvals.get('pytag') or "" + githash = fvals.get('githash') or "" if tag and not pytag: pytag = version.PEP440_TAG_BY_TAG[tag] @@ -257,6 +258,7 @@ def parse_field_values_to_vinfo(field_values: FieldValues) -> version.V2VersionI bid=bid, tag=tag, pytag=pytag, + githash=githash, num=num, inc0=inc0, inc1=inc1, diff --git a/src/bumpver/version.py b/src/bumpver/version.py index dca2c16..e5d207e 100644 --- a/src/bumpver/version.py +++ b/src/bumpver/version.py @@ -77,6 +77,7 @@ class V2VersionInfo(typ.NamedTuple): bid : str tag : str pytag : str + githash : str num : int inc0 : int inc1 : int