implement INC0 and INC1 parts

This commit is contained in:
Manuel Barkhau 2020-10-04 11:28:53 +00:00
parent f92c7347ae
commit d23689634c
7 changed files with 62 additions and 24 deletions

View file

@ -7,6 +7,7 @@
- Better support for week numbering. - Better support for week numbering.
- Better support for optional parts. - Better support for optional parts.
- New: Start `BUILD` parts at `1000` to avoid leading zero truncation. - New: Start `BUILD` parts at `1000` to avoid leading zero truncation.
- New: Add `INC0` (0-based) and `INC1` (1-based) parts that do auto increment and rollover.
- New: `MAJOR`/`MINOR`/`PATCH`/`INC` will roll over when a date part changes to their left. - New: `MAJOR`/`MINOR`/`PATCH`/`INC` will roll over when a date part changes to their left.
- New gitlab #2: Added `grep` subcommand to find and debug patterns. - New gitlab #2: Added `grep` subcommand to find and debug patterns.
- New: Added better error messages to debug regular expressions. - New: Added better error messages to debug regular expressions.

View file

@ -229,14 +229,16 @@ These patterns are closely based on https://calver.org/
| `0D` | 01, 02, 03..31 | `%d` | | `0D` | 01, 02, 03..31 | `%d` |
| `JJJ` | 1,2,3..366 | `int(%j)` | | `JJJ` | 1,2,3..366 | `int(%j)` |
| `00J` | 001, 002..366 | `%j` | | `00J` | 001, 002..366 | `%j` |
| `BUILD` | 0011, 1001, 1002, .. | build number (lexid) |
| `BLD` | 11, 1001, 1002, .. | zero truncated `BUILD` |
| `MAJOR` | 0..9, 10..99, 100.. | `--major` | | `MAJOR` | 0..9, 10..99, 100.. | `--major` |
| `MINOR` | 0..9, 10..99, 100.. | `-m/--minor` | | `MINOR` | 0..9, 10..99, 100.. | `-m/--minor` |
| `PATCH` | 0..9, 10..99, 100.. | `-p/--patch` | | `PATCH` | 0..9, 10..99, 100.. | `-p/--patch` |
| `NUM` | 0, 1, 2... | `-r/--release-num` | | `INC0` | 0, 1, 2... | |
| `INC1` | 1, 2... | |
| `BUILD` | 0011, 1001, 1002, .. | build number (lexid) |
| `BLD` | 11, 1001, 1002, .. | zero truncated `BUILD` |
| `RELEASE` | alpha, beta, rc | `--release=<tag>` | | `RELEASE` | alpha, beta, rc | `--release=<tag>` |
| `PYTAG` | a, b, rc | `--release=<tag>` | | `PYTAG` | a, b, rc | `--release=<tag>` |
| `NUM` | 0, 1, 2... | `-r/--release-num` |
### Week Numbering ### Week Numbering

View file

@ -126,7 +126,8 @@ README.md =
score = no score = no
reports = no reports = no
jobs = 4 # pylint spams the same message multiple times if jobs > 1
jobs = 1
# Set the output format. Available formats are text, parseable, colorized, # Set the output format. Available formats are text, parseable, colorized,
# msvs (visual studio) and html. You can also give a reporter class, eg # msvs (visual studio) and html. You can also give a reporter class, eg
@ -134,7 +135,7 @@ jobs = 4
output-format = colorized output-format = colorized
# Maximum number of locals for function / method body # Maximum number of locals for function / method body
max-locals = 21 max-locals = 25
# Maximum number of arguments for function / method # Maximum number of arguments for function / method
max-args = 12 max-args = 12

View file

@ -86,6 +86,8 @@ PART_PATTERNS = {
'RELEASE': r"preview|final|alpha|beta|post|rc", 'RELEASE': r"preview|final|alpha|beta|post|rc",
'PYTAG' : r"post|rc|a|b", 'PYTAG' : r"post|rc|a|b",
'NUM' : r"[0-9]+", 'NUM' : r"[0-9]+",
'INC0' : r"[0-9]+",
'INC1' : r"[1-9][0-9]*",
} }
@ -111,6 +113,8 @@ PATTERN_PART_FIELDS = {
'RELEASE': 'tag', 'RELEASE': 'tag',
'PYTAG' : 'pytag', 'PYTAG' : 'pytag',
'NUM' : 'num', 'NUM' : 'num',
'INC0' : 'inc0',
'INC1' : 'inc1',
'WW' : 'week_w', 'WW' : 'week_w',
'0W' : 'week_w', '0W' : 'week_w',
'UU' : 'week_u', 'UU' : 'week_u',
@ -183,7 +187,10 @@ def _fmt_0v(week_v: FieldValue) -> str:
return "{0:02}".format(int(week_v)) return "{0:02}".format(int(week_v))
PART_FORMATS: typ.Dict[str, typ.Callable[[FieldValue], str]] = { FormatterFunc = typ.Callable[[FieldValue], str]
PART_FORMATS: typ.Dict[str, FormatterFunc] = {
'YYYY' : _fmt_num, 'YYYY' : _fmt_num,
'YY' : _fmt_yy, 'YY' : _fmt_yy,
'0Y' : _fmt_0y, '0Y' : _fmt_0y,
@ -205,6 +212,8 @@ PART_FORMATS: typ.Dict[str, typ.Callable[[FieldValue], str]] = {
'RELEASE': _fmt_num, 'RELEASE': _fmt_num,
'PYTAG' : _fmt_num, 'PYTAG' : _fmt_num,
'NUM' : _fmt_num, 'NUM' : _fmt_num,
'INC0' : _fmt_num,
'INC1' : _fmt_num,
'WW' : _fmt_num, 'WW' : _fmt_num,
'0W' : _fmt_0w, '0W' : _fmt_0w,
'UU' : _fmt_num, 'UU' : _fmt_num,

View file

@ -201,6 +201,8 @@ def _parse_version_info(field_values: FieldValues) -> version.V2VersionInfo:
patch = int(fvals.get('patch') or 0) patch = int(fvals.get('patch') or 0)
num = int(fvals.get('num' ) or 0) num = int(fvals.get('num' ) or 0)
bid = fvals['bid'] if 'bid' in fvals else "1000" bid = fvals['bid'] if 'bid' in fvals else "1000"
inc0 = int(fvals.get('inc0') or 0)
inc1 = int(fvals.get('inc1') or 1)
vinfo = version.V2VersionInfo( vinfo = version.V2VersionInfo(
year_y=year_y, year_y=year_y,
@ -219,6 +221,8 @@ def _parse_version_info(field_values: FieldValues) -> version.V2VersionInfo:
bid=bid, bid=bid,
tag=tag, tag=tag,
pytag=pytag, pytag=pytag,
inc0=inc0,
inc1=inc1,
) )
return vinfo return vinfo
@ -567,9 +571,9 @@ def _iter_reset_field_items(
# Any field to the left of another can reset all to the right # Any field to the left of another can reset all to the right
has_reset = False has_reset = False
for field in fields: for field in fields:
zero_val = version.V2_FIELD_ZERO_VALUES.get(field) initial_val = version.V2_FIELD_INITIAL_VALUES.get(field)
if has_reset and zero_val is not None: if has_reset and initial_val is not None:
yield field, zero_val yield field, initial_val
elif getattr(old_vinfo, field) != getattr(cur_vinfo, field): elif getattr(old_vinfo, field) != getattr(cur_vinfo, field):
has_reset = True has_reset = True
@ -598,6 +602,16 @@ def _incr_numeric(
cur_vinfo = cur_vinfo._replace(bid=lexid.next_id(cur_vinfo.bid)) cur_vinfo = cur_vinfo._replace(bid=lexid.next_id(cur_vinfo.bid))
if 'inc0' in reset_fields:
cur_vinfo = cur_vinfo._replace(inc0=0)
else:
cur_vinfo = cur_vinfo._replace(inc0=cur_vinfo.inc0 + 1)
if 'inc1' in reset_fields:
cur_vinfo = cur_vinfo._replace(inc1=1)
else:
cur_vinfo = cur_vinfo._replace(inc1=cur_vinfo.inc1 + 1)
if major and 'major' not in reset_fields: if major and 'major' not in reset_fields:
cur_vinfo = cur_vinfo._replace(major=cur_vinfo.major + 1, minor=0, patch=0) cur_vinfo = cur_vinfo._replace(major=cur_vinfo.major + 1, minor=0, patch=0)
if minor and 'minor' not in reset_fields: if minor and 'minor' not in reset_fields:

View file

@ -73,6 +73,8 @@ class V2VersionInfo(typ.NamedTuple):
bid : str bid : str
tag : str tag : str
pytag : str pytag : str
inc0 : int
inc1 : int
# The test suite may replace this. # The test suite may replace this.
@ -116,18 +118,19 @@ PART_ZERO_VALUES = {
'RELEASE': "final", 'RELEASE': "final",
'PYTAG' : "", 'PYTAG' : "",
'NUM' : "0", 'NUM' : "0",
'INC' : "0", 'INC0' : "0",
} }
V2_FIELD_ZERO_VALUES = { V2_FIELD_INITIAL_VALUES = {
'major': "0", 'major': "0",
'minor': "0", 'minor': "0",
'patch': "0", 'patch': "0",
'tag' : "final", 'tag' : "final",
'pytag': "", 'pytag': "",
'num' : "0", 'num' : "0",
'inc' : "0", 'inc0' : "0",
'inc1' : "1",
} }

View file

@ -768,23 +768,31 @@ def test_multimatch_file_patterns(runner):
assert "[aka. 202010.1003b0 !]" in readme_text assert "[aka. 202010.1003b0 !]" in readme_text
def _kwargs(month, minor): def _kwargs(year, month, minor=False):
return {'date': dt.date(2020, month, 1), 'minor': minor} return {'date': dt.date(year, month, 1), 'minor': minor}
ROLLOVER_TEST_CASES = [ ROLLOVER_TEST_CASES = [
# v1 cases # v1 cases
["{year}.{month}.{MINOR}", "2020.10.3", "2020.10.4", _kwargs(10, True)], ["{year}.{month}.{MINOR}", "2020.10.3", "2020.10.4", _kwargs(2020, 10, True)],
["{year}.{month}.{MINOR}", "2020.10.3", None, _kwargs(10, False)], ["{year}.{month}.{MINOR}", "2020.10.3", None, _kwargs(2020, 10, False)],
["{year}.{month}.{MINOR}", "2020.10.3", "2020.11.4", _kwargs(11, True)], ["{year}.{month}.{MINOR}", "2020.10.3", "2020.11.4", _kwargs(2020, 11, True)],
["{year}.{month}.{MINOR}", "2020.10.3", "2020.11.3", _kwargs(11, False)], ["{year}.{month}.{MINOR}", "2020.10.3", "2020.11.3", _kwargs(2020, 11, False)],
# v2 cases # v2 cases
["YYYY.MM.MINOR" , "2020.10.3", "2020.10.4", _kwargs(10, True)], ["YYYY.MM.MINOR" , "2020.10.3", "2020.10.4", _kwargs(2020, 10, True)],
["YYYY.MM.MINOR" , "2020.10.3", None, _kwargs(10, False)], ["YYYY.MM.MINOR" , "2020.10.3", None, _kwargs(2020, 10, False)],
["YYYY.MM.MINOR" , "2020.10.3", "2020.11.0", _kwargs(11, True)], ["YYYY.MM.MINOR" , "2020.10.3", "2020.11.0", _kwargs(2020, 11, True)],
["YYYY.MM.MINOR" , "2020.10.3", "2020.11.0", _kwargs(11, False)], ["YYYY.MM.MINOR" , "2020.10.3", "2020.11.0", _kwargs(2020, 11, False)],
["YYYY.MM[.MINOR]", "2020.10.3", "2020.10.4", _kwargs(10, True)], ["YYYY.MM[.MINOR]", "2020.10.3", "2020.10.4", _kwargs(2020, 10, True)],
["YYYY.MM[.MINOR]", "2020.10.3", "2020.11", _kwargs(11, False)], ["YYYY.MM[.MINOR]", "2020.10.3", "2020.11", _kwargs(2020, 11, False)],
["YYYY.MM.MINOR" , "2020.10.3", "2021.10.0", _kwargs(2021, 10, False)],
# incr0/incr1 part
["YYYY.MM.INC0", "2020.10.3", "2020.10.4", _kwargs(2020, 10)],
["YYYY.MM.INC0", "2020.10.3", "2020.11.0", _kwargs(2020, 11)],
["YYYY.MM.INC0", "2020.10.3", "2021.10.0", _kwargs(2021, 10)],
["YYYY.MM.INC1", "2020.10.3", "2020.10.4", _kwargs(2020, 10)],
["YYYY.MM.INC1", "2020.10.3", "2020.11.1", _kwargs(2020, 11)],
["YYYY.MM.INC1", "2020.10.3", "2021.10.1", _kwargs(2021, 10)],
] ]