Optional GITHASH directive for version_pattern

Optionally add GIT hash to your version number.
This commit is contained in:
Michał Pasternak 2022-04-19 13:26:27 +02:00 committed by mbarkhau
parent e96904438b
commit da44922261
5 changed files with 34 additions and 0 deletions

View file

@ -1,5 +1,9 @@
# Changelog for https://github.com/mbarkhau/bumpver # Changelog for https://github.com/mbarkhau/bumpver
## **unreleased**
- Add ``GITHASH`` to ``version_pattern`` (@mpasternak)
## BumpVer 2022.1116 ## BumpVer 2022.1116
- Fix: [incorrect version comparison when updating from vcs tag][gh_i174]. - Fix: [incorrect version comparison when updating from vcs tag][gh_i174].

View file

@ -412,6 +412,30 @@ INFO - New Version: v2020.1060
+__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` ### Searching for Patterns with `grep`

View file

@ -82,6 +82,7 @@ PART_PATTERNS = {
'BLD' : r"[1-9][0-9]*", 'BLD' : r"[1-9][0-9]*",
'TAG' : r"preview|final|alpha|beta|post|rc", 'TAG' : r"preview|final|alpha|beta|post|rc",
'PYTAG': r"post|rc|a|b", 'PYTAG': r"post|rc|a|b",
'GITHASH' : r"\.[0-9]+\+.*",
'NUM' : r"[0-9]+", 'NUM' : r"[0-9]+",
'INC0' : r"[0-9]+", 'INC0' : r"[0-9]+",
'INC1' : r"[1-9][0-9]*", 'INC1' : r"[1-9][0-9]*",
@ -109,6 +110,7 @@ PATTERN_PART_FIELDS = {
'BLD' : 'bid', 'BLD' : 'bid',
'TAG' : 'tag', 'TAG' : 'tag',
'PYTAG': 'pytag', 'PYTAG': 'pytag',
'GITHASH' : 'githash',
'NUM' : 'num', 'NUM' : 'num',
'INC0' : 'inc0', 'INC0' : 'inc0',
'INC1' : 'inc1', 'INC1' : 'inc1',
@ -208,6 +210,7 @@ PART_FORMATS: typ.Dict[str, FormatterFunc] = {
'BLD' : _fmt_bld, 'BLD' : _fmt_bld,
'TAG' : _fmt_num, 'TAG' : _fmt_num,
'PYTAG': _fmt_num, 'PYTAG': _fmt_num,
'GITHASH' : _fmt_num,
'NUM' : _fmt_num, 'NUM' : _fmt_num,
'INC0' : _fmt_num, 'INC0' : _fmt_num,
'INC1' : _fmt_num, 'INC1' : _fmt_num,

View file

@ -223,6 +223,7 @@ def parse_field_values_to_vinfo(field_values: FieldValues) -> version.V2VersionI
tag = fvals.get('tag' ) or "" tag = fvals.get('tag' ) or ""
pytag = fvals.get('pytag') or "" pytag = fvals.get('pytag') or ""
githash = fvals.get('githash') or ""
if tag and not pytag: if tag and not pytag:
pytag = version.PEP440_TAG_BY_TAG[tag] pytag = version.PEP440_TAG_BY_TAG[tag]
@ -257,6 +258,7 @@ def parse_field_values_to_vinfo(field_values: FieldValues) -> version.V2VersionI
bid=bid, bid=bid,
tag=tag, tag=tag,
pytag=pytag, pytag=pytag,
githash=githash,
num=num, num=num,
inc0=inc0, inc0=inc0,
inc1=inc1, inc1=inc1,

View file

@ -77,6 +77,7 @@ class V2VersionInfo(typ.NamedTuple):
bid : str bid : str
tag : str tag : str
pytag : str pytag : str
githash : str
num : int num : int
inc0 : int inc0 : int
inc1 : int inc1 : int