mirror of
https://github.com/TECHNOFAB11/bumpver.git
synced 2025-12-12 14:30:09 +01:00
more consistent internal naming (release -> tag)
This commit is contained in:
parent
879ff4a945
commit
98647519c2
4 changed files with 31 additions and 28 deletions
|
|
@ -69,7 +69,7 @@ def _configure_logging(verbose: int = 0) -> None:
|
||||||
logger.debug("Logging configured.")
|
logger.debug("Logging configured.")
|
||||||
|
|
||||||
|
|
||||||
VALID_RELEASE_VALUES = ("alpha", "beta", "rc", "post", "final")
|
VALID_RELEASE_TAG_VALUES = ("alpha", "beta", "rc", "post", "final")
|
||||||
|
|
||||||
|
|
||||||
_current_date = dt.date.today().isoformat()
|
_current_date = dt.date.today().isoformat()
|
||||||
|
|
@ -93,15 +93,15 @@ def _validate_date(date: typ.Optional[str], pin_date: bool) -> typ.Optional[dt.d
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
def _validate_release_tag(release: typ.Optional[str]) -> None:
|
def _validate_release_tag(tag: typ.Optional[str]) -> None:
|
||||||
if release is None:
|
if tag is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
if release in VALID_RELEASE_VALUES:
|
if tag in VALID_RELEASE_TAG_VALUES:
|
||||||
return
|
return
|
||||||
|
|
||||||
logger.error(f"Invalid argument --release={release}")
|
logger.error(f"Invalid argument --release={tag}")
|
||||||
logger.error(f"Valid arguments are: {', '.join(VALID_RELEASE_VALUES)}")
|
logger.error(f"Valid arguments are: {', '.join(VALID_RELEASE_TAG_VALUES)}")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -124,7 +124,7 @@ def cli(verbose: int = 0) -> None:
|
||||||
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(VALID_RELEASE_VALUES)}."
|
f"{', '.join(VALID_RELEASE_TAG_VALUES)}."
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
@click.option("--major" , is_flag=True, default=False, help="Increment major component.")
|
@click.option("--major" , is_flag=True, default=False, help="Increment major component.")
|
||||||
|
|
@ -154,13 +154,14 @@ def test(
|
||||||
_configure_logging(verbose=max(_VERBOSE, verbose))
|
_configure_logging(verbose=max(_VERBOSE, verbose))
|
||||||
raw_pattern = pattern # use internal naming convention
|
raw_pattern = pattern # use internal naming convention
|
||||||
|
|
||||||
_validate_release_tag(release)
|
tag = release # use internal naming convention
|
||||||
|
_validate_release_tag(tag)
|
||||||
_date = _validate_date(date, pin_date)
|
_date = _validate_date(date, pin_date)
|
||||||
|
|
||||||
new_version = _incr(
|
new_version = incr_dispatch(
|
||||||
old_version,
|
old_version,
|
||||||
raw_pattern=raw_pattern,
|
raw_pattern=raw_pattern,
|
||||||
release=release,
|
tag=tag,
|
||||||
major=major,
|
major=major,
|
||||||
minor=minor,
|
minor=minor,
|
||||||
patch=patch,
|
patch=patch,
|
||||||
|
|
@ -337,11 +338,11 @@ def _print_diff(cfg: config.Config, new_version: str) -> None:
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
def _incr(
|
def incr_dispatch(
|
||||||
old_version: str,
|
old_version: str,
|
||||||
raw_pattern: str,
|
raw_pattern: str,
|
||||||
*,
|
*,
|
||||||
release : str = None,
|
tag : str = None,
|
||||||
major : bool = False,
|
major : bool = False,
|
||||||
minor : bool = False,
|
minor : bool = False,
|
||||||
patch : bool = False,
|
patch : bool = False,
|
||||||
|
|
@ -351,6 +352,7 @@ def _incr(
|
||||||
) -> typ.Optional[str]:
|
) -> typ.Optional[str]:
|
||||||
v1_parts = list(v1patterns.PART_PATTERNS) + list(v1patterns.FULL_PART_FORMATS)
|
v1_parts = list(v1patterns.PART_PATTERNS) + list(v1patterns.FULL_PART_FORMATS)
|
||||||
has_v1_part = any("{" + part + "}" in raw_pattern for part in v1_parts)
|
has_v1_part = any("{" + part + "}" in raw_pattern for part in v1_parts)
|
||||||
|
|
||||||
if _VERBOSE:
|
if _VERBOSE:
|
||||||
if has_v1_part:
|
if has_v1_part:
|
||||||
pattern = v1patterns.compile_pattern(raw_pattern)
|
pattern = v1patterns.compile_pattern(raw_pattern)
|
||||||
|
|
@ -364,7 +366,7 @@ def _incr(
|
||||||
return v1version.incr(
|
return v1version.incr(
|
||||||
old_version,
|
old_version,
|
||||||
raw_pattern=raw_pattern,
|
raw_pattern=raw_pattern,
|
||||||
release=release,
|
tag=tag,
|
||||||
major=major,
|
major=major,
|
||||||
minor=minor,
|
minor=minor,
|
||||||
patch=patch,
|
patch=patch,
|
||||||
|
|
@ -376,7 +378,7 @@ def _incr(
|
||||||
return v2version.incr(
|
return v2version.incr(
|
||||||
old_version,
|
old_version,
|
||||||
raw_pattern=raw_pattern,
|
raw_pattern=raw_pattern,
|
||||||
release=release,
|
tag=tag,
|
||||||
major=major,
|
major=major,
|
||||||
minor=minor,
|
minor=minor,
|
||||||
patch=patch,
|
patch=patch,
|
||||||
|
|
@ -501,7 +503,7 @@ def _update_cfg_from_vcs(cfg: config.Config, fetch: bool) -> config.Config:
|
||||||
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(VALID_RELEASE_VALUES)}."
|
f"{', '.join(VALID_RELEASE_TAG_VALUES)}."
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
@click.option(
|
@click.option(
|
||||||
|
|
@ -542,7 +544,8 @@ def bump(
|
||||||
verbose = max(_VERBOSE, verbose)
|
verbose = max(_VERBOSE, verbose)
|
||||||
_configure_logging(verbose)
|
_configure_logging(verbose)
|
||||||
|
|
||||||
_validate_release_tag(release)
|
tag = release # use internal naming convention
|
||||||
|
_validate_release_tag(tag)
|
||||||
_date = _validate_date(date, pin_date)
|
_date = _validate_date(date, pin_date)
|
||||||
|
|
||||||
_, cfg = config.init(project_path=".")
|
_, cfg = config.init(project_path=".")
|
||||||
|
|
@ -554,10 +557,10 @@ def bump(
|
||||||
cfg = _update_cfg_from_vcs(cfg, fetch)
|
cfg = _update_cfg_from_vcs(cfg, fetch)
|
||||||
|
|
||||||
old_version = cfg.current_version
|
old_version = cfg.current_version
|
||||||
new_version = _incr(
|
new_version = incr_dispatch(
|
||||||
old_version,
|
old_version,
|
||||||
raw_pattern=cfg.version_pattern,
|
raw_pattern=cfg.version_pattern,
|
||||||
release=release,
|
tag=tag,
|
||||||
major=major,
|
major=major,
|
||||||
minor=minor,
|
minor=minor,
|
||||||
patch=patch,
|
patch=patch,
|
||||||
|
|
|
||||||
|
|
@ -374,7 +374,7 @@ def incr(
|
||||||
old_version: str,
|
old_version: str,
|
||||||
raw_pattern: str = "{pycalver}",
|
raw_pattern: str = "{pycalver}",
|
||||||
*,
|
*,
|
||||||
release : typ.Optional[str] = None,
|
tag : typ.Optional[str] = None,
|
||||||
major : bool = False,
|
major : bool = False,
|
||||||
minor : bool = False,
|
minor : bool = False,
|
||||||
patch : bool = False,
|
patch : bool = False,
|
||||||
|
|
@ -410,8 +410,8 @@ def incr(
|
||||||
cur_vinfo = cur_vinfo._replace(patch=cur_vinfo.patch + 1)
|
cur_vinfo = cur_vinfo._replace(patch=cur_vinfo.patch + 1)
|
||||||
if release_num:
|
if release_num:
|
||||||
raise NotImplementedError("--release-num not supported for old style patterns")
|
raise NotImplementedError("--release-num not supported for old style patterns")
|
||||||
if release:
|
if tag:
|
||||||
cur_vinfo = cur_vinfo._replace(tag=release)
|
cur_vinfo = cur_vinfo._replace(tag=tag)
|
||||||
|
|
||||||
new_version = format_version(cur_vinfo, raw_pattern)
|
new_version = format_version(cur_vinfo, raw_pattern)
|
||||||
if new_version == old_version:
|
if new_version == old_version:
|
||||||
|
|
|
||||||
|
|
@ -638,7 +638,7 @@ def incr(
|
||||||
old_version: str,
|
old_version: str,
|
||||||
raw_pattern: str = "vYYYY0M.BUILD[-RELEASE]",
|
raw_pattern: str = "vYYYY0M.BUILD[-RELEASE]",
|
||||||
*,
|
*,
|
||||||
release : typ.Optional[str] = None,
|
tag : typ.Optional[str] = None,
|
||||||
major : bool = False,
|
major : bool = False,
|
||||||
minor : bool = False,
|
minor : bool = False,
|
||||||
patch : bool = False,
|
patch : bool = False,
|
||||||
|
|
|
||||||
|
|
@ -22,20 +22,20 @@ def test_bump_beta():
|
||||||
cur_version = "v201712.0001-beta"
|
cur_version = "v201712.0001-beta"
|
||||||
assert cur_version < v1version.incr(cur_version)
|
assert cur_version < v1version.incr(cur_version)
|
||||||
assert v1version.incr(cur_version).endswith("-beta")
|
assert v1version.incr(cur_version).endswith("-beta")
|
||||||
assert v1version.incr(cur_version, release="alpha").endswith("-alpha")
|
assert v1version.incr(cur_version, tag="alpha").endswith("-alpha")
|
||||||
assert v1version.incr(cur_version, release="final").endswith("0002")
|
assert v1version.incr(cur_version, tag="final").endswith("0002")
|
||||||
|
|
||||||
|
|
||||||
def test_bump_final():
|
def test_bump_final():
|
||||||
cur_version = "v201712.0001"
|
cur_version = "v201712.0001"
|
||||||
assert cur_version < v1version.incr(cur_version)
|
assert cur_version < v1version.incr(cur_version)
|
||||||
assert v1version.incr(cur_version).endswith(".0002")
|
assert v1version.incr(cur_version).endswith(".0002")
|
||||||
assert v1version.incr(cur_version, release="alpha").endswith("-alpha")
|
assert v1version.incr(cur_version, tag="alpha").endswith("-alpha")
|
||||||
|
|
||||||
assert v1version.incr(cur_version, release="final").endswith(".0002")
|
assert v1version.incr(cur_version, tag="final").endswith(".0002")
|
||||||
|
|
||||||
pre_version = cur_version + "-beta"
|
pre_version = cur_version + "-beta"
|
||||||
assert v1version.incr(pre_version, release="final").endswith(".0002")
|
assert v1version.incr(pre_version, tag="final").endswith(".0002")
|
||||||
|
|
||||||
|
|
||||||
def test_bump_future():
|
def test_bump_future():
|
||||||
|
|
@ -56,7 +56,7 @@ def test_bump_random(monkeypatch):
|
||||||
for _ in range(1000):
|
for _ in range(1000):
|
||||||
cur_date += dt.timedelta(days=int((1 + random.random()) ** 10))
|
cur_date += dt.timedelta(days=int((1 + random.random()) ** 10))
|
||||||
new_version = v1version.incr(
|
new_version = v1version.incr(
|
||||||
cur_version, release=random.choice([None, "alpha", "beta", "rc", "final", "post"])
|
cur_version, tag=random.choice([None, "alpha", "beta", "rc", "final", "post"])
|
||||||
)
|
)
|
||||||
assert cur_version < new_version
|
assert cur_version < new_version
|
||||||
cur_version = new_version
|
cur_version = new_version
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue