From 70bf8e121bd49d5b13182c57f9c5e3b5f884d272 Mon Sep 17 00:00:00 2001 From: Floris Lambrechts Date: Wed, 1 Aug 2018 15:16:24 +0200 Subject: [PATCH 1/8] Expose version 'parts' to all configurable strings Currently, only 'serialize' has access to the 'part' identifiers such as {major}, {minor} and {patch}. This change exposes them also to other configurable strings, providing more flexibility in formatting: message tag_name tag_message replace To be intuitive relative to the existing 'current_version' and 'new_version' identifiers, these are named 'current_[part]' and 'new_[part]'. --- bumpversion/cli.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/bumpversion/cli.py b/bumpversion/cli.py index ac2d05d..859fd50 100644 --- a/bumpversion/cli.py +++ b/bumpversion/cli.py @@ -628,7 +628,7 @@ def _update_config_file( ) -def _commit_to_vcs(files, context, config_file, config_file_exists, vcs, args): +def _commit_to_vcs(files, context, config_file, config_file_exists, vcs, args, current_version, new_version): commit_files = [f.path for f in files] if config_file_exists: commit_files.append(config_file) @@ -652,9 +652,17 @@ def _commit_to_vcs(files, context, config_file, config_file_exists, vcs, args): if do_commit: vcs.add_path(path) - context["current_version"] = args.current_version - context["new_version"] = args.new_version + context = { + "current_version": current_version, + "new_version": new_version, + } + context.update(time_context) + context.update(prefixed_environ()) + context.update({'current_' + part: current_version[part].value for part in current_version}) + context.update({'new_' + part: new_version[part].value for part in new_version}) + commit_message = args.message.format(**context) + logger.info( "%s to %s with message '%s'", "Would commit" if not do_commit else "Committing", From 65c13ad161928f7c4c6ef66844cba6267200e32f Mon Sep 17 00:00:00 2001 From: Floris Lambrechts Date: Wed, 31 Oct 2018 15:31:48 +0100 Subject: [PATCH 2/8] Add test: use all current_* and new_* parts in commit-message and tag --- tests/test_cli.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/tests/test_cli.py b/tests/test_cli.py index e678ea1..717061c 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -778,6 +778,44 @@ def test_message_from_config_file(tmpdir, capsys, vcs): assert b'from-400.0.0-to-401.0.0' in tag_out +def test_all_parts_in_message_and_serialize_and_tag_name_from_config_file(tmpdir, capsys, vcs): + """ + Ensure that major/minor/patch *and* custom parts can be used everywhere. + + - As [part] in 'serialize'. + - As new_[part] and previous_[part] in 'message'. + - As new_[part] and previous_[part] in 'tag_name'. + + In message and tag_name, also ensure that new_version and + current_version are correct. + """ + tmpdir.chdir() + check_call([vcs, "init"]) + tmpdir.join("VERSION").write("400.1.2.101") + check_call([vcs, "add", "VERSION"]) + check_call([vcs, "commit", "-m", "initial commit"]) + + tmpdir.join(".bumpversion.cfg").write("""[bumpversion] +current_version: 400.1.2.101 +new_version: 401.2.3.102 +parse = (?P\d+)\.(?P\d+)\.(?P\d+).(?P\d+) +serialize = {major}.{minor}.{patch}.{custom} +commit: True +tag: True +message: {current_version}/{current_major}.{current_minor}.{current_patch} custom {current_custom} becomes {new_version}/{new_major}.{new_minor}.{new_patch} custom {new_custom} +tag_name: from-{current_version}-aka-{current_major}.{current_minor}.{current_patch}-custom-{current_custom}-to-{new_version}-aka-{new_major}.{new_minor}.{new_patch}-custom-{new_custom} + +[bumpversion:part:custom] """) + + main(['major', 'VERSION']) + + log = check_output([vcs, "log", "-p"]) + assert b'400.1.2.101/400.1.2 custom 101 becomes 401.2.3.102/401.2.3 custom 102' in log + + tag_out = check_output([vcs, {"git": "tag", "hg": "tags"}[vcs]]) + assert b'from-400.1.2.101-aka-400.1.2-custom-101-to-401.2.3.102-aka-401.2.3-custom-102' in tag_out + + def test_unannotated_tag(tmpdir, vcs): tmpdir.chdir() check_call([vcs, "init"]) From 0edd89311e818d42e6145459da1d5fbf8b18250f Mon Sep 17 00:00:00 2001 From: Floris Lambrechts Date: Mon, 19 Nov 2018 10:03:57 +0100 Subject: [PATCH 3/8] Also test that all 'parts' can be used in 'replace' --- tests/test_cli.py | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index 717061c..a093ae0 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -780,7 +780,7 @@ def test_message_from_config_file(tmpdir, capsys, vcs): def test_all_parts_in_message_and_serialize_and_tag_name_from_config_file(tmpdir, capsys, vcs): """ - Ensure that major/minor/patch *and* custom parts can be used everywhere. + Ensure that major/minor/patch *and* custom parts can be used everywhere. - As [part] in 'serialize'. - As new_[part] and previous_[part] in 'message'. @@ -805,7 +805,8 @@ def test_all_parts_in_message_and_serialize_and_tag_name_from_config_file(tmpdir message: {current_version}/{current_major}.{current_minor}.{current_patch} custom {current_custom} becomes {new_version}/{new_major}.{new_minor}.{new_patch} custom {new_custom} tag_name: from-{current_version}-aka-{current_major}.{current_minor}.{current_patch}-custom-{current_custom}-to-{new_version}-aka-{new_major}.{new_minor}.{new_patch}-custom-{new_custom} -[bumpversion:part:custom] """) +[bumpversion:part:custom] +""") main(['major', 'VERSION']) @@ -816,6 +817,35 @@ def test_all_parts_in_message_and_serialize_and_tag_name_from_config_file(tmpdir assert b'from-400.1.2.101-aka-400.1.2-custom-101-to-401.2.3.102-aka-401.2.3-custom-102' in tag_out +def test_all_parts_in_replace_from_config_file(tmpdir, capsys, vcs): + """ + Ensure that major/minor/patch *and* custom parts can be used in 'replace'. + """ + tmpdir.chdir() + check_call([vcs, "init"]) + tmpdir.join("VERSION").write("my version is 400.1.2.101\n") + check_call([vcs, "add", "VERSION"]) + check_call([vcs, "commit", "-m", "initial commit"]) + + tmpdir.join(".bumpversion.cfg").write("""[bumpversion] +current_version: 400.1.2.101 +new_version: 401.2.3.102 +parse = (?P\d+)\.(?P\d+)\.(?P\d+).(?P\d+) +serialize = {major}.{minor}.{patch}.{custom} +commit: True +tag: False + +[bumpversion:part:custom] + +[bumpversion:VERSION] +search = my version is {current_version} +replace = my version is {new_major}.{new_minor}.{new_patch}.{new_custom}""") + + main(['major', 'VERSION']) + log = check_output([vcs, "log", "-p"]) + assert b'+my version is 401.2.3.102' in log + + def test_unannotated_tag(tmpdir, vcs): tmpdir.chdir() check_call([vcs, "init"]) From 4d34cf46fd50ddd6509974e9bba1b68127bfd3e7 Mon Sep 17 00:00:00 2001 From: Floris Lambrechts Date: Tue, 18 Dec 2018 10:00:57 +0100 Subject: [PATCH 4/8] Cleanup warnings about escape sequences --- tests/test_cli.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index a093ae0..521804a 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -795,7 +795,7 @@ def test_all_parts_in_message_and_serialize_and_tag_name_from_config_file(tmpdir check_call([vcs, "add", "VERSION"]) check_call([vcs, "commit", "-m", "initial commit"]) - tmpdir.join(".bumpversion.cfg").write("""[bumpversion] + tmpdir.join(".bumpversion.cfg").write(r"""[bumpversion] current_version: 400.1.2.101 new_version: 401.2.3.102 parse = (?P\d+)\.(?P\d+)\.(?P\d+).(?P\d+) @@ -827,7 +827,7 @@ def test_all_parts_in_replace_from_config_file(tmpdir, capsys, vcs): check_call([vcs, "add", "VERSION"]) check_call([vcs, "commit", "-m", "initial commit"]) - tmpdir.join(".bumpversion.cfg").write("""[bumpversion] + tmpdir.join(".bumpversion.cfg").write(r"""[bumpversion] current_version: 400.1.2.101 new_version: 401.2.3.102 parse = (?P\d+)\.(?P\d+)\.(?P\d+).(?P\d+) From f7d7076ca11143cc8f66668d1ddc312a3b16054d Mon Sep 17 00:00:00 2001 From: Floris Lambrechts Date: Thu, 10 Jan 2019 22:51:05 +0100 Subject: [PATCH 5/8] Readme: mention [current|new]_[part] availability --- README.md | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index a8a7454..9017e2f 100644 --- a/README.md +++ b/README.md @@ -146,8 +146,10 @@ General configuration is grouped in a `[bumpversion]` section. This is templated using the [Python Format String Syntax](http://docs.python.org/2/library/string.html#format-string-syntax) Available in the template context are `current_version` and `new_version` - as well as all environment variables (prefixed with `$`). You can also use - the variables `now` or `utcnow` to get a current timestamp. Both accept + as well as `current_[part]` and `new_[part]` (e.g. '`current_major`' + or '`new_patch`'). + In addtion, all environment variables are exposed, prefixed with `$`. + You can also use the variables `now` or `utcnow` to get a current timestamp. Both accept datetime formatting (when used like as in `{now:%d.%m.%Y}`). Also available as a command line flag, `--tag-name` (e.g. `bump2version --message 'Jenkins Build @@ -178,8 +180,10 @@ General configuration is grouped in a `[bumpversion]` section. This is templated using the [Python Format String Syntax](http://docs.python.org/2/library/string.html#format-string-syntax) Available in the template context are `current_version` and `new_version` - as well as all environment variables (prefixed with `$`). You can also use - the variables `now` or `utcnow` to get a current timestamp. Both accept + as well as `current_[part]` and `new_[part]` (e.g. '`current_major`' + or '`new_patch`'). + In addition, all environment variables are exposed, prefixed with `$`. + You can also use the variables `now` or `utcnow` to get a current timestamp. Both accept datetime formatting (when used like as in `{now:%d.%m.%Y}`). Also available as `--message` (e.g.: `bump2version --message From e9edb3eb66333c600aec2febb7db4e0af7e2115f Mon Sep 17 00:00:00 2001 From: Floris Lambrechts Date: Thu, 10 Jan 2019 22:52:28 +0100 Subject: [PATCH 6/8] Readme typo: tag_name example shows 'message' use --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9017e2f..a7ced07 100644 --- a/README.md +++ b/README.md @@ -152,8 +152,8 @@ General configuration is grouped in a `[bumpversion]` section. You can also use the variables `now` or `utcnow` to get a current timestamp. Both accept datetime formatting (when used like as in `{now:%d.%m.%Y}`). - Also available as a command line flag, `--tag-name` (e.g. `bump2version --message 'Jenkins Build - {$BUILD_NUMBER}: {new_version}' patch`). + Also available as command-line flag `tag_name`. Example usage: + `bump2version --tag_name 'release-{new_version}' patch` #### `commit = (True | False)` _**[optional]**_
From 5c2fccfda8b8e807737eb9cfd8d2570872565912 Mon Sep 17 00:00:00 2001 From: Floris Lambrechts Date: Thu, 10 Jan 2019 22:52:45 +0100 Subject: [PATCH 7/8] Readme: minor cosmetics --- README.md | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index a7ced07..7e67ee0 100644 --- a/README.md +++ b/README.md @@ -144,7 +144,7 @@ General configuration is grouped in a `[bumpversion]` section. The name of the tag that will be created. Only valid when using `--tag` / `tag = True`. - This is templated using the [Python Format String Syntax](http://docs.python.org/2/library/string.html#format-string-syntax) + This is templated using the [Python Format String Syntax](http://docs.python.org/2/library/string.html#format-string-syntax). Available in the template context are `current_version` and `new_version` as well as `current_[part]` and `new_[part]` (e.g. '`current_major`' or '`new_patch`'). @@ -178,16 +178,16 @@ General configuration is grouped in a `[bumpversion]` section. The commit message to use when creating a commit. Only valid when using `--commit` / `commit = True`. - This is templated using the [Python Format String Syntax](http://docs.python.org/2/library/string.html#format-string-syntax) + This is templated using the [Python Format String Syntax](http://docs.python.org/2/library/string.html#format-string-syntax). Available in the template context are `current_version` and `new_version` as well as `current_[part]` and `new_[part]` (e.g. '`current_major`' or '`new_patch`'). In addition, all environment variables are exposed, prefixed with `$`. You can also use the variables `now` or `utcnow` to get a current timestamp. Both accept datetime formatting (when used like as in `{now:%d.%m.%Y}`). - - Also available as `--message` (e.g.: `bump2version --message - '[{now:%Y-%m-%d}] Jenkins Build {$BUILD_NUMBER}: {new_version}' patch`) + + Also available as command-line flag `--message`. Example usage: + `bump2version --message '[{now:%Y-%m-%d}] Jenkins Build {$BUILD_NUMBER}: {new_version}' patch`) ### Configuration file -- Part specific configuration @@ -281,7 +281,7 @@ This configuration is in the section: `[bumpversion:file:…]` Available in the template context are parsed values of the named groups specified in `parse =` as well as all environment variables (prefixed with `$`). - + Can be specified multiple times, bumpversion will try the serialization formats beginning with the first and choose the last one where all values can be represented like this:: @@ -290,8 +290,8 @@ This configuration is in the section: `[bumpversion:file:…]` {major}.{minor} {major} - Given the example above, the new version *1.9* it will be serialized as - `1.9`, but the version *2.0* will be serialized as `2`. + Given the example above, the new version `1.9` will be serialized as + `1.9`, but the version `2.0` will be serialized as `2`. Also available as `--serialize`. Multiple values on the command line are given like `--serialize {major}.{minor} --serialize {major}` @@ -301,7 +301,7 @@ This configuration is in the section: `[bumpversion:file:…]` Template string how to search for the string to be replaced in the file. Useful if the remotest possibility exists that the current version number - might be multiple times in the file and you mean to only bump one of the + might be present multiple times in the file and you mean to only bump one of the occurences. Can be multiple lines, templated using [Python Format String Syntax](http://docs.python.org/2/library/string.html#format-string-syntax) #### `replace =` From 535da18e59bff8db5d6c6d6b18bc6472926b9aac Mon Sep 17 00:00:00 2001 From: Christian Verkerk Date: Sat, 24 Aug 2019 18:31:46 -0700 Subject: [PATCH 8/8] fix rebase --- Makefile | 3 +++ bumpversion/cli.py | 6 +++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index ec555a6..7e411f4 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,9 @@ test: docker-compose build test docker-compose run test +local_test: + PYTHONPATH=. py.test tests/ + lint: pip install pylint pylint bumpversion diff --git a/bumpversion/cli.py b/bumpversion/cli.py index 859fd50..5a7d531 100644 --- a/bumpversion/cli.py +++ b/bumpversion/cli.py @@ -115,7 +115,7 @@ def main(original_args=None): # commit and tag if vcs: - context = _commit_to_vcs(files, context, config_file, config_file_exists, vcs, args) + context = _commit_to_vcs(files, context, config_file, config_file_exists, vcs, args, current_version, new_version) _tag_in_vcs(vcs, context, args) @@ -653,8 +653,8 @@ def _commit_to_vcs(files, context, config_file, config_file_exists, vcs, args, c vcs.add_path(path) context = { - "current_version": current_version, - "new_version": new_version, + "current_version": args.current_version, + "new_version": args.new_version, } context.update(time_context) context.update(prefixed_environ())