diff --git a/.gitignore b/.gitignore index c899f50..e910e29 100644 --- a/.gitignore +++ b/.gitignore @@ -216,4 +216,7 @@ fabric.properties .idea/httpRequests # Android studio 3.1+ serialized cache file -.idea/caches/build_file_checksums.ser \ No newline at end of file +.idea/caches/build_file_checksums.ser + +# Visual Studio Code +.vscode diff --git a/CHANGELOG.md b/CHANGELOG.md index 715f937..d2c08f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ # Changelog for https://github.com/mbarkhau/pycalver +## BumpVer 2021.1109 + + - Add `-e/--env` option to support shell script automation. + - Fix [github#151][github_i151]: invalid increment of `TAGNUM` when `TAG=final` is set. + +[github_i151]: https://gitlab.com/mbarkhau/pycalver/-/issues/15 + +Thank you to Dave Wapstra @dwapstra for your contributions. + + ## BumpVer 2020.1108 - Don't match empty patterns (possibly causing a whole file to be rewritten if braces `[]` are not escaped). diff --git a/LICENSE b/LICENSE index a7b7ab4..a3f8f80 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -MIT License Copyright (c) 2018-2020 Manuel Barkhau (mbarkhau@gmail.com) +MIT License Copyright (c) 2018-2021 Manuel Barkhau (mbarkhau@gmail.com) Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index ccb4ed9..a11ab36 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ Project/Repo: [![MIT License][img_license]][url_license] [![Supported Python Versions][img_pyversions]][url_pyversions] -[![CalVer 2020.1108][img_version]][url_version] +[![CalVer 2021.1109][img_version]][url_version] [![PyPI Releases][img_pypi]][url_pypi] [![PyPI Downloads][img_downloads]][url_downloads] @@ -56,7 +56,7 @@ Code Quality/CI: [img_downloads]: https://pepy.tech/badge/bumpver/month [url_downloads]: https://pepy.tech/project/bumpver -[img_version]: https://img.shields.io/static/v1.svg?label=CalVer&message=2020.1108&color=blue +[img_version]: https://img.shields.io/static/v1.svg?label=CalVer&message=2021.1109&color=blue [url_version]: https://pypi.org/project/bumpver/ [img_pypi]: https://img.shields.io/badge/PyPI-wheels-green.svg @@ -538,7 +538,7 @@ ERROR - No patterns matched for file 'src/mymodule/utils.py' $ bumpver --help Usage: bumpver [OPTIONS] COMMAND [ARGS]... - Automatically update CalVer version strings in plaintext files. + Automatically update version strings in plaintext files. Options: --version Show the version and exit. @@ -591,6 +591,21 @@ Options: +To help with shell script automation, you can use `bumpver show --env`. + +```shell +$ bumpver show -n --env +YEAR_Y=2020 +YEAR_G= +... +TAG=final +... + +$ eval $(bumpver show -n --env) +$ echo $TAG +final +``` + ### Part Overview @@ -749,7 +764,7 @@ The create an initial configuration for project with `bumpver init`. $ pip install bumpver ... Installing collected packages: click toml lexid bumpver -Successfully installed bumpver-2020.1108 +Successfully installed bumpver-2021.1109 $ cd myproject ~/myproject/ diff --git a/bootstrapit.sh b/bootstrapit.sh index cb645d2..f52d67d 100644 --- a/bootstrapit.sh +++ b/bootstrapit.sh @@ -13,7 +13,7 @@ PACKAGE_NAME="bumpver" GIT_REPO_NAMESPACE="mbarkhau" GIT_REPO_DOMAIN="github.com" -PACKAGE_VERSION="2020.1108" +PACKAGE_VERSION="2021.1109" DEFAULT_PYTHON_VERSION="python=3.8" SUPPORTED_PYTHON_VERSIONS="python=2.7 python=3.6 pypy2.7 pypy3.5 python=3.8" diff --git a/license.header b/license.header index cb08b33..53ee994 100644 --- a/license.header +++ b/license.header @@ -1,9 +1,9 @@ Individual files contain the following tag instead of the full license text. - This file is part of the pycalver project - https://github.com/mbarkhau/pycalver + This file is part of the bumpver project + https://github.com/mbarkhau/bumpver - Copyright (c) 2018-2020 Manuel Barkhau (mbarkhau@gmail.com) - MIT License + Copyright (c) 2018-2021 Manuel Barkhau (mbarkhau@gmail.com) - MIT License SPDX-License-Identifier: MIT This enables machine processing of license information based on the SPDX diff --git a/setup.cfg b/setup.cfg index 760585f..917b049 100644 --- a/setup.cfg +++ b/setup.cfg @@ -89,7 +89,7 @@ addopts = --doctest-modules [bumpver] -current_version = "2020.1108" +current_version = "2021.1109" version_pattern = "YYYY.BUILD[-TAG]" commit_message = "bump {old_version} -> {new_version}" commit = True diff --git a/setup.py b/setup.py index 07afaa3..4129fc3 100644 --- a/setup.py +++ b/setup.py @@ -1,5 +1,5 @@ -# This file is part of the pycalver project -# https://github.com/mbarkhau/pycalver +# This file is part of the bumpver project +# https://github.com/mbarkhau/bumpver # # Copyright (c) 2018-2020 Manuel Barkhau (mbarkhau@gmail.com) - MIT License # SPDX-License-Identifier: MIT @@ -63,7 +63,7 @@ setuptools.setup( author="Manuel Barkhau", author_email="mbarkhau@gmail.com", url="https://github.com/mbarkhau/bumpver", - version="2020.1108", + version="2021.1109", keywords="version bumpver calver semver versioning bumpversion pep440", description="Bump version numbers in project files.", long_description=long_description, diff --git a/src/bumpver/__init__.py b/src/bumpver/__init__.py index 3167a9f..21bd94d 100644 --- a/src/bumpver/__init__.py +++ b/src/bumpver/__init__.py @@ -1,8 +1,8 @@ -# This file is part of the pycalver project -# https://github.com/mbarkhau/pycalver +# This file is part of the bumpver project +# https://github.com/mbarkhau/bumpver # -# Copyright (c) 2018-2020 Manuel Barkhau (mbarkhau@gmail.com) - MIT License +# Copyright (c) 2018-2021 Manuel Barkhau (mbarkhau@gmail.com) - MIT License # SPDX-License-Identifier: MIT """BumpVer: A CLI program for versioning.""" -__version__ = "2020.1108" +__version__ = "2021.1109" diff --git a/src/bumpver/__main__.py b/src/bumpver/__main__.py index 588684c..dced799 100644 --- a/src/bumpver/__main__.py +++ b/src/bumpver/__main__.py @@ -1,8 +1,8 @@ #!/usr/bin/env python -# This file is part of the pycalver project -# https://github.com/mbarkhau/pycalver +# This file is part of the bumpver project +# https://github.com/mbarkhau/bumpver # -# Copyright (c) 2018-2020 Manuel Barkhau (mbarkhau@gmail.com) - MIT License +# Copyright (c) 2018-2021 Manuel Barkhau (mbarkhau@gmail.com) - MIT License # SPDX-License-Identifier: MIT """ __main__ module for BumpVer. diff --git a/src/bumpver/cli.py b/src/bumpver/cli.py index 66f9c20..9b0fa80 100755 --- a/src/bumpver/cli.py +++ b/src/bumpver/cli.py @@ -1,8 +1,8 @@ #!/usr/bin/env python -# This file is part of the pycalver project -# https://github.com/mbarkhau/pycalver +# This file is part of the bumpver project +# https://github.com/mbarkhau/bumpver # -# Copyright (c) 2018-2020 Manuel Barkhau (mbarkhau@gmail.com) - MIT License +# Copyright (c) 2018-2021 Manuel Barkhau (mbarkhau@gmail.com) - MIT License # SPDX-License-Identifier: MIT """cli module for BumpVer.""" import io @@ -189,6 +189,15 @@ fetch_option = click.option( ) +env_option = click.option( + "-e", + "--env", + is_flag=True, + default=False, + help="Print version state for use with shell scripts: eval $(bumpver show --env)", +) + + def version_options(function: typ.Callable) -> typ.Callable: decorators = [ click.option("--major", is_flag=True, default=False, help="Increment major component."), @@ -237,7 +246,7 @@ def version_options(function: typ.Callable) -> typ.Callable: @click.group() -@click.version_option(version="2020.1108") +@click.version_option(version="2021.1109") @click.help_option() @verbose_option def cli(verbose: int = 0) -> None: @@ -413,7 +422,8 @@ def grep( @cli.command() @verbose_option @fetch_option -def show(verbose: int = 0, fetch: bool = True) -> None: +@env_option +def show(verbose: int = 0, fetch: bool = True, env: bool = False) -> None: """Show current version of your project.""" _configure_logging(verbose=max(_VERBOSE, verbose)) @@ -424,8 +434,15 @@ def show(verbose: int = 0, fetch: bool = True) -> None: sys.exit(1) cfg = _update_cfg_from_vcs(cfg, fetch) - click.echo(f"Current Version: {cfg.current_version}") - click.echo(f"PEP440 : {cfg.pep440_version}") + if env: + version_info = v2version.parse_version_info(cfg.current_version, cfg.version_pattern) + for key, val in version_info._asdict().items(): + click.echo(f"{key.upper()}={val if val else ''}") + click.echo(f"CURRENT_VERSION={cfg.current_version}") + click.echo(f"PEP440_VERSION={cfg.pep440_version}") + else: + click.echo(f"Current Version: {cfg.current_version}") + click.echo(f"PEP440 : {cfg.pep440_version}") def _colored_diff_lines(diff: str) -> typ.Iterable[str]: diff --git a/src/bumpver/config.py b/src/bumpver/config.py index af48613..d4789c4 100644 --- a/src/bumpver/config.py +++ b/src/bumpver/config.py @@ -1,7 +1,7 @@ -# This file is part of the pycalver project -# https://gitlab.com/mbarkhau/pycalver +# This file is part of the bumpver project +# https://gitlab.com/mbarkhau/bumpver # -# Copyright (c) 2018-2020 Manuel Barkhau (mbarkhau@gmail.com) - MIT License +# Copyright (c) 2018-2021 Manuel Barkhau (mbarkhau@gmail.com) - MIT License # SPDX-License-Identifier: MIT """Parse bumpver.toml, setup.cfg or pyproject.toml files.""" diff --git a/src/bumpver/parse.py b/src/bumpver/parse.py index d45c390..9afc286 100644 --- a/src/bumpver/parse.py +++ b/src/bumpver/parse.py @@ -1,7 +1,7 @@ -# This file is part of the pycalver project -# https://github.com/mbarkhau/pycalver +# This file is part of the bumpver project +# https://github.com/mbarkhau/bumpver # -# Copyright (c) 2018-2020 Manuel Barkhau (mbarkhau@gmail.com) - MIT License +# Copyright (c) 2018-2021 Manuel Barkhau (mbarkhau@gmail.com) - MIT License # SPDX-License-Identifier: MIT """Parse PyCalVer strings from files.""" diff --git a/src/bumpver/patterns.py b/src/bumpver/patterns.py index 157d62b..1f0d49a 100644 --- a/src/bumpver/patterns.py +++ b/src/bumpver/patterns.py @@ -1,7 +1,7 @@ -# This file is part of the pycalver project -# https://github.com/mbarkhau/pycalver +# This file is part of the bumpver project +# https://github.com/mbarkhau/bumpver # -# Copyright (c) 2018-2020 Manuel Barkhau (mbarkhau@gmail.com) - MIT License +# Copyright (c) 2018-2021 Manuel Barkhau (mbarkhau@gmail.com) - MIT License # SPDX-License-Identifier: MIT import typing as typ diff --git a/src/bumpver/pysix.py b/src/bumpver/pysix.py index f11c7d8..1b2b77a 100644 --- a/src/bumpver/pysix.py +++ b/src/bumpver/pysix.py @@ -1,7 +1,7 @@ -# This file is part of the pycalver project -# https://github.com/mbarkhau/pycalver +# This file is part of the bumpver project +# https://github.com/mbarkhau/bumpver # -# Copyright (c) 2018-2020 Manuel Barkhau (mbarkhau@gmail.com) - MIT License +# Copyright (c) 2018-2021 Manuel Barkhau (mbarkhau@gmail.com) - MIT License # SPDX-License-Identifier: MIT import sys import typing as typ diff --git a/src/bumpver/regexfmt.py b/src/bumpver/regexfmt.py index 8d7a850..a6fb458 100644 --- a/src/bumpver/regexfmt.py +++ b/src/bumpver/regexfmt.py @@ -1,7 +1,7 @@ -# This file is part of the pycalver project -# https://github.com/mbarkhau/pycalver +# This file is part of the bumpver project +# https://github.com/mbarkhau/bumpver # -# Copyright (c) 2018-2020 Manuel Barkhau (mbarkhau@gmail.com) - MIT License +# Copyright (c) 2018-2021 Manuel Barkhau (mbarkhau@gmail.com) - MIT License # SPDX-License-Identifier: MIT import re import logging diff --git a/src/bumpver/rewrite.py b/src/bumpver/rewrite.py index 93a9b53..269639f 100644 --- a/src/bumpver/rewrite.py +++ b/src/bumpver/rewrite.py @@ -1,7 +1,7 @@ -# This file is part of the pycalver project -# https://github.com/mbarkhau/pycalver +# This file is part of the bumpver project +# https://github.com/mbarkhau/bumpver # -# Copyright (c) 2018-2020 Manuel Barkhau (mbarkhau@gmail.com) - MIT License +# Copyright (c) 2018-2021 Manuel Barkhau (mbarkhau@gmail.com) - MIT License # SPDX-License-Identifier: MIT import typing as typ import difflib diff --git a/src/bumpver/utils.py b/src/bumpver/utils.py index 5f7c5bc..313542d 100644 --- a/src/bumpver/utils.py +++ b/src/bumpver/utils.py @@ -1,7 +1,7 @@ -# This file is part of the pycalver project -# https://github.com/mbarkhau/pycalver +# This file is part of the bumpver project +# https://github.com/mbarkhau/bumpver # -# Copyright (c) 2018-2020 Manuel Barkhau (mbarkhau@gmail.com) - MIT License +# Copyright (c) 2018-2021 Manuel Barkhau (mbarkhau@gmail.com) - MIT License # SPDX-License-Identifier: MIT import typing as typ import functools diff --git a/src/bumpver/v1patterns.py b/src/bumpver/v1patterns.py index 265fffd..9b891dc 100644 --- a/src/bumpver/v1patterns.py +++ b/src/bumpver/v1patterns.py @@ -1,7 +1,7 @@ -# This file is part of the pycalver project -# https://github.com/mbarkhau/pycalver +# This file is part of the bumpver project +# https://github.com/mbarkhau/bumpver # -# Copyright (c) 2018-2020 Manuel Barkhau (mbarkhau@gmail.com) - MIT License +# Copyright (c) 2018-2021 Manuel Barkhau (mbarkhau@gmail.com) - MIT License # SPDX-License-Identifier: MIT """Compose Regular Expressions from Patterns. diff --git a/src/bumpver/v1rewrite.py b/src/bumpver/v1rewrite.py index bb594dd..76bcd3e 100644 --- a/src/bumpver/v1rewrite.py +++ b/src/bumpver/v1rewrite.py @@ -1,7 +1,7 @@ -# This file is part of the pycalver project -# https://github.com/mbarkhau/pycalver +# This file is part of the bumpver project +# https://github.com/mbarkhau/bumpver # -# Copyright (c) 2018-2020 Manuel Barkhau (mbarkhau@gmail.com) - MIT License +# Copyright (c) 2018-2021 Manuel Barkhau (mbarkhau@gmail.com) - MIT License # SPDX-License-Identifier: MIT """Rewrite files, updating occurences of version strings.""" diff --git a/src/bumpver/v1version.py b/src/bumpver/v1version.py index b149974..67176b5 100644 --- a/src/bumpver/v1version.py +++ b/src/bumpver/v1version.py @@ -1,7 +1,7 @@ -# This file is part of the pycalver project -# https://github.com/mbarkhau/pycalver +# This file is part of the bumpver project +# https://github.com/mbarkhau/bumpver # -# Copyright (c) 2018-2020 Manuel Barkhau (mbarkhau@gmail.com) - MIT License +# Copyright (c) 2018-2021 Manuel Barkhau (mbarkhau@gmail.com) - MIT License # SPDX-License-Identifier: MIT """Functions related to version string manipulation.""" diff --git a/src/bumpver/v2patterns.py b/src/bumpver/v2patterns.py index ccf41ee..e8857ea 100644 --- a/src/bumpver/v2patterns.py +++ b/src/bumpver/v2patterns.py @@ -1,7 +1,7 @@ -# This file is part of the pycalver project -# https://github.com/mbarkhau/pycalver +# This file is part of the bumpver project +# https://github.com/mbarkhau/bumpver # -# Copyright (c) 2018-2020 Manuel Barkhau (mbarkhau@gmail.com) - MIT License +# Copyright (c) 2018-2021 Manuel Barkhau (mbarkhau@gmail.com) - MIT License # SPDX-License-Identifier: MIT """Compose Regular Expressions from Patterns. diff --git a/src/bumpver/v2rewrite.py b/src/bumpver/v2rewrite.py index e70ea12..80604f5 100644 --- a/src/bumpver/v2rewrite.py +++ b/src/bumpver/v2rewrite.py @@ -1,7 +1,7 @@ -# This file is part of the pycalver project -# https://github.com/mbarkhau/pycalver +# This file is part of the bumpver project +# https://github.com/mbarkhau/bumpver # -# Copyright (c) 2018-2020 Manuel Barkhau (mbarkhau@gmail.com) - MIT License +# Copyright (c) 2018-2021 Manuel Barkhau (mbarkhau@gmail.com) - MIT License # SPDX-License-Identifier: MIT """Rewrite files, updating occurences of version strings.""" diff --git a/src/bumpver/v2version.py b/src/bumpver/v2version.py index 39e0e1e..85366b5 100644 --- a/src/bumpver/v2version.py +++ b/src/bumpver/v2version.py @@ -1,7 +1,7 @@ -# This file is part of the pycalver project -# https://github.com/mbarkhau/pycalver +# This file is part of the bumpver project +# https://github.com/mbarkhau/bumpver # -# Copyright (c) 2018-2020 Manuel Barkhau (mbarkhau@gmail.com) - MIT License +# Copyright (c) 2018-2021 Manuel Barkhau (mbarkhau@gmail.com) - MIT License # SPDX-License-Identifier: MIT """Functions related to version string manipulation.""" @@ -754,6 +754,11 @@ def incr( else: cur_vinfo = old_vinfo._replace(**cur_cinfo._asdict()) + has_tag_part = cur_vinfo.tag != "final" + if tag_num and not tag and not has_tag_part: + logger.error("Invalid arguments, non-final --tag= is needed to use --tag-num.") + return None + cur_vinfo = _incr_numeric( raw_pattern, old_vinfo, diff --git a/src/bumpver/vcs.py b/src/bumpver/vcs.py index 87c144d..0613d47 100644 --- a/src/bumpver/vcs.py +++ b/src/bumpver/vcs.py @@ -1,7 +1,7 @@ -# This file is part of the pycalver project -# https://github.com/mbarkhau/pycalver +# This file is part of the bumpver project +# https://github.com/mbarkhau/bumpver # -# Copyright (c) 2018-2020 Manuel Barkhau (mbarkhau@gmail.com) - MIT License +# Copyright (c) 2018-2021 Manuel Barkhau (mbarkhau@gmail.com) - MIT License # SPDX-License-Identifier: MIT # # bumpver/vcs.py (this file) is based on code from the diff --git a/src/bumpver/version.py b/src/bumpver/version.py index fae6376..5c855b6 100644 --- a/src/bumpver/version.py +++ b/src/bumpver/version.py @@ -1,7 +1,7 @@ -# This file is part of the pycalver project -# https://github.com/mbarkhau/pycalver +# This file is part of the bumpver project +# https://github.com/mbarkhau/bumpver # -# Copyright (c) 2018-2020 Manuel Barkhau (mbarkhau@gmail.com) - MIT License +# Copyright (c) 2018-2021 Manuel Barkhau (mbarkhau@gmail.com) - MIT License # SPDX-License-Identifier: MIT import typing as typ import datetime as dt diff --git a/test/test_cli.py b/test/test_cli.py index 701c002..5145772 100644 --- a/test/test_cli.py +++ b/test/test_cli.py @@ -116,6 +116,17 @@ def test_version(runner): assert match +def test_show_env(runner): + _add_project_files("README.md", "setup.cfg") + + result = runner.invoke(cli.cli, ['init', "-vv"]) + assert result.exit_code == 0 + + result = runner.invoke(cli.cli, ['show', "-e"]) + assert result.exit_code == 0 + assert "TAG=alpha" in result.output + + def test_incr_default(runner): old_version = "v201709.1004-alpha" diff --git a/test/test_rewrite.py b/test/test_rewrite.py index a306920..033abb3 100644 --- a/test/test_rewrite.py +++ b/test/test_rewrite.py @@ -227,10 +227,10 @@ def test_v1_iter_rewritten(): rewritten_datas = v1rewrite.iter_rewritten(file_patterns, new_vinfo) rfd = list(rewritten_datas)[0] expected = [ - "# This file is part of the pycalver project", - "# https://github.com/mbarkhau/pycalver", + "# This file is part of the bumpver project", + "# https://github.com/mbarkhau/bumpver", "#", - "# Copyright (c) 2018-2020 Manuel Barkhau (mbarkhau@gmail.com) - MIT License", + "# Copyright (c) 2018-2021 Manuel Barkhau (mbarkhau@gmail.com) - MIT License", "# SPDX-License-Identifier: MIT", '"""BumpVer: A CLI program for versioning."""', '', @@ -253,10 +253,10 @@ def test_v2_iter_rewritten(): rewritten_datas = v2rewrite.iter_rewritten(file_patterns, new_vinfo) rfd = list(rewritten_datas)[0] expected = [ - "# This file is part of the pycalver project", - "# https://github.com/mbarkhau/pycalver", + "# This file is part of the bumpver project", + "# https://github.com/mbarkhau/bumpver", "#", - "# Copyright (c) 2018-2020 Manuel Barkhau (mbarkhau@gmail.com) - MIT License", + "# Copyright (c) 2018-2021 Manuel Barkhau (mbarkhau@gmail.com) - MIT License", "# SPDX-License-Identifier: MIT", '"""BumpVer: A CLI program for versioning."""', '', diff --git a/test/test_version.py b/test/test_version.py index 191a534..40b3da1 100644 --- a/test/test_version.py +++ b/test/test_version.py @@ -73,6 +73,18 @@ def test_bump_random(monkeypatch): cur_version = new_version +def test_bump_tag_num(): + raw_pattern = "MAJOR.MINOR.PATCH[PYTAGNUM]" + cur_version = "0.1.1b0" + assert v2version.incr(cur_version, raw_pattern, tag_num=True) == "0.1.1b1" + + +def test_bump_tag_num_without_tag(): + raw_pattern = "MAJOR.MINOR.PATCH[PYTAGNUM]" + cur_version = "0.1.1" + assert v2version.incr(cur_version, raw_pattern, tag_num=True) is None + + def test_parse_version_info(): version_str = "v201712.0001-alpha" version_info = v1version.parse_version_info(version_str)