mirror of
https://github.com/TECHNOFAB11/bumpver.git
synced 2025-12-12 14:30:09 +01:00
show pattern when --verbose
This commit is contained in:
parent
fb2f3f11fd
commit
e10f858c40
3 changed files with 45 additions and 34 deletions
|
|
@ -28,9 +28,7 @@ from . import v1version
|
||||||
from . import v2rewrite
|
from . import v2rewrite
|
||||||
from . import v2version
|
from . import v2version
|
||||||
from . import v1patterns
|
from . import v1patterns
|
||||||
|
from . import v2patterns
|
||||||
_VERBOSE = 0
|
|
||||||
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import pretty_traceback
|
import pretty_traceback
|
||||||
|
|
@ -45,7 +43,14 @@ click.disable_unicode_literals_warning = True
|
||||||
logger = logging.getLogger("pycalver.__main__")
|
logger = logging.getLogger("pycalver.__main__")
|
||||||
|
|
||||||
|
|
||||||
|
_VERBOSE = 0
|
||||||
|
|
||||||
|
|
||||||
def _configure_logging(verbose: int = 0) -> None:
|
def _configure_logging(verbose: int = 0) -> None:
|
||||||
|
# pylint:disable=global-statement; global flag is global.
|
||||||
|
global _VERBOSE
|
||||||
|
_VERBOSE = verbose
|
||||||
|
|
||||||
if verbose >= 2:
|
if verbose >= 2:
|
||||||
log_format = "%(asctime)s.%(msecs)03d %(levelname)-7s %(name)-17s - %(message)s"
|
log_format = "%(asctime)s.%(msecs)03d %(levelname)-7s %(name)-17s - %(message)s"
|
||||||
log_level = logging.DEBUG
|
log_level = logging.DEBUG
|
||||||
|
|
@ -102,9 +107,7 @@ def _validate_release_tag(release: typ.Optional[str]) -> None:
|
||||||
@click.option('-v', '--verbose', count=True, help="Control log level. -vv for debug level.")
|
@click.option('-v', '--verbose', count=True, help="Control log level. -vv for debug level.")
|
||||||
def cli(verbose: int = 0) -> None:
|
def cli(verbose: int = 0) -> None:
|
||||||
"""Automatically update PyCalVer version strings on python projects."""
|
"""Automatically update PyCalVer version strings on python projects."""
|
||||||
# pylint:disable=global-statement; global flag is global.
|
_configure_logging(verbose=max(_VERBOSE, verbose))
|
||||||
global _VERBOSE
|
|
||||||
_VERBOSE = verbose
|
|
||||||
|
|
||||||
|
|
||||||
@cli.command()
|
@cli.command()
|
||||||
|
|
@ -241,6 +244,14 @@ 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 has_v1_part:
|
||||||
|
pattern = v1patterns.compile_pattern(raw_pattern)
|
||||||
|
else:
|
||||||
|
pattern = v2patterns.compile_pattern(raw_pattern)
|
||||||
|
|
||||||
|
logger.info(f"Using pattern {raw_pattern}/{pattern.regexp.pattern}")
|
||||||
|
|
||||||
if has_v1_part:
|
if has_v1_part:
|
||||||
return v1version.incr(
|
return v1version.incr(
|
||||||
old_version,
|
old_version,
|
||||||
|
|
|
||||||
|
|
@ -406,8 +406,8 @@ def init(
|
||||||
DEFAULT_CONFIGPARSER_BASE_TMPL = """
|
DEFAULT_CONFIGPARSER_BASE_TMPL = """
|
||||||
[pycalver]
|
[pycalver]
|
||||||
current_version = "{initial_version}"
|
current_version = "{initial_version}"
|
||||||
version_pattern = "{{pycalver}}"
|
version_pattern = "vYYYY0M.BUILD[-RELEASE]"
|
||||||
commit_message = "bump version to {{new_version}}"
|
commit_message = "bump version {{old_version}} -> {{new_version}}"
|
||||||
commit = True
|
commit = True
|
||||||
tag = True
|
tag = True
|
||||||
push = True
|
push = True
|
||||||
|
|
@ -446,8 +446,8 @@ README.md =
|
||||||
DEFAULT_TOML_BASE_TMPL = """
|
DEFAULT_TOML_BASE_TMPL = """
|
||||||
[pycalver]
|
[pycalver]
|
||||||
current_version = "{initial_version}"
|
current_version = "{initial_version}"
|
||||||
version_pattern = "{{pycalver}}"
|
version_pattern = "vYYYY0M.BUILD[-RELEASE]"
|
||||||
commit_message = "bump version to {{new_version}}"
|
commit_message = "bump version {{old_version}} -> {{new_version}}"
|
||||||
commit = true
|
commit = true
|
||||||
tag = true
|
tag = true
|
||||||
push = true
|
push = true
|
||||||
|
|
|
||||||
|
|
@ -263,10 +263,10 @@ def parse_version_info(
|
||||||
return _parse_version_info(field_values)
|
return _parse_version_info(field_values)
|
||||||
|
|
||||||
|
|
||||||
def is_valid(version_str: str, raw_pattern: str = "vYYYY0M.BUILD[-RELEASE[NUM]]") -> bool:
|
def is_valid(version_str: str, raw_pattern: str = "vYYYY0M.BUILD[-RELEASE]") -> bool:
|
||||||
"""Check if a version matches a pattern.
|
"""Check if a version matches a pattern.
|
||||||
|
|
||||||
>>> is_valid("v201712.0033-beta", raw_pattern="vYYYY0M.BUILD[-RELEASE[NUM]]")
|
>>> is_valid("v201712.0033-beta", raw_pattern="vYYYY0M.BUILD[-RELEASE]")
|
||||||
True
|
True
|
||||||
>>> is_valid("v201712.0033-beta", raw_pattern="MAJOR.MINOR.PATCH")
|
>>> is_valid("v201712.0033-beta", raw_pattern="MAJOR.MINOR.PATCH")
|
||||||
False
|
False
|
||||||
|
|
@ -465,44 +465,44 @@ def format_version(vinfo: version.V2VersionInfo, raw_pattern: str) -> str:
|
||||||
>>> format_version(vinfo_a, raw_pattern="vYY.BLD[-PYTAGNUM]")
|
>>> format_version(vinfo_a, raw_pattern="vYY.BLD[-PYTAGNUM]")
|
||||||
'v7.33-b0'
|
'v7.33-b0'
|
||||||
|
|
||||||
>>> format_version(vinfo_a, raw_pattern="YYYY0M.BUILD[PYTAG[NUM]]")
|
|
||||||
'200701.0033b'
|
|
||||||
>>> format_version(vinfo_a, raw_pattern="vYY.BLD[-PYTAGNUM]")
|
>>> format_version(vinfo_a, raw_pattern="vYY.BLD[-PYTAGNUM]")
|
||||||
'v7.33-b0'
|
'v7.33-b0'
|
||||||
>>> format_version(vinfo_a, raw_pattern="v0Y.BLD[-RELEASE[NUM]]")
|
>>> format_version(vinfo_a, raw_pattern="YYYY0M.BUILD[PYTAG[NUM]]")
|
||||||
|
'200701.0033b'
|
||||||
|
>>> format_version(vinfo_a, raw_pattern="v0Y.BLD[-RELEASE]")
|
||||||
'v07.33-beta'
|
'v07.33-beta'
|
||||||
|
|
||||||
>>> format_version(vinfo_a, raw_pattern="vYYYY0M.BUILD[-RELEASE[NUM]]")
|
>>> format_version(vinfo_a, raw_pattern="vYYYY0M.BUILD[-RELEASE]")
|
||||||
'v200701.0033-beta'
|
'v200701.0033-beta'
|
||||||
>>> format_version(vinfo_b, raw_pattern="vYYYY0M.BUILD[-RELEASE[NUM]]")
|
>>> format_version(vinfo_b, raw_pattern="vYYYY0M.BUILD[-RELEASE]")
|
||||||
'v200712.0033-beta'
|
'v200712.0033-beta'
|
||||||
|
|
||||||
>>> format_version(vinfo_a, raw_pattern="vYYYYw0W.BUILD[-RELEASE[NUM]]")
|
>>> format_version(vinfo_a, raw_pattern="vYYYYw0W.BUILD[-RELEASE]")
|
||||||
'v2007w01.0033-beta'
|
'v2007w01.0033-beta'
|
||||||
>>> format_version(vinfo_a, raw_pattern="vYYYYwWW.BLD[-RELEASE[NUM]]")
|
>>> format_version(vinfo_a, raw_pattern="vYYYYwWW.BLD[-RELEASE]")
|
||||||
'v2007w1.33-beta'
|
'v2007w1.33-beta'
|
||||||
>>> format_version(vinfo_b, raw_pattern="vYYYYw0W.BUILD[-RELEASE[NUM]]")
|
>>> format_version(vinfo_b, raw_pattern="vYYYYw0W.BUILD[-RELEASE]")
|
||||||
'v2007w53.0033-beta'
|
'v2007w53.0033-beta'
|
||||||
|
|
||||||
>>> format_version(vinfo_a, raw_pattern="vYYYYd00J.BUILD[-RELEASE[NUM]]")
|
>>> format_version(vinfo_a, raw_pattern="vYYYYd00J.BUILD[-RELEASE]")
|
||||||
'v2007d001.0033-beta'
|
'v2007d001.0033-beta'
|
||||||
>>> format_version(vinfo_a, raw_pattern="vYYYYdJJJ.BUILD[-RELEASE[NUM]]")
|
>>> format_version(vinfo_a, raw_pattern="vYYYYdJJJ.BUILD[-RELEASE]")
|
||||||
'v2007d1.0033-beta'
|
'v2007d1.0033-beta'
|
||||||
>>> format_version(vinfo_b, raw_pattern="vYYYYd00J.BUILD[-RELEASE[NUM]]")
|
>>> format_version(vinfo_b, raw_pattern="vYYYYd00J.BUILD[-RELEASE]")
|
||||||
'v2007d365.0033-beta'
|
'v2007d365.0033-beta'
|
||||||
|
|
||||||
>>> format_version(vinfo_a, raw_pattern="vGGGGwVV.BLD[PYTAGNUM]")
|
>>> format_version(vinfo_a, raw_pattern="vGGGGwVV.BLD[PYTAGNUM]")
|
||||||
'v2007w1.33b0'
|
'v2007w1.33b0'
|
||||||
>>> format_version(vinfo_a, raw_pattern="vGGGGw0V.BUILD[-RELEASE[NUM]]")
|
>>> format_version(vinfo_a, raw_pattern="vGGGGw0V.BUILD[-RELEASE]")
|
||||||
'v2007w01.0033-beta'
|
'v2007w01.0033-beta'
|
||||||
>>> format_version(vinfo_b, raw_pattern="vGGGGw0V.BUILD[-RELEASE[NUM]]")
|
>>> format_version(vinfo_b, raw_pattern="vGGGGw0V.BUILD[-RELEASE]")
|
||||||
'v2008w01.0033-beta'
|
'v2008w01.0033-beta'
|
||||||
|
|
||||||
>>> vinfo_c = vinfo_b._replace(major=1, minor=2, patch=34, tag='final')
|
>>> vinfo_c = vinfo_b._replace(major=1, minor=2, patch=34, tag='final')
|
||||||
|
|
||||||
>>> format_version(vinfo_c, raw_pattern="vYYYYwWW.BUILD-RELEASE")
|
>>> format_version(vinfo_c, raw_pattern="vYYYYwWW.BUILD-RELEASE")
|
||||||
'v2007w53.0033-final'
|
'v2007w53.0033-final'
|
||||||
>>> format_version(vinfo_c, raw_pattern="vYYYYwWW.BUILD[-RELEASE[NUM]]")
|
>>> format_version(vinfo_c, raw_pattern="vYYYYwWW.BUILD[-RELEASE]")
|
||||||
'v2007w53.0033'
|
'v2007w53.0033'
|
||||||
|
|
||||||
>>> format_version(vinfo_c, raw_pattern="vMAJOR.MINOR.PATCH")
|
>>> format_version(vinfo_c, raw_pattern="vMAJOR.MINOR.PATCH")
|
||||||
|
|
@ -511,21 +511,21 @@ def format_version(vinfo: version.V2VersionInfo, raw_pattern: str) -> str:
|
||||||
>>> vinfo_d = vinfo_b._replace(major=1, minor=0, patch=0, tag='final')
|
>>> vinfo_d = vinfo_b._replace(major=1, minor=0, patch=0, tag='final')
|
||||||
>>> format_version(vinfo_d, raw_pattern="vMAJOR.MINOR.PATCH-RELEASENUM")
|
>>> format_version(vinfo_d, raw_pattern="vMAJOR.MINOR.PATCH-RELEASENUM")
|
||||||
'v1.0.0-final0'
|
'v1.0.0-final0'
|
||||||
>>> format_version(vinfo_d, raw_pattern="vMAJOR.MINOR.PATCH-RELEASE[NUM]")
|
>>> format_version(vinfo_d, raw_pattern="vMAJOR.MINOR.PATCH-RELEASE")
|
||||||
'v1.0.0-final'
|
'v1.0.0-final'
|
||||||
>>> format_version(vinfo_d, raw_pattern="vMAJOR.MINOR.PATCH-RELEASE")
|
>>> format_version(vinfo_d, raw_pattern="vMAJOR.MINOR.PATCH-RELEASE")
|
||||||
'v1.0.0-final'
|
'v1.0.0-final'
|
||||||
>>> format_version(vinfo_d, raw_pattern="vMAJOR.MINOR.PATCH[-RELEASE[NUM]]")
|
>>> format_version(vinfo_d, raw_pattern="vMAJOR.MINOR.PATCH[-RELEASE]")
|
||||||
'v1.0.0'
|
'v1.0.0'
|
||||||
>>> format_version(vinfo_d, raw_pattern="vMAJOR.MINOR[.PATCH[-RELEASE[NUM]]]")
|
>>> format_version(vinfo_d, raw_pattern="vMAJOR.MINOR[.PATCH[-RELEASE]]")
|
||||||
'v1.0'
|
'v1.0'
|
||||||
>>> format_version(vinfo_d, raw_pattern="vMAJOR[.MINOR[.PATCH[-RELEASE[NUM]]]]")
|
>>> format_version(vinfo_d, raw_pattern="vMAJOR[.MINOR[.PATCH[-RELEASE]]]")
|
||||||
'v1'
|
'v1'
|
||||||
|
|
||||||
>>> vinfo_d = vinfo_b._replace(major=1, minor=0, patch=2, tag='rc', pytag='rc', num=0)
|
>>> vinfo_d = vinfo_b._replace(major=1, minor=0, patch=2, tag='rc', pytag='rc', num=0)
|
||||||
>>> format_version(vinfo_d, raw_pattern="vMAJOR[.MINOR[.PATCH]]")
|
>>> format_version(vinfo_d, raw_pattern="vMAJOR[.MINOR[.PATCH]]")
|
||||||
'v1.0.2'
|
'v1.0.2'
|
||||||
>>> format_version(vinfo_d, raw_pattern="vMAJOR[.MINOR[.PATCH[-RELEASE[NUM]]]]")
|
>>> format_version(vinfo_d, raw_pattern="vMAJOR[.MINOR[.PATCH[-RELEASE]]]")
|
||||||
'v1.0.2-rc'
|
'v1.0.2-rc'
|
||||||
>>> format_version(vinfo_d, raw_pattern="vMAJOR[.MINOR[.PATCH[PYTAGNUM]]]")
|
>>> format_version(vinfo_d, raw_pattern="vMAJOR[.MINOR[.PATCH[PYTAGNUM]]]")
|
||||||
'v1.0.2rc0'
|
'v1.0.2rc0'
|
||||||
|
|
@ -533,11 +533,11 @@ def format_version(vinfo: version.V2VersionInfo, raw_pattern: str) -> str:
|
||||||
'v1.0.2'
|
'v1.0.2'
|
||||||
|
|
||||||
>>> vinfo_d = vinfo_b._replace(major=1, minor=0, patch=0, tag='rc', num=2)
|
>>> vinfo_d = vinfo_b._replace(major=1, minor=0, patch=0, tag='rc', num=2)
|
||||||
>>> format_version(vinfo_d, raw_pattern="vMAJOR[.MINOR[.PATCH[-RELEASE[NUM]]]]")
|
>>> format_version(vinfo_d, raw_pattern="vMAJOR[.MINOR[.PATCH[-RELEASENUM]]]")
|
||||||
'v1.0.0-rc2'
|
'v1.0.0-rc2'
|
||||||
|
|
||||||
>>> vinfo_d = vinfo_b._replace(major=1, minor=0, patch=0, tag='rc', num=2)
|
>>> vinfo_d = vinfo_b._replace(major=1, minor=0, patch=0, tag='rc', num=2)
|
||||||
>>> format_version(vinfo_d, raw_pattern='__version__ = "vMAJOR[.MINOR[.PATCH[-RELEASE[NUM]]]]"')
|
>>> format_version(vinfo_d, raw_pattern='__version__ = "vMAJOR[.MINOR[.PATCH[-RELEASENUM]]]"')
|
||||||
'__version__ = "v1.0.0-rc2"'
|
'__version__ = "v1.0.0-rc2"'
|
||||||
"""
|
"""
|
||||||
part_values = _format_part_values(vinfo)
|
part_values = _format_part_values(vinfo)
|
||||||
|
|
@ -598,7 +598,7 @@ def is_valid_week_pattern(raw_pattern) -> bool:
|
||||||
|
|
||||||
def incr(
|
def incr(
|
||||||
old_version: str,
|
old_version: str,
|
||||||
raw_pattern: str = "vYYYY0M.BUILD[-RELEASE[NUM]]",
|
raw_pattern: str = "vYYYY0M.BUILD[-RELEASE]",
|
||||||
*,
|
*,
|
||||||
release : typ.Optional[str] = None,
|
release : typ.Optional[str] = None,
|
||||||
major : bool = False,
|
major : bool = False,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue