mirror of
https://github.com/TECHNOFAB11/bumpver.git
synced 2025-12-16 16:23:51 +01:00
pycalver -> bumpver
This commit is contained in:
parent
2c01699b99
commit
bbf5bfa31c
35 changed files with 764 additions and 1235 deletions
|
|
@ -3,6 +3,6 @@
|
|||
#
|
||||
# Copyright (c) 2018-2020 Manuel Barkhau (mbarkhau@gmail.com) - MIT License
|
||||
# SPDX-License-Identifier: MIT
|
||||
"""PyCalVer: CalVer for Python Packages."""
|
||||
"""BumpVer: A CLI program for versioning."""
|
||||
|
||||
__version__ = "v2020.1041-beta"
|
||||
__version__ = "2020.1041-beta"
|
||||
|
|
@ -5,9 +5,9 @@
|
|||
# Copyright (c) 2018-2020 Manuel Barkhau (mbarkhau@gmail.com) - MIT License
|
||||
# SPDX-License-Identifier: MIT
|
||||
"""
|
||||
__main__ module for PyCalVer.
|
||||
__main__ module for BumpVer.
|
||||
|
||||
Enables use as module: $ python -m pycalver --version
|
||||
Enables use as module: $ python -m bumpver --version
|
||||
"""
|
||||
from . import cli
|
||||
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
#
|
||||
# Copyright (c) 2018-2020 Manuel Barkhau (mbarkhau@gmail.com) - MIT License
|
||||
# SPDX-License-Identifier: MIT
|
||||
"""cli module for PyCalVer."""
|
||||
"""cli module for BumpVer."""
|
||||
import io
|
||||
import sys
|
||||
import typing as typ
|
||||
|
|
@ -39,7 +39,7 @@ except ImportError:
|
|||
|
||||
click.disable_unicode_literals_warning = True
|
||||
|
||||
logger = logging.getLogger("pycalver2.cli")
|
||||
logger = logging.getLogger("bumpver.cli")
|
||||
|
||||
|
||||
_VERBOSE = 0
|
||||
|
|
@ -140,7 +140,7 @@ def _log_no_change(subcmd: str, version_pattern: str, old_version: str) -> None:
|
|||
]
|
||||
if available_flags:
|
||||
available_flags_str = "/".join(available_flags)
|
||||
logger.info(f"Perhaps try: calver {subcmd} {available_flags_str} ")
|
||||
logger.info(f"Perhaps try: bumpver {subcmd} {available_flags_str} ")
|
||||
|
||||
|
||||
def _get_normalized_pattern(raw_pattern: str, version_pattern: typ.Optional[str]) -> str:
|
||||
|
|
@ -164,7 +164,7 @@ def _get_normalized_pattern(raw_pattern: str, version_pattern: typ.Optional[str]
|
|||
|
||||
|
||||
@click.group()
|
||||
@click.version_option(version="v2020.1041-beta")
|
||||
@click.version_option(version="2020.1041-beta")
|
||||
@click.help_option()
|
||||
@click.option('-v', '--verbose', count=True, help="Control log level. -vv for debug level.")
|
||||
def cli(verbose: int = 0) -> None:
|
||||
|
|
@ -241,7 +241,8 @@ def test(
|
|||
pep440_version = version.to_pep440(new_version)
|
||||
|
||||
click.echo(f"New Version: {new_version}")
|
||||
click.echo(f"PEP440 : {pep440_version}")
|
||||
if new_version != pep440_version:
|
||||
click.echo(f"PEP440 : {pep440_version}")
|
||||
|
||||
|
||||
def _grep_text(pattern: patterns.Pattern, text: str, color: bool) -> typ.Iterable[str]:
|
||||
|
|
@ -292,7 +293,8 @@ def _grep(
|
|||
|
||||
match_strs = list(_grep_text(pattern, text, color))
|
||||
if len(match_strs) > 0:
|
||||
print(file_io.name)
|
||||
if len(file_ios) > 1:
|
||||
print(file_io.name)
|
||||
for match_str in match_strs:
|
||||
print(match_str)
|
||||
print()
|
||||
|
|
@ -365,7 +367,7 @@ def show(verbose: int = 0, fetch: bool = True) -> None:
|
|||
_, cfg = config.init(project_path=".")
|
||||
|
||||
if cfg is None:
|
||||
logger.error("Could not parse configuration. Perhaps try 'calver init'.")
|
||||
logger.error("Could not parse configuration. Perhaps try 'bumpver init'.")
|
||||
sys.exit(1)
|
||||
|
||||
cfg = _update_cfg_from_vcs(cfg, fetch)
|
||||
|
|
@ -418,6 +420,9 @@ def _print_diff(cfg: config.Config, new_version: str) -> None:
|
|||
try:
|
||||
diff = get_diff(cfg, new_version)
|
||||
_print_diff_str(diff)
|
||||
except OSError as err:
|
||||
logger.error(str(err))
|
||||
sys.exit(1)
|
||||
except rewrite.NoPatternMatch as ex:
|
||||
logger.error(str(ex))
|
||||
sys.exit(1)
|
||||
|
|
@ -482,7 +487,7 @@ def incr_dispatch(
|
|||
return new_version
|
||||
|
||||
|
||||
def _bump(
|
||||
def _update(
|
||||
cfg : config.Config,
|
||||
new_version : str,
|
||||
commit_message: str,
|
||||
|
|
@ -516,14 +521,14 @@ def _bump(
|
|||
vcs.commit(cfg, vcs_api, filepaths, new_version, commit_message)
|
||||
|
||||
|
||||
def _try_bump(
|
||||
def _try_update(
|
||||
cfg : config.Config,
|
||||
new_version : str,
|
||||
commit_message: str,
|
||||
allow_dirty : bool = False,
|
||||
) -> None:
|
||||
try:
|
||||
_bump(cfg, new_version, commit_message, allow_dirty)
|
||||
_update(cfg, new_version, commit_message, allow_dirty)
|
||||
except sp.CalledProcessError as ex:
|
||||
logger.error(f"Error running subcommand: {ex.cmd}")
|
||||
if ex.stdout:
|
||||
|
|
@ -650,7 +655,7 @@ def _update_cfg_from_vcs(cfg: config.Config, fetch: bool) -> config.Config:
|
|||
metavar="<ISODATE>",
|
||||
help=f"Set explicit date in format YYYY-0M-0D (e.g. {_current_date}).",
|
||||
)
|
||||
def bump(
|
||||
def update(
|
||||
verbose : int = 0,
|
||||
dry : bool = False,
|
||||
allow_dirty: bool = False,
|
||||
|
|
@ -663,7 +668,7 @@ def bump(
|
|||
pin_date : bool = False,
|
||||
date : typ.Optional[str] = None,
|
||||
) -> None:
|
||||
"""Increment the current version string and update project files."""
|
||||
"""Update project files with the incremented version string."""
|
||||
verbose = max(_VERBOSE, verbose)
|
||||
_configure_logging(verbose)
|
||||
_validate_release_tag(tag)
|
||||
|
|
@ -672,7 +677,7 @@ def bump(
|
|||
_, cfg = config.init(project_path=".")
|
||||
|
||||
if cfg is None:
|
||||
logger.error("Could not parse configuration. Perhaps try 'pycalver init'.")
|
||||
logger.error("Could not parse configuration. Perhaps try 'bumpver init'.")
|
||||
sys.exit(1)
|
||||
|
||||
cfg = _update_cfg_from_vcs(cfg, fetch)
|
||||
|
|
@ -691,7 +696,7 @@ def bump(
|
|||
)
|
||||
|
||||
if new_version is None:
|
||||
_log_no_change('bump', cfg.version_pattern, old_version)
|
||||
_log_no_change('update', cfg.version_pattern, old_version)
|
||||
sys.exit(1)
|
||||
|
||||
logger.info(f"Old Version: {old_version}")
|
||||
|
|
@ -711,7 +716,7 @@ def bump(
|
|||
}
|
||||
commit_message = cfg.commit_message.format(**commit_message_kwargs)
|
||||
|
||||
_try_bump(cfg, new_version, commit_message, allow_dirty)
|
||||
_try_update(cfg, new_version, commit_message, allow_dirty)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
#
|
||||
# Copyright (c) 2018-2020 Manuel Barkhau (mbarkhau@gmail.com) - MIT License
|
||||
# SPDX-License-Identifier: MIT
|
||||
"""Parse setup.cfg or pycalver.cfg files."""
|
||||
"""Parse bumpver.toml, setup.cfg or pyproject.toml files."""
|
||||
|
||||
import re
|
||||
import glob
|
||||
|
|
@ -22,7 +22,7 @@ from . import v1patterns
|
|||
from . import v2patterns
|
||||
from .patterns import Pattern
|
||||
|
||||
logger = logging.getLogger("pycalver2.config")
|
||||
logger = logging.getLogger("bumpver.config")
|
||||
|
||||
RawPatterns = typ.List[str]
|
||||
RawPatternsByFile = typ.Dict[str, RawPatterns]
|
||||
|
|
@ -32,7 +32,7 @@ PatternsByFile = typ.Dict[str, typ.List[Pattern]]
|
|||
FilePatternsItem = typ.Tuple[str, typ.List[Pattern]]
|
||||
|
||||
|
||||
SUPPORTED_CONFIGS = ["setup.cfg", "pyproject.toml", "pycalver.toml", "calver.toml"]
|
||||
SUPPORTED_CONFIGS = ["setup.cfg", "pyproject.toml", "pycalver.toml", "bumpver.toml"]
|
||||
|
||||
DEFAULT_COMMIT_MESSAGE = "bump version to {new_version}"
|
||||
|
||||
|
|
@ -51,8 +51,8 @@ def _parse_config_and_format(path: pl.Path) -> typ.Tuple[pl.Path, str, str]:
|
|||
if (path / "pycalver.toml").exists():
|
||||
config_filepath = path / "pycalver.toml"
|
||||
config_format = 'toml'
|
||||
elif (path / "calver.toml").exists():
|
||||
config_filepath = path / "calver.toml"
|
||||
elif (path / "bumpver.toml").exists():
|
||||
config_filepath = path / "bumpver.toml"
|
||||
config_format = 'toml'
|
||||
elif (path / "pyproject.toml").exists():
|
||||
config_filepath = path / "pyproject.toml"
|
||||
|
|
@ -61,8 +61,8 @@ def _parse_config_and_format(path: pl.Path) -> typ.Tuple[pl.Path, str, str]:
|
|||
config_filepath = path / "setup.cfg"
|
||||
config_format = 'cfg'
|
||||
else:
|
||||
# fallback to creating a new calver.toml
|
||||
config_filepath = path / "calver.toml"
|
||||
# fallback to creating a new bumpver.toml
|
||||
config_filepath = path / "bumpver.toml"
|
||||
config_format = 'toml'
|
||||
|
||||
if config_filepath.is_absolute():
|
||||
|
|
@ -150,8 +150,8 @@ def _parse_cfg_file_patterns(
|
|||
|
||||
if cfg_parser.has_section("pycalver:file_patterns"):
|
||||
file_pattern_items = cfg_parser.items("pycalver:file_patterns")
|
||||
elif cfg_parser.has_section("calver:file_patterns"):
|
||||
file_pattern_items = cfg_parser.items("calver:file_patterns")
|
||||
elif cfg_parser.has_section("bumpver:file_patterns"):
|
||||
file_pattern_items = cfg_parser.items("bumpver:file_patterns")
|
||||
else:
|
||||
return
|
||||
|
||||
|
|
@ -191,10 +191,10 @@ def _parse_cfg(cfg_buffer: typ.IO[str]) -> RawConfig:
|
|||
raw_cfg: RawConfig
|
||||
if cfg_parser.has_section("pycalver"):
|
||||
raw_cfg = dict(cfg_parser.items("pycalver"))
|
||||
elif cfg_parser.has_section("calver"):
|
||||
raw_cfg = dict(cfg_parser.items("calver"))
|
||||
elif cfg_parser.has_section("bumpver"):
|
||||
raw_cfg = dict(cfg_parser.items("bumpver"))
|
||||
else:
|
||||
raise ValueError("Missing [calver] section.")
|
||||
raise ValueError("Missing [bumpver] section.")
|
||||
|
||||
for option, default_val in BOOL_OPTIONS.items():
|
||||
val: OptionVal = raw_cfg.get(option, default_val)
|
||||
|
|
@ -213,10 +213,10 @@ def _parse_toml(cfg_buffer: typ.IO[str]) -> RawConfig:
|
|||
raw_full_cfg: typ.Any = toml.load(cfg_buffer)
|
||||
raw_cfg : RawConfig
|
||||
|
||||
if 'pycalver' in raw_full_cfg:
|
||||
if 'bumpver' in raw_full_cfg:
|
||||
raw_cfg = raw_full_cfg['bumpver']
|
||||
elif 'pycalver' in raw_full_cfg:
|
||||
raw_cfg = raw_full_cfg['pycalver']
|
||||
elif 'calver' in raw_full_cfg:
|
||||
raw_cfg = raw_full_cfg['calver']
|
||||
else:
|
||||
raw_cfg = {}
|
||||
|
||||
|
|
@ -297,10 +297,18 @@ def _validate_version_with_pattern(
|
|||
is_new_pattern : bool,
|
||||
) -> None:
|
||||
"""Provoke ValueError if version_pattern and current_version are not compatible."""
|
||||
if is_new_pattern:
|
||||
v2version.parse_version_info(current_version, version_pattern)
|
||||
else:
|
||||
v1version.parse_version_info(current_version, version_pattern)
|
||||
try:
|
||||
if is_new_pattern:
|
||||
v2version.parse_version_info(current_version, version_pattern)
|
||||
else:
|
||||
v1version.parse_version_info(current_version, version_pattern)
|
||||
except version.PatternError:
|
||||
errmsg = (
|
||||
"Invalid configuration. "
|
||||
f"current_version='{current_version}' is invalid for "
|
||||
f"version_pattern='{version_pattern}'"
|
||||
)
|
||||
raise ValueError(errmsg)
|
||||
|
||||
if is_new_pattern:
|
||||
invalid_chars = re.search(r"([\s]+)", version_pattern)
|
||||
|
|
@ -328,6 +336,7 @@ def _parse_config(raw_cfg: RawConfig) -> Config:
|
|||
version_pattern = raw_cfg['version_pattern'] = version_pattern.strip("'\" ")
|
||||
|
||||
is_new_pattern = "{" not in version_pattern and "}" not in version_pattern
|
||||
|
||||
_validate_version_with_pattern(current_version, version_pattern, is_new_pattern)
|
||||
|
||||
pep440_version = version.to_pep440(current_version)
|
||||
|
|
@ -365,19 +374,19 @@ def _parse_config(raw_cfg: RawConfig) -> Config:
|
|||
|
||||
|
||||
def _parse_current_version_default_pattern(raw_cfg: RawConfig, raw_cfg_text: str) -> str:
|
||||
is_pycalver_section = False
|
||||
is_config_section = False
|
||||
for line in raw_cfg_text.splitlines():
|
||||
if is_pycalver_section and line.startswith("current_version"):
|
||||
if is_config_section and line.startswith("current_version"):
|
||||
current_version: str = raw_cfg['current_version']
|
||||
version_pattern: str = raw_cfg['version_pattern']
|
||||
return line.replace(current_version, version_pattern)
|
||||
|
||||
if line.strip() == "[pycalver]":
|
||||
is_pycalver_section = True
|
||||
elif line.strip() == "[calver]":
|
||||
is_pycalver_section = True
|
||||
is_config_section = True
|
||||
elif line.strip() == "[bumpver]":
|
||||
is_config_section = True
|
||||
elif line and line[0] == "[" and line[-1] == "]":
|
||||
is_pycalver_section = False
|
||||
is_config_section = False
|
||||
|
||||
raise ValueError("Could not parse 'current_version'")
|
||||
|
||||
|
|
@ -449,15 +458,15 @@ def init(
|
|||
|
||||
|
||||
DEFAULT_CONFIGPARSER_BASE_TMPL = """
|
||||
[calver]
|
||||
[bumpver]
|
||||
current_version = "{initial_version}"
|
||||
version_pattern = "vYYYY.BUILD[-TAG]"
|
||||
version_pattern = "YYYY.BUILD[-TAG]"
|
||||
commit_message = "bump version {{old_version}} -> {{new_version}}"
|
||||
commit = True
|
||||
tag = True
|
||||
push = True
|
||||
|
||||
[calver:file_patterns]
|
||||
[bumpver:file_patterns]
|
||||
""".lstrip()
|
||||
|
||||
|
||||
|
|
@ -489,15 +498,15 @@ README.md =
|
|||
|
||||
|
||||
DEFAULT_TOML_BASE_TMPL = """
|
||||
[calver]
|
||||
[bumpver]
|
||||
current_version = "{initial_version}"
|
||||
version_pattern = "vYYYY.BUILD[-TAG]"
|
||||
version_pattern = "YYYY.BUILD[-TAG]"
|
||||
commit_message = "bump version {{old_version}} -> {{new_version}}"
|
||||
commit = true
|
||||
tag = true
|
||||
push = true
|
||||
|
||||
[calver.file_patterns]
|
||||
[bumpver.file_patterns]
|
||||
""".lstrip()
|
||||
|
||||
|
||||
|
|
@ -508,8 +517,8 @@ DEFAULT_TOML_PYCALVER_STR = """
|
|||
""".lstrip()
|
||||
|
||||
|
||||
DEFAULT_TOML_CALVER_STR = """
|
||||
"calver.toml" = [
|
||||
DEFAULT_TOML_BUMPVER_STR = """
|
||||
"bumpver.toml" = [
|
||||
'current_version = "{version}"',
|
||||
]
|
||||
""".lstrip()
|
||||
|
|
@ -547,7 +556,7 @@ DEFAULT_TOML_README_MD_STR = """
|
|||
|
||||
|
||||
def _initial_version() -> str:
|
||||
return dt.datetime.utcnow().strftime("v%Y.1001-alpha")
|
||||
return dt.datetime.utcnow().strftime("%Y.1001-alpha")
|
||||
|
||||
|
||||
def _initial_version_pep440() -> str:
|
||||
|
|
@ -572,7 +581,7 @@ def default_config(ctx: ProjectContext) -> str:
|
|||
default_pattern_strs_by_filename = {
|
||||
"pyproject.toml": DEFAULT_TOML_PYPROJECT_STR,
|
||||
"pycalver.toml" : DEFAULT_TOML_PYCALVER_STR,
|
||||
"calver.toml" : DEFAULT_TOML_CALVER_STR,
|
||||
"bumpver.toml" : DEFAULT_TOML_BUMPVER_STR,
|
||||
"setup.py" : DEFAULT_TOML_SETUP_PY_STR,
|
||||
"README.rst" : DEFAULT_TOML_README_RST_STR,
|
||||
"README.md" : DEFAULT_TOML_README_MD_STR,
|
||||
|
|
@ -592,7 +601,7 @@ def default_config(ctx: ProjectContext) -> str:
|
|||
if ctx.config_format == 'cfg':
|
||||
cfg_str += DEFAULT_CONFIGPARSER_SETUP_CFG_STR
|
||||
if ctx.config_format == 'toml':
|
||||
cfg_str += DEFAULT_TOML_CALVER_STR
|
||||
cfg_str += DEFAULT_TOML_BUMPVER_STR
|
||||
|
||||
cfg_str += "\n"
|
||||
|
||||
|
|
@ -9,7 +9,7 @@ import textwrap
|
|||
|
||||
from . import pysix
|
||||
|
||||
logger = logging.getLogger("pycalver2.regexfmt")
|
||||
logger = logging.getLogger("bumpver.regexfmt")
|
||||
|
||||
|
||||
def format_regex(regex: str) -> str:
|
||||
|
|
@ -38,7 +38,7 @@ from . import utils
|
|||
from .patterns import RE_PATTERN_ESCAPES
|
||||
from .patterns import Pattern
|
||||
|
||||
logger = logging.getLogger("pycalver2.v1patterns")
|
||||
logger = logging.getLogger("bumpver.v1patterns")
|
||||
|
||||
# https://regex101.com/r/fnj60p/10
|
||||
PYCALVER_PATTERN = r"""
|
||||
|
|
@ -17,7 +17,7 @@ from . import regexfmt
|
|||
from . import v1version
|
||||
from .patterns import Pattern
|
||||
|
||||
logger = logging.getLogger("pycalver2.v1rewrite")
|
||||
logger = logging.getLogger("bumpver.v1rewrite")
|
||||
|
||||
|
||||
def rewrite_lines(
|
||||
|
|
@ -14,7 +14,7 @@ import lexid
|
|||
from . import version
|
||||
from . import v1patterns
|
||||
|
||||
logger = logging.getLogger("pycalver2.v1version")
|
||||
logger = logging.getLogger("bumpver.v1version")
|
||||
|
||||
|
||||
CalInfo = typ.Union[version.V1CalendarInfo, version.V1VersionInfo]
|
||||
|
|
@ -37,7 +37,7 @@ from . import utils
|
|||
from .patterns import RE_PATTERN_ESCAPES
|
||||
from .patterns import Pattern
|
||||
|
||||
logger = logging.getLogger("pycalver2.v2patterns")
|
||||
logger = logging.getLogger("bumpver.v2patterns")
|
||||
|
||||
# NOTE (mb 2020-09-17): For patterns with different options '(AAA|BB|C)', the
|
||||
# patterns with more digits should be first/left of those with fewer digits:
|
||||
|
|
@ -248,6 +248,8 @@ def _convert_to_pep440(version_pattern: str) -> str:
|
|||
continue
|
||||
|
||||
substitution = PEP440_PART_SUBSTITUTIONS[part_name]
|
||||
if substitution in pep440_pattern:
|
||||
continue
|
||||
|
||||
is_numerical_part = part_name not in ('TAG', 'PYTAG')
|
||||
if is_numerical_part:
|
||||
|
|
@ -18,7 +18,7 @@ from . import v2version
|
|||
from . import v2patterns
|
||||
from .patterns import Pattern
|
||||
|
||||
logger = logging.getLogger("pycalver2.v2rewrite")
|
||||
logger = logging.getLogger("bumpver.v2rewrite")
|
||||
|
||||
|
||||
def rewrite_lines(
|
||||
|
|
@ -14,7 +14,7 @@ import lexid
|
|||
from . import version
|
||||
from . import v2patterns
|
||||
|
||||
logger = logging.getLogger("pycalver2.v2version")
|
||||
logger = logging.getLogger("bumpver.v2version")
|
||||
|
||||
|
||||
CalInfo = typ.Union[version.V2CalendarInfo, version.V2VersionInfo]
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
# Copyright (c) 2018-2020 Manuel Barkhau (mbarkhau@gmail.com) - MIT License
|
||||
# SPDX-License-Identifier: MIT
|
||||
#
|
||||
# pycalver2/vcs.py (this file) is based on code from the
|
||||
# bumpver/vcs.py (this file) is based on code from the
|
||||
# bumpversion project: https://github.com/peritus/bumpversion
|
||||
# Copyright (c) 2013-2014 Filip Noetzel - MIT License
|
||||
|
||||
|
|
@ -25,7 +25,7 @@ import subprocess as sp
|
|||
|
||||
from . import config
|
||||
|
||||
logger = logging.getLogger("pycalver2.vcs")
|
||||
logger = logging.getLogger("bumpver.vcs")
|
||||
|
||||
|
||||
VCS_SUBCOMMANDS_BY_NAME = {
|
||||
Loading…
Add table
Add a link
Reference in a new issue