mirror of
https://github.com/TECHNOFAB11/bumpver.git
synced 2025-12-12 14:30:09 +01:00
fix: patterns/replacements for "-final" releases
This commit is contained in:
parent
f571d95093
commit
8dfcea90c4
7 changed files with 78 additions and 40 deletions
|
|
@ -1,7 +1,12 @@
|
||||||
# Changelog for https://gitlab.com/mbarkhau/pycalver
|
# Changelog for https://gitlab.com/mbarkhau/pycalver
|
||||||
|
|
||||||
|
|
||||||
## v201812.0016
|
## v201812.0018
|
||||||
|
|
||||||
|
- Fixed: Better handling of pattern replacements with "-final" releases.
|
||||||
|
|
||||||
|
|
||||||
|
## v201812.0017
|
||||||
|
|
||||||
- Fixed #2 on github. `pycalver init` was broken.
|
- Fixed #2 on github. `pycalver init` was broken.
|
||||||
- Fixed pattern escaping issues.
|
- Fixed pattern escaping issues.
|
||||||
|
|
|
||||||
44
README.md
44
README.md
|
|
@ -441,8 +441,8 @@ INFO - New Version: v201809.0002-rc
|
||||||
+[![PyCalVer v201812.0017][version_img]][version_ref]
|
+[![PyCalVer v201812.0017][version_img]][version_ref]
|
||||||
[![PyPI Releases][pypi_img]][pypi_ref]
|
[![PyPI Releases][pypi_img]][pypi_ref]
|
||||||
|
|
||||||
--- myprojcet/__init__.py
|
--- myproject/__init__.py
|
||||||
+++ myprojcet/__init__.py
|
+++ myproject/__init__.py
|
||||||
@@ -1,1 +1,1 @@
|
@@ -1,1 +1,1 @@
|
||||||
-__version__ = "v201809.0001-beta"
|
-__version__ = "v201809.0001-beta"
|
||||||
+__version__ = "v201809.0002-rc"
|
+__version__ = "v201809.0002-rc"
|
||||||
|
|
@ -478,34 +478,42 @@ use, everything else in a pattern is treated as literal text.
|
||||||
| `{release_tag}` | alpha |
|
| `{release_tag}` | alpha |
|
||||||
|
|
||||||
|
|
||||||
Note that the separator/prefix characters can be part of what is
|
There are two limitations to keep in mind:
|
||||||
matched and generated for a given placeholder. In other words,
|
|
||||||
assuming you have the following text in your README.md (note the
|
1. A version string cannot span multiple lines.
|
||||||
two dashes before alpha):
|
2. There is no way to escape "-", "." characters (yet).
|
||||||
|
|
||||||
|
The lack of escaping may for example be an issue with badge URLs.
|
||||||
|
You may want to put the following text in your README.md (note the
|
||||||
|
two dashes before `beta` are parsed as a literal dash by shields.io):
|
||||||
|
|
||||||
```
|
```
|
||||||
https://img.shields.io/badge/PyCalVer-v201812.0016-None-blue.svg
|
https://img.shields.io/badge/myproject-v201812.0116--beta-blue.svg
|
||||||
```
|
```
|
||||||
|
|
||||||
An appropriate pattern would be:
|
While could use the following pattern, which will work for a while:
|
||||||
|
|
||||||
```ini
|
```ini
|
||||||
README.md =
|
README.md =
|
||||||
/badge/PyCalVer {calver}{build}-{release}-blue.svg
|
/badge/myproject-v{year}{month}.{build_no}--{release_tag}-blue.svg
|
||||||
```
|
```
|
||||||
|
|
||||||
Notice that neither the "v" prefix, nor the "." and "-"
|
This will eventually break though, when you do a `final` release, at
|
||||||
separators are included in the pattern text, as they are
|
which point the following will be put in your README.md:
|
||||||
respectively part of the `calver`, `build` and `release`
|
|
||||||
placeholders. Alternatively you can be more explicit.
|
|
||||||
|
|
||||||
```ini
|
```
|
||||||
README.md =
|
https://img.shields.io/badge/myproject-v201812.0117--final-blue.svg
|
||||||
/badge/PyCalVer v{year}{month}.{build_no}--{release_tag}-blue.svg
|
|
||||||
```
|
```
|
||||||
|
|
||||||
One limitation to keep in mind is that a version string cannot
|
Whereas what you probably wanted was this:
|
||||||
span multiple lines.
|
|
||||||
|
```
|
||||||
|
https://img.shields.io/badge/myproject-v201812.0117-blue.svg
|
||||||
|
```
|
||||||
|
|
||||||
|
I think we can all agree that this is a travesty and the author
|
||||||
|
should be ashamed for releasing PyCalVer with such a monumental
|
||||||
|
deficiency.
|
||||||
|
|
||||||
|
|
||||||
### Bump It Up
|
### Bump It Up
|
||||||
|
|
|
||||||
|
|
@ -57,11 +57,11 @@ def _init_logging(verbose: int = 0) -> None:
|
||||||
|
|
||||||
|
|
||||||
def _validate_release_tag(release: str) -> None:
|
def _validate_release_tag(release: str) -> None:
|
||||||
if release == 'final' or release in parse.VALID_RELEASE_VALUES:
|
if release in parse.VALID_RELEASE_VALUES:
|
||||||
return
|
return
|
||||||
|
|
||||||
log.error(f"Invalid argument --release={release}")
|
log.error(f"Invalid argument --release={release}")
|
||||||
log.error(f"Valid arguments are: final, {', '.join(parse.VALID_RELEASE_VALUES)}")
|
log.error(f"Valid arguments are: {', '.join(parse.VALID_RELEASE_VALUES)}")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -235,7 +235,7 @@ def _bump(cfg: config.Config, new_version: str, allow_dirty: bool = False) -> No
|
||||||
metavar="<name>",
|
metavar="<name>",
|
||||||
help=(
|
help=(
|
||||||
f"Override release name of current_version. Valid options are: "
|
f"Override release name of current_version. Valid options are: "
|
||||||
f"{', '.join(parse.VALID_RELEASE_VALUES)} and final."
|
f"{', '.join(parse.VALID_RELEASE_VALUES)}."
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
@click.option(
|
@click.option(
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ import typing as typ
|
||||||
log = logging.getLogger("pycalver.parse")
|
log = logging.getLogger("pycalver.parse")
|
||||||
|
|
||||||
|
|
||||||
VALID_RELEASE_VALUES = ("alpha", "beta", "dev", "rc", "post")
|
VALID_RELEASE_VALUES = ("alpha", "beta", "dev", "rc", "post", "final")
|
||||||
|
|
||||||
|
|
||||||
PATTERN_ESCAPES = [
|
PATTERN_ESCAPES = [
|
||||||
|
|
@ -38,12 +38,14 @@ PATTERN_ESCAPES = [
|
||||||
|
|
||||||
RE_PATTERN_PARTS = {
|
RE_PATTERN_PARTS = {
|
||||||
'pep440_version': r"\d{6}\.[1-9]\d*(a|b|dev|rc|post)?\d*",
|
'pep440_version': r"\d{6}\.[1-9]\d*(a|b|dev|rc|post)?\d*",
|
||||||
'version' : r"v\d{6}\.\d{4,}(\-(alpha|beta|dev|rc|post))?",
|
'version' : r"v\d{6}\.\d{4,}(\-(alpha|beta|dev|rc|post|final))?",
|
||||||
'calver' : r"v\d{6}",
|
'calver' : r"v\d{6}",
|
||||||
|
'year' : r"\d{4}",
|
||||||
|
'month' : r"\d{2}",
|
||||||
'build' : r"\.\d{4,}",
|
'build' : r"\.\d{4,}",
|
||||||
'build_no' : r"\d{4,}",
|
'build_no' : r"\d{4,}",
|
||||||
'release' : r"(\-(alpha|beta|dev|rc|post))?",
|
'release' : r"(\-(alpha|beta|dev|rc|post|final))?",
|
||||||
'release_tag' : r"(alpha|beta|dev|rc|post)?",
|
'release_tag' : r"(alpha|beta|dev|rc|post|final)?",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -100,6 +100,10 @@ def parse_version_info(version_str: str) -> VersionInfo:
|
||||||
|
|
||||||
kwargs = match.groupdict()
|
kwargs = match.groupdict()
|
||||||
kwargs['pep440_version'] = pycalver_to_pep440(kwargs['version'])
|
kwargs['pep440_version'] = pycalver_to_pep440(kwargs['version'])
|
||||||
|
if kwargs['release'] is None:
|
||||||
|
kwargs['release'] = "-final"
|
||||||
|
if kwargs['release_tag'] is None:
|
||||||
|
kwargs['release_tag'] = "final"
|
||||||
return VersionInfo(**kwargs)
|
return VersionInfo(**kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -144,6 +148,9 @@ def incr(old_version: str, *, release: str = None) -> str:
|
||||||
else:
|
else:
|
||||||
new_release = release
|
new_release = release
|
||||||
|
|
||||||
|
if new_release == 'final':
|
||||||
|
new_release = None
|
||||||
|
|
||||||
new_version = new_calver + "." + new_build
|
new_version = new_calver + "." + new_build
|
||||||
if new_release:
|
if new_release:
|
||||||
new_version += "-" + new_release
|
new_version += "-" + new_release
|
||||||
|
|
|
||||||
|
|
@ -2,22 +2,30 @@ from pycalver import rewrite
|
||||||
|
|
||||||
|
|
||||||
REWRITE_FIXTURE = """
|
REWRITE_FIXTURE = """
|
||||||
# This file is part of the pycalver project
|
|
||||||
# https://github.com/mbarkhau/pycalver
|
|
||||||
#
|
|
||||||
# (C) 2018 Manuel Barkhau (@mbarkhau)
|
|
||||||
# SPDX-License-Identifier: MIT
|
# SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
__version__ = "v201809.0002-beta"
|
__version__ = "v201809.0002-beta"
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
def test_rewrite_lines():
|
def test_rewrite_lines():
|
||||||
old_lines = REWRITE_FIXTURE.splitlines()
|
old_lines = REWRITE_FIXTURE.splitlines()
|
||||||
patterns = ['__version__ = "{version}"']
|
patterns = ['__version__ = "{version}"']
|
||||||
new_version = "v201809.0003"
|
new_lines = rewrite.rewrite_lines(patterns, "v201911.0003", old_lines)
|
||||||
new_lines = rewrite.rewrite_lines(patterns, new_version, old_lines)
|
|
||||||
|
|
||||||
assert len(new_lines) == len(old_lines)
|
assert len(new_lines) == len(old_lines)
|
||||||
assert new_version not in "\n".join(old_lines)
|
assert "v201911.0003" not in "\n".join(old_lines)
|
||||||
assert new_version in "\n".join(new_lines)
|
assert "v201911.0003" in "\n".join(new_lines)
|
||||||
|
|
||||||
|
|
||||||
|
def test_rewrite_final():
|
||||||
|
# Patterns written with {release_tag} placeholder preserve
|
||||||
|
# the release tag even if the new version is -final
|
||||||
|
|
||||||
|
old_lines = REWRITE_FIXTURE.splitlines()
|
||||||
|
patterns = ['__version__ = "v{year}{month}.{build_no}-{release_tag}"']
|
||||||
|
new_lines = rewrite.rewrite_lines(patterns, "v201911.0003", old_lines)
|
||||||
|
|
||||||
|
assert len(new_lines) == len(old_lines)
|
||||||
|
assert "v201911.0003" not in "\n".join(old_lines)
|
||||||
|
assert "None" not in "\n".join(new_lines)
|
||||||
|
assert "v201911.0003-final" in "\n".join(new_lines)
|
||||||
|
|
|
||||||
|
|
@ -24,9 +24,13 @@ def test_bump_final():
|
||||||
calver = version.current_calver()
|
calver = version.current_calver()
|
||||||
cur_version = calver + ".0001"
|
cur_version = calver + ".0001"
|
||||||
assert cur_version < version.incr(cur_version)
|
assert cur_version < version.incr(cur_version)
|
||||||
|
assert version.incr(cur_version).endswith(".0002")
|
||||||
assert version.incr(cur_version, release="alpha").endswith("-alpha")
|
assert version.incr(cur_version, release="alpha").endswith("-alpha")
|
||||||
assert version.incr(cur_version, release="final").endswith("0002")
|
|
||||||
assert version.incr(cur_version).endswith("0002")
|
assert version.incr(cur_version, release="final").endswith(".0002")
|
||||||
|
|
||||||
|
pre_version = cur_version + "-beta"
|
||||||
|
assert version.incr(pre_version, release="final").endswith(".0002")
|
||||||
|
|
||||||
|
|
||||||
def test_bump_future():
|
def test_bump_future():
|
||||||
|
|
@ -65,6 +69,8 @@ def test_parse_version_info():
|
||||||
assert version_nfo.month == "12"
|
assert version_nfo.month == "12"
|
||||||
assert version_nfo.build == ".0001"
|
assert version_nfo.build == ".0001"
|
||||||
assert version_nfo.release == "-alpha"
|
assert version_nfo.release == "-alpha"
|
||||||
|
assert version_nfo.build_no == "0001"
|
||||||
|
assert version_nfo.release_tag == "alpha"
|
||||||
|
|
||||||
version_str = "v201712.0001"
|
version_str = "v201712.0001"
|
||||||
version_nfo = version.parse_version_info(version_str)
|
version_nfo = version.parse_version_info(version_str)
|
||||||
|
|
@ -75,7 +81,9 @@ def test_parse_version_info():
|
||||||
assert version_nfo.year == "2017"
|
assert version_nfo.year == "2017"
|
||||||
assert version_nfo.month == "12"
|
assert version_nfo.month == "12"
|
||||||
assert version_nfo.build == ".0001"
|
assert version_nfo.build == ".0001"
|
||||||
assert version_nfo.release is None
|
assert version_nfo.release == "-final"
|
||||||
|
assert version_nfo.build_no == "0001"
|
||||||
|
assert version_nfo.release_tag == "final"
|
||||||
|
|
||||||
|
|
||||||
def test_readme_pycalver1():
|
def test_readme_pycalver1():
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue