diff --git a/CHANGELOG.md b/CHANGELOG.md index c2f31a7..8aa7acc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - Better support for optional parts. - New: Start `BUILD` parts at `1000` to avoid leading zero truncation. - New gitlab #10: `--pin-date` to keep date parts unchanged, and only increment non-date parts. + - New add `--release-num` to increment the `alphaN`/`betaN`/`a0`/`b0`/etc. release number - Fix gitlab #8: Push tags only pushed tags, not actual commit. - Fix gitlab #9: Make commit message configurable. diff --git a/README.md b/README.md index db3fe38..d02232c 100644 --- a/README.md +++ b/README.md @@ -591,15 +591,16 @@ TODO: Descriptions TODO: Descriptions -| CLI Argument | Description | -|---------------|-------------| -| --major | | -| --minor | | -| --patch | | -| --pin-date | | -| --no-fetch | | -| --dry | | -| --allow-dirty | | +| CLI Argument | Description | +|------------------|-------------| +| --major | | +| -m --minor | | +| -p --patch | | +| -r --release-num | | +| --pin-date | | +| --no-fetch | | +| --dry | | +| --allow-dirty | | ## The PyCalVer Format diff --git a/src/pycalver/__main__.py b/src/pycalver/__main__.py index 8f3dc41..0c28381 100755 --- a/src/pycalver/__main__.py +++ b/src/pycalver/__main__.py @@ -85,14 +85,19 @@ def cli(verbose: int = 0) -> None: @click.argument("pattern", default="{pycalver}") @click.option('-v', '--verbose', count=True, help="Control log level. -vv for debug level.") @click.option( - "--release", default=None, metavar="", help="Override release name of current_version" + "--release", + default=None, + metavar="", + help=( + f"Override release name of current_version. Valid options are: " + f"{', '.join(VALID_RELEASE_VALUES)}." + ), ) @click.option("--major", is_flag=True, default=False, help="Increment major component.") -@click.option("--minor", is_flag=True, default=False, help="Increment minor component.") -@click.option("--patch", is_flag=True, default=False, help="Increment patch component.") -@click.option( - "-p", "--pin-date", is_flag=True, default=False, help="Leave date components unchanged." -) +@click.option("-m", "--minor", is_flag=True, default=False, help="Increment minor component.") +@click.option("-p", "--patch", is_flag=True, default=False, help="Increment patch component.") +@click.option("-r", "--release-num", is_flag=True, default=False, help="Increment release number.") +@click.option("--pin-date", is_flag=True, default=False, help="Leave date components unchanged.") def test( old_version: str, pattern : str = "{pycalver}", @@ -101,6 +106,7 @@ def test( major : bool = False, minor : bool = False, patch : bool = False, + release_num: bool = False, pin_date : bool = False, ) -> None: """Increment a version number for demo purposes.""" @@ -117,6 +123,7 @@ def test( major=major, minor=minor, patch=patch, + release_num=release_num, pin_date=pin_date, ) if new_version is None: @@ -193,6 +200,7 @@ def _incr( major : bool = False, minor : bool = False, patch : bool = False, + release_num: bool = False, pin_date: bool = False, ) -> typ.Optional[str]: v1_parts = list(v1patterns.PART_PATTERNS) + list(v1patterns.FULL_PART_FORMATS) @@ -205,6 +213,7 @@ def _incr( major=major, minor=minor, patch=patch, + release_num=release_num, pin_date=pin_date, ) else: @@ -215,6 +224,7 @@ def _incr( major=major, minor=minor, patch=patch, + release_num=release_num, pin_date=pin_date, ) @@ -346,11 +356,10 @@ def _update_cfg_from_vcs(cfg: config.Config, fetch: bool) -> config.Config: ), ) @click.option("--major", is_flag=True, default=False, help="Increment major component.") -@click.option("--minor", is_flag=True, default=False, help="Increment minor component.") -@click.option("--patch", is_flag=True, default=False, help="Increment patch component.") -@click.option( - "-p", "--pin-date", is_flag=True, default=False, help="Leave date components unchanged." -) +@click.option("-m", "--minor", is_flag=True, default=False, help="Increment minor component.") +@click.option("-p", "--patch", is_flag=True, default=False, help="Increment patch component.") +@click.option("-r", "--release-num", is_flag=True, default=False, help="Increment release number.") +@click.option("--pin-date", is_flag=True, default=False, help="Leave date components unchanged.") def bump( release : typ.Optional[str] = None, verbose : int = 0, @@ -360,6 +369,7 @@ def bump( major : bool = False, minor : bool = False, patch : bool = False, + release_num: bool = False, pin_date : bool = False, ) -> None: """Increment the current version string and update project files.""" @@ -386,6 +396,7 @@ def bump( major=major, minor=minor, patch=patch, + release_num=release_num, pin_date=pin_date, ) diff --git a/src/pycalver/v1version.py b/src/pycalver/v1version.py index 978eb39..7659d8e 100644 --- a/src/pycalver/v1version.py +++ b/src/pycalver/v1version.py @@ -378,6 +378,7 @@ def incr( major : bool = False, minor : bool = False, patch : bool = False, + release_num: bool = False, pin_date: bool = False, ) -> typ.Optional[str]: """Increment version string. @@ -400,14 +401,16 @@ def incr( cur_vinfo = cur_vinfo._replace(bid=lexid.next_id(cur_vinfo.bid)) - if release: - cur_vinfo = cur_vinfo._replace(tag=release) if major: cur_vinfo = cur_vinfo._replace(major=cur_vinfo.major + 1, minor=0, patch=0) if minor: cur_vinfo = cur_vinfo._replace(minor=cur_vinfo.minor + 1, patch=0) if patch: cur_vinfo = cur_vinfo._replace(patch=cur_vinfo.patch + 1) + if release_num: + cur_vinfo = cur_vinfo._replace(num=cur_vinfo.num + 1) + if release: + cur_vinfo = cur_vinfo._replace(tag=release) new_version = format_version(cur_vinfo, raw_pattern) if new_version == old_version: diff --git a/src/pycalver/v2version.py b/src/pycalver/v2version.py index fcf53ac..a4ef187 100644 --- a/src/pycalver/v2version.py +++ b/src/pycalver/v2version.py @@ -519,6 +519,7 @@ def incr( major : bool = False, minor : bool = False, patch : bool = False, + release_num: bool = False, pin_date: bool = False, ) -> typ.Optional[str]: """Increment version string. @@ -545,14 +546,18 @@ def incr( cur_vinfo = cur_vinfo._replace(bid=lexid.next_id(cur_vinfo.bid)) - if release: - cur_vinfo = cur_vinfo._replace(tag=release) if major: cur_vinfo = cur_vinfo._replace(major=cur_vinfo.major + 1, minor=0, patch=0) if minor: cur_vinfo = cur_vinfo._replace(minor=cur_vinfo.minor + 1, patch=0) if patch: cur_vinfo = cur_vinfo._replace(patch=cur_vinfo.patch + 1) + if release_num: + cur_vinfo = cur_vinfo._replace(num=cur_vinfo.num + 1) + if release: + if release != cur_vinfo.tag: + cur_vinfo = cur_vinfo._replace(num=0) + cur_vinfo = cur_vinfo._replace(tag=release) # TODO (mb 2020-09-20): New Rollover Behaviour: # Reset major, minor, patch to zero if any part to the left of it is incremented