From 47b2e7dd3165d1f42d0844434480338374378dac Mon Sep 17 00:00:00 2001 From: Jeremy Carroll Date: Thu, 23 Aug 2018 20:02:19 -0700 Subject: [PATCH 01/21] appveyor needs strings only in the environment --- tests/test_cli.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index 7b798d3..488dc1c 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -21,10 +21,14 @@ from bumpversion import main, DESCRIPTION, WorkingDirectoryIsDirtyException, \ split_args_in_optional_and_positional + def _get_subprocess_env(): env = os.environ.copy() - env['HGENCODING'] = 'utf-8' + # In python2 cast to str from unicode (note the future import). + # In python3 does nothing. + env[str('HGENCODING')] = str('utf-8') return env + SUBPROCESS_ENV = _get_subprocess_env() call = partial(subprocess.call, env=SUBPROCESS_ENV) From 6db633030ebef961608dbfd7dcd2d36ec33c7fe2 Mon Sep 17 00:00:00 2001 From: Jeremy Carroll Date: Thu, 23 Aug 2018 07:30:30 -0700 Subject: [PATCH 02/21] Work correctly when hg is not installed. --- tests/test_cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index 488dc1c..17fb045 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -31,7 +31,7 @@ def _get_subprocess_env(): SUBPROCESS_ENV = _get_subprocess_env() -call = partial(subprocess.call, env=SUBPROCESS_ENV) +call = partial(subprocess.call, env=SUBPROCESS_ENV, shell=True) check_call = partial(subprocess.check_call, env=SUBPROCESS_ENV) check_output = partial(subprocess.check_output, env=SUBPROCESS_ENV) From ab36633debdb3caf495f52a2e5ecc68ec8f99ce7 Mon Sep 17 00:00:00 2001 From: Jeremy Carroll Date: Sun, 19 Aug 2018 09:07:48 -0700 Subject: [PATCH 03/21] More gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index ebe387d..8c7cb9c 100644 --- a/.gitignore +++ b/.gitignore @@ -105,6 +105,8 @@ venv.bak/ .spyderproject .spyproject +.idea + # Rope project settings .ropeproject @@ -129,3 +131,4 @@ Session.vim # Auto-generated tag files tags +.pytest_cache From 9f55b5dbf2ccfc6bb4af86bcde852c931bc2a173 Mon Sep 17 00:00:00 2001 From: Jeremy Carroll Date: Thu, 23 Aug 2018 20:17:16 -0700 Subject: [PATCH 04/21] Improved error handling --- tests/test_cli.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index 17fb045..41d8c89 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -160,12 +160,13 @@ def test_usage_string_fork(tmpdir, capsys): try: out = check_output('bumpversion --help', shell=True, stderr=subprocess.STDOUT).decode('utf-8') except subprocess.CalledProcessError as e: - out = e.output + out = e.output.decode('utf-8') if not 'usage: bumpversion [-h]' in out: print(out) assert 'usage: bumpversion [-h]' in out + assert False @pytest.mark.parametrize(("vcs"), [xfail_if_no_git("git"), xfail_if_no_hg("hg")]) def test_regression_help_in_workdir(tmpdir, capsys, vcs): From e3ce60f3073ecd7db4afca6cd04915091951a834 Mon Sep 17 00:00:00 2001 From: Jeremy Carroll Date: Thu, 23 Aug 2018 20:23:14 -0700 Subject: [PATCH 05/21] appveyor needs strings only in the environment --- bumpversion/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bumpversion/__init__.py b/bumpversion/__init__.py index 57972aa..7c0a07b 100644 --- a/bumpversion/__init__.py +++ b/bumpversion/__init__.py @@ -72,7 +72,7 @@ def commit(cls, message): f.write(message.encode('utf-8')) f.close() env = os.environ.copy() - env['HGENCODING'] = 'utf-8' + env[str('HGENCODING')] = str('utf-8') try: subprocess.check_output(cls._COMMIT_COMMAND + [f.name], env=env) except subprocess.CalledProcessError as exc: From ff6ff8bc471fa9fd95cdc22b7372dd9c6a5d1527 Mon Sep 17 00:00:00 2001 From: Jeremy Carroll Date: Thu, 23 Aug 2018 20:40:16 -0700 Subject: [PATCH 06/21] Mapping new lines in test_serialize_newline to os.linesep --- tests/test_cli.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index 41d8c89..a6e0855 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -907,17 +907,21 @@ def test_non_vcs_operations_if_vcs_is_not_installed(tmpdir, vcs, monkeypatch): assert '32.0.0' == tmpdir.join("VERSION").read() def test_serialize_newline(tmpdir): - tmpdir.join("filenewline").write("MAJOR=31\nMINOR=0\nPATCH=3\n") + def replace_newline(data): + return data.replace('\n', os.linesep).replace(repr('\n')[1:-1], repr(os.linesep)[1:-1]) + + tmpdir.join("filenewline").write(replace_newline("MAJOR=31\nMINOR=0\nPATCH=3\n")) tmpdir.chdir() main([ - '--current-version', 'MAJOR=31\nMINOR=0\nPATCH=3\n', - '--parse', 'MAJOR=(?P\d+)\\nMINOR=(?P\d+)\\nPATCH=(?P\d+)\\n', - '--serialize', 'MAJOR={major}\nMINOR={minor}\nPATCH={patch}\n', + '--current-version', replace_newline('MAJOR=31\nMINOR=0\nPATCH=3\n'), + '--parse', + replace_newline('MAJOR=(?P\d+)\\nMINOR=(?P\d+)\\nPATCH=(?P\d+)\\n'), + '--serialize', replace_newline('MAJOR={major}\nMINOR={minor}\nPATCH={patch}\n'), '--verbose', 'major', 'filenewline' ]) - assert 'MAJOR=32\nMINOR=0\nPATCH=0\n' == tmpdir.join("filenewline").read() + assert replace_newline('MAJOR=32\nMINOR=0\nPATCH=0\n') == tmpdir.join("filenewline").read() def test_multiple_serialize_threepart(tmpdir): tmpdir.join("fileA").write("Version: 0.9") From ed3b17bf5990cf16e2970814da53f3643f751251 Mon Sep 17 00:00:00 2001 From: Jeremy Carroll Date: Thu, 23 Aug 2018 21:05:45 -0700 Subject: [PATCH 07/21] Use text mode for io not binary --- bumpversion/__init__.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/bumpversion/__init__.py b/bumpversion/__init__.py index 7c0a07b..f0785f5 100644 --- a/bumpversion/__init__.py +++ b/bumpversion/__init__.py @@ -233,12 +233,12 @@ def should_contain_version(self, version, context): assert False, msg def contains(self, search): - with io.open(self.path, 'rb') as f: + with io.open(self.path, 'rt', encoding='utf-8') as f: search_lines = search.splitlines() lookbehind = [] for lineno, line in enumerate(f.readlines()): - lookbehind.append(line.decode('utf-8').rstrip("\n")) + lookbehind.append(line.rstrip("\n")) if len(lookbehind) > len(search_lines): lookbehind = lookbehind[1:] @@ -247,14 +247,14 @@ def contains(self, search): search_lines[-1] in lookbehind[-1] and search_lines[1:-1] == lookbehind[1:-1]): logger.info("Found '{}' in {} at line {}: {}".format( - search, self.path, lineno - (len(lookbehind) - 1), line.decode('utf-8').rstrip())) + search, self.path, lineno - (len(lookbehind) - 1), line.rstrip())) return True return False def replace(self, current_version, new_version, context, dry_run): - with io.open(self.path, 'rb') as f: - file_content_before = f.read().decode('utf-8') + with io.open(self.path, 'rt', encoding='utf-8') as f: + file_content_before = f.read() context['current_version'] = self._versionconfig.serialize(current_version, context) context['new_version'] = self._versionconfig.serialize(new_version, context) @@ -292,8 +292,8 @@ def replace(self, current_version, new_version, context, dry_run): )) if not dry_run: - with io.open(self.path, 'wb') as f: - f.write(file_content_after.encode('utf-8')) + with io.open(self.path, 'wt', encoding='utf-8') as f: + f.write(file_content_after) def __str__(self): return self.path @@ -892,8 +892,8 @@ def main(original_args=None): logger.info(new_config.getvalue()) if write_to_config_file: - with io.open(config_file, 'wb') as f: - f.write(new_config.getvalue().encode('utf-8')) + with io.open(config_file, 'wt', encoding='utf-8') as f: + f.write(new_config.getvalue()) except UnicodeEncodeError: warnings.warn( From e795fb76547e7d16f37336f5d0e4192479695a2d Mon Sep 17 00:00:00 2001 From: Jeremy Carroll Date: Thu, 23 Aug 2018 22:04:03 -0700 Subject: [PATCH 08/21] test_usage_string_fork use bytes --- tests/test_cli.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index a6e0855..5f7b51a 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -154,19 +154,20 @@ def test_usage_string(tmpdir, capsys): assert EXPECTED_USAGE in out + def test_usage_string_fork(tmpdir, capsys): tmpdir.chdir() try: - out = check_output('bumpversion --help', shell=True, stderr=subprocess.STDOUT).decode('utf-8') + out = check_output('bumpversion --help', shell=True, stderr=subprocess.STDOUT) except subprocess.CalledProcessError as e: - out = e.output.decode('utf-8') + out = e.output - if not 'usage: bumpversion [-h]' in out: + if not b'usage: bumpversion [-h]' in out: print(out) - assert 'usage: bumpversion [-h]' in out - assert False + assert b'usage: bumpversion [-h]' in out + @pytest.mark.parametrize(("vcs"), [xfail_if_no_git("git"), xfail_if_no_hg("hg")]) def test_regression_help_in_workdir(tmpdir, capsys, vcs): From e43ebbb83ee632764cabe00c012b7fc2e49e4217 Mon Sep 17 00:00:00 2001 From: Jeremy Carroll Date: Thu, 23 Aug 2018 22:04:55 -0700 Subject: [PATCH 09/21] =?UTF-8?q?Replace=20=E2=86=92=20with=20to?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bumpversion/__init__.py | 4 ++-- tests/test_cli.py | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/bumpversion/__init__.py b/bumpversion/__init__.py index f0785f5..7f5418c 100644 --- a/bumpversion/__init__.py +++ b/bumpversion/__init__.py @@ -811,11 +811,11 @@ def main(original_args=None): default=defaults.get('tag_name', 'v{new_version}')) parser3.add_argument('--tag-message', metavar='TAG_MESSAGE', dest='tag_message', - help='Tag message', default=defaults.get('tag_message', 'Bump version: {current_version} → {new_version}')) + help='Tag message', default=defaults.get('tag_message', 'Bump version: {current_version} to {new_version}')) parser3.add_argument('--message', '-m', metavar='COMMIT_MSG', help='Commit message', - default=defaults.get('message', 'Bump version: {current_version} → {new_version}')) + default=defaults.get('message', 'Bump version: {current_version} to {new_version}')) file_names = [] if 'files' in defaults: diff --git a/tests/test_cli.py b/tests/test_cli.py index 5f7b51a..06e1802 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1189,8 +1189,8 @@ def test_subjunctive_dry_run_logging(tmpdir, vcs): info|Would prepare Git commit| info|Would add changes in file 'dont_touch_me.txt' to Git| info|Would add changes in file '.bumpversion.cfg' to Git| - info|Would commit to Git with message 'Bump version: 0.8 \u2192 0.8.1'| - info|Would tag 'v0.8.1' with message 'Bump version: 0.8 \u2192 0.8.1' in Git and not signing| + info|Would commit to Git with message 'Bump version: 0.8 to 0.8.1'| + info|Would tag 'v0.8.1' with message 'Bump version: 0.8 to 0.8.1' in Git and not signing| """).strip() if vcs == "hg": @@ -1255,8 +1255,8 @@ def test_log_commitmessage_if_no_commit_tag_but_usable_vcs(tmpdir, vcs): info|Would prepare Git commit| info|Would add changes in file 'please_touch_me.txt' to Git| info|Would add changes in file '.bumpversion.cfg' to Git| - info|Would commit to Git with message 'Bump version: 0.3.3 \u2192 0.3.4'| - info|Would tag 'v0.3.4' with message 'Bump version: 0.3.3 \u2192 0.3.4' in Git and not signing| + info|Would commit to Git with message 'Bump version: 0.3.3 to 0.3.4'| + info|Would tag 'v0.3.4' with message 'Bump version: 0.3.3 to 0.3.4' in Git and not signing| """).strip() if vcs == "hg": From eb984a5bc1caf7073925a3ecfa817f3a8931a516 Mon Sep 17 00:00:00 2001 From: Jeremy Carroll Date: Thu, 23 Aug 2018 22:17:57 -0700 Subject: [PATCH 10/21] =?UTF-8?q?Replace=20=E2=86=92=20with=20to=20(more)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_cli.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index 06e1802..cf128c4 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -69,7 +69,6 @@ def _mock_calls_to_string(called_mock): ) for name, args, kwargs in called_mock.mock_calls] - EXPECTED_OPTIONS = """ [-h] [--config-file FILE] @@ -133,10 +132,10 @@ def _mock_calls_to_string(called_mock): v{new_version}) --tag-message TAG_MESSAGE Tag message (default: Bump version: {current_version} - → {new_version}) + to {new_version}) --message COMMIT_MSG, -m COMMIT_MSG Commit message (default: Bump version: - {current_version} → {new_version}) + {current_version} to {new_version}) """ % DESCRIPTION).lstrip() @@ -435,7 +434,7 @@ def test_commit_and_tag(tmpdir, vcs): assert '-47.1.1' in log assert '+47.1.2' in log - assert 'Bump version: 47.1.1 → 47.1.2' in log + assert 'Bump version: 47.1.1 to 47.1.2' in log tag_out = check_output([vcs, {"git": "tag", "hg": "tags"}[vcs]]) @@ -471,7 +470,7 @@ def test_commit_and_tag_with_configfile(tmpdir, vcs): assert '-48.1.1' in log assert '+48.1.2' in log - assert 'Bump version: 48.1.1 → 48.1.2' in log + assert 'Bump version: 48.1.1 to 48.1.2' in log tag_out = check_output([vcs, {"git": "tag", "hg": "tags"}[vcs]]) @@ -512,7 +511,7 @@ def test_commit_and_not_tag_with_configfile(tmpdir, vcs, config): assert '-48.1.1' in log assert '+48.1.2' in log - assert 'Bump version: 48.1.1 → 48.1.2' in log + assert 'Bump version: 48.1.1 to 48.1.2' in log tag_out = check_output([vcs, {"git": "tag", "hg": "tags"}[vcs]]) From cc48328bbd0b08a17ec954653a37b1e2b1cd5896 Mon Sep 17 00:00:00 2001 From: Jeremy Carroll Date: Thu, 23 Aug 2018 22:36:26 -0700 Subject: [PATCH 11/21] Revert "Mapping new lines in test_serialize_newline to os.linesep" This reverts commit ff6ff8bc471fa9fd95cdc22b7372dd9c6a5d1527. --- tests/test_cli.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index cf128c4..7c29622 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -907,21 +907,17 @@ def test_non_vcs_operations_if_vcs_is_not_installed(tmpdir, vcs, monkeypatch): assert '32.0.0' == tmpdir.join("VERSION").read() def test_serialize_newline(tmpdir): - def replace_newline(data): - return data.replace('\n', os.linesep).replace(repr('\n')[1:-1], repr(os.linesep)[1:-1]) - - tmpdir.join("filenewline").write(replace_newline("MAJOR=31\nMINOR=0\nPATCH=3\n")) + tmpdir.join("filenewline").write("MAJOR=31\nMINOR=0\nPATCH=3\n") tmpdir.chdir() main([ - '--current-version', replace_newline('MAJOR=31\nMINOR=0\nPATCH=3\n'), - '--parse', - replace_newline('MAJOR=(?P\d+)\\nMINOR=(?P\d+)\\nPATCH=(?P\d+)\\n'), - '--serialize', replace_newline('MAJOR={major}\nMINOR={minor}\nPATCH={patch}\n'), + '--current-version', 'MAJOR=31\nMINOR=0\nPATCH=3\n', + '--parse', 'MAJOR=(?P\d+)\\nMINOR=(?P\d+)\\nPATCH=(?P\d+)\\n', + '--serialize', 'MAJOR={major}\nMINOR={minor}\nPATCH={patch}\n', '--verbose', 'major', 'filenewline' ]) - assert replace_newline('MAJOR=32\nMINOR=0\nPATCH=0\n') == tmpdir.join("filenewline").read() + assert 'MAJOR=32\nMINOR=0\nPATCH=0\n' == tmpdir.join("filenewline").read() def test_multiple_serialize_threepart(tmpdir): tmpdir.join("fileA").write("Version: 0.9") From d42354b54a3922ccee1e85d1fa75e74055d88d98 Mon Sep 17 00:00:00 2001 From: Jeremy Carroll Date: Thu, 23 Aug 2018 22:44:49 -0700 Subject: [PATCH 12/21] =?UTF-8?q?Revert=20"Replace=20=E2=86=92=20with=20to?= =?UTF-8?q?=20(more)"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit eb984a5bc1caf7073925a3ecfa817f3a8931a516. --- tests/test_cli.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index 7c29622..74a58ea 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -69,6 +69,7 @@ def _mock_calls_to_string(called_mock): ) for name, args, kwargs in called_mock.mock_calls] + EXPECTED_OPTIONS = """ [-h] [--config-file FILE] @@ -132,10 +133,10 @@ def _mock_calls_to_string(called_mock): v{new_version}) --tag-message TAG_MESSAGE Tag message (default: Bump version: {current_version} - to {new_version}) + → {new_version}) --message COMMIT_MSG, -m COMMIT_MSG Commit message (default: Bump version: - {current_version} to {new_version}) + {current_version} → {new_version}) """ % DESCRIPTION).lstrip() @@ -434,7 +435,7 @@ def test_commit_and_tag(tmpdir, vcs): assert '-47.1.1' in log assert '+47.1.2' in log - assert 'Bump version: 47.1.1 to 47.1.2' in log + assert 'Bump version: 47.1.1 → 47.1.2' in log tag_out = check_output([vcs, {"git": "tag", "hg": "tags"}[vcs]]) @@ -470,7 +471,7 @@ def test_commit_and_tag_with_configfile(tmpdir, vcs): assert '-48.1.1' in log assert '+48.1.2' in log - assert 'Bump version: 48.1.1 to 48.1.2' in log + assert 'Bump version: 48.1.1 → 48.1.2' in log tag_out = check_output([vcs, {"git": "tag", "hg": "tags"}[vcs]]) @@ -511,7 +512,7 @@ def test_commit_and_not_tag_with_configfile(tmpdir, vcs, config): assert '-48.1.1' in log assert '+48.1.2' in log - assert 'Bump version: 48.1.1 to 48.1.2' in log + assert 'Bump version: 48.1.1 → 48.1.2' in log tag_out = check_output([vcs, {"git": "tag", "hg": "tags"}[vcs]]) From a1d8f0237462a099d01deafb970f5278ce7ae4eb Mon Sep 17 00:00:00 2001 From: Jeremy Carroll Date: Thu, 23 Aug 2018 22:45:03 -0700 Subject: [PATCH 13/21] =?UTF-8?q?Revert=20"Replace=20=E2=86=92=20with=20to?= =?UTF-8?q?"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit e43ebbb83ee632764cabe00c012b7fc2e49e4217. --- bumpversion/__init__.py | 4 ++-- tests/test_cli.py | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/bumpversion/__init__.py b/bumpversion/__init__.py index 7f5418c..f0785f5 100644 --- a/bumpversion/__init__.py +++ b/bumpversion/__init__.py @@ -811,11 +811,11 @@ def main(original_args=None): default=defaults.get('tag_name', 'v{new_version}')) parser3.add_argument('--tag-message', metavar='TAG_MESSAGE', dest='tag_message', - help='Tag message', default=defaults.get('tag_message', 'Bump version: {current_version} to {new_version}')) + help='Tag message', default=defaults.get('tag_message', 'Bump version: {current_version} → {new_version}')) parser3.add_argument('--message', '-m', metavar='COMMIT_MSG', help='Commit message', - default=defaults.get('message', 'Bump version: {current_version} to {new_version}')) + default=defaults.get('message', 'Bump version: {current_version} → {new_version}')) file_names = [] if 'files' in defaults: diff --git a/tests/test_cli.py b/tests/test_cli.py index 74a58ea..b3ce402 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -1185,8 +1185,8 @@ def test_subjunctive_dry_run_logging(tmpdir, vcs): info|Would prepare Git commit| info|Would add changes in file 'dont_touch_me.txt' to Git| info|Would add changes in file '.bumpversion.cfg' to Git| - info|Would commit to Git with message 'Bump version: 0.8 to 0.8.1'| - info|Would tag 'v0.8.1' with message 'Bump version: 0.8 to 0.8.1' in Git and not signing| + info|Would commit to Git with message 'Bump version: 0.8 \u2192 0.8.1'| + info|Would tag 'v0.8.1' with message 'Bump version: 0.8 \u2192 0.8.1' in Git and not signing| """).strip() if vcs == "hg": @@ -1251,8 +1251,8 @@ def test_log_commitmessage_if_no_commit_tag_but_usable_vcs(tmpdir, vcs): info|Would prepare Git commit| info|Would add changes in file 'please_touch_me.txt' to Git| info|Would add changes in file '.bumpversion.cfg' to Git| - info|Would commit to Git with message 'Bump version: 0.3.3 to 0.3.4'| - info|Would tag 'v0.3.4' with message 'Bump version: 0.3.3 to 0.3.4' in Git and not signing| + info|Would commit to Git with message 'Bump version: 0.3.3 \u2192 0.3.4'| + info|Would tag 'v0.3.4' with message 'Bump version: 0.3.3 \u2192 0.3.4' in Git and not signing| """).strip() if vcs == "hg": From fb6ef2b8102442f204b84330590515c7db990ec4 Mon Sep 17 00:00:00 2001 From: Jeremy Carroll Date: Thu, 23 Aug 2018 23:05:24 -0700 Subject: [PATCH 14/21] For Windows and py2, encode unicode before calling subprocess --- bumpversion/__init__.py | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/bumpversion/__init__.py b/bumpversion/__init__.py index f0785f5..e0e5099 100644 --- a/bumpversion/__init__.py +++ b/bumpversion/__init__.py @@ -12,24 +12,32 @@ except: from io import StringIO - import argparse +import codecs +import io import os +import platform import re import sre_constants import subprocess +import sys import warnings -import io from string import Formatter from datetime import datetime from difflib import unified_diff from tempfile import NamedTemporaryFile -import sys -import codecs - from bumpversion.version_part import VersionPart, NumericVersionPartConfiguration, ConfiguredVersionPartConfiguration + +if platform.system() == 'Windows' and sys.version_info[0] == 2: + def _command_args(args): + return [a.encode("utf-8") for a in args] +else: + def _command_args(args): + return args + + if sys.version_info[0] == 2: sys.stdout = codecs.getwriter('utf-8')(sys.stdout) @@ -64,6 +72,7 @@ def __call__(self, parser, namespace, values, option_string=None): 'utcnow': datetime.utcnow(), } + class BaseVCS(object): @classmethod @@ -153,7 +162,7 @@ def latest_tag_info(cls): @classmethod def add_path(cls, path): - subprocess.check_output(["git", "add", "--update", path]) + subprocess.check_output(_command_args(["git", "add", "--update", path])) @classmethod def tag(cls, sign, name, message): @@ -162,7 +171,7 @@ def tag(cls, sign, name, message): command += ['-s'] if message: command += ['--message', message] - subprocess.check_output(command) + subprocess.check_output(_command_args(command)) class Mercurial(BaseVCS): @@ -201,7 +210,7 @@ def tag(cls, sign, name, message): ) if message: command += ['--message', message] - subprocess.check_output(command) + subprocess.check_output(_command_args(command)) VCS = [Git, Mercurial] From 16f040c403005fb4b042dc45fab0abcd8bb0ff7e Mon Sep 17 00:00:00 2001 From: Jeremy Carroll Date: Fri, 24 Aug 2018 04:58:53 -0700 Subject: [PATCH 15/21] Addressing encoding in test_usage_string_fork --- tests/test_cli.py | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index b3ce402..da7c524 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -2,24 +2,20 @@ from __future__ import unicode_literals, print_function +import argparse +import bumpversion +import mock import os import pytest -import sys -import logging -import mock - -import argparse +import six import subprocess -from os import curdir, makedirs, chdir, environ -from os.path import join, curdir, dirname -from shlex import split as shlex_split -from textwrap import dedent -from functools import partial - -import bumpversion from bumpversion import main, DESCRIPTION, WorkingDirectoryIsDirtyException, \ split_args_in_optional_and_positional +from functools import partial +from os import environ +from shlex import split as shlex_split +from textwrap import dedent def _get_subprocess_env(): @@ -157,16 +153,17 @@ def test_usage_string(tmpdir, capsys): def test_usage_string_fork(tmpdir, capsys): tmpdir.chdir() + kwargs = {} if six.PY2 else {"encoding": "utf-8"} try: - out = check_output('bumpversion --help', shell=True, stderr=subprocess.STDOUT) + out = check_output('bumpversion --help', shell=True, stderr=subprocess.STDOUT, **kwargs) except subprocess.CalledProcessError as e: out = e.output - if not b'usage: bumpversion [-h]' in out: + if not 'usage: bumpversion [-h]' in out: print(out) - assert b'usage: bumpversion [-h]' in out + assert 'usage: bumpversion [-h]' in out @pytest.mark.parametrize(("vcs"), [xfail_if_no_git("git"), xfail_if_no_hg("hg")]) From 8af31259fec1d46e649d9a5cf1440846b00ea5a5 Mon Sep 17 00:00:00 2001 From: Jeremy Carroll Date: Fri, 24 Aug 2018 05:16:26 -0700 Subject: [PATCH 16/21] Revert "Addressing encoding in test_usage_string_fork" This reverts commit 16f040c403005fb4b042dc45fab0abcd8bb0ff7e. --- tests/test_cli.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index da7c524..b3ce402 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -2,20 +2,24 @@ from __future__ import unicode_literals, print_function -import argparse -import bumpversion -import mock import os import pytest -import six +import sys +import logging +import mock + +import argparse import subprocess +from os import curdir, makedirs, chdir, environ +from os.path import join, curdir, dirname +from shlex import split as shlex_split +from textwrap import dedent +from functools import partial + +import bumpversion from bumpversion import main, DESCRIPTION, WorkingDirectoryIsDirtyException, \ split_args_in_optional_and_positional -from functools import partial -from os import environ -from shlex import split as shlex_split -from textwrap import dedent def _get_subprocess_env(): @@ -153,17 +157,16 @@ def test_usage_string(tmpdir, capsys): def test_usage_string_fork(tmpdir, capsys): tmpdir.chdir() - kwargs = {} if six.PY2 else {"encoding": "utf-8"} try: - out = check_output('bumpversion --help', shell=True, stderr=subprocess.STDOUT, **kwargs) + out = check_output('bumpversion --help', shell=True, stderr=subprocess.STDOUT) except subprocess.CalledProcessError as e: out = e.output - if not 'usage: bumpversion [-h]' in out: + if not b'usage: bumpversion [-h]' in out: print(out) - assert 'usage: bumpversion [-h]' in out + assert b'usage: bumpversion [-h]' in out @pytest.mark.parametrize(("vcs"), [xfail_if_no_git("git"), xfail_if_no_hg("hg")]) From 3f781ba63b084db92318ef069ad8f17198f95764 Mon Sep 17 00:00:00 2001 From: Jeremy Carroll Date: Fri, 24 Aug 2018 05:24:54 -0700 Subject: [PATCH 17/21] xfailing problem case on WIndows PY3 --- tests/test_cli.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index b3ce402..4938231 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -2,21 +2,20 @@ from __future__ import unicode_literals, print_function +import argparse +import bumpversion +import mock import os +import platform import pytest -import sys -import logging -import mock -import argparse +import six import subprocess -from os import curdir, makedirs, chdir, environ -from os.path import join, curdir, dirname +from os import environ from shlex import split as shlex_split from textwrap import dedent from functools import partial -import bumpversion from bumpversion import main, DESCRIPTION, WorkingDirectoryIsDirtyException, \ split_args_in_optional_and_positional @@ -154,7 +153,8 @@ def test_usage_string(tmpdir, capsys): assert EXPECTED_USAGE in out - +@pytest.mark.xfail(platform.system() == "Windows" and six.PY3, + reason="Windows encoding problems") def test_usage_string_fork(tmpdir, capsys): tmpdir.chdir() From 8dbaf48a99ca9a12c7ad1f97daead6b2f5059d29 Mon Sep 17 00:00:00 2001 From: Jeremy Carroll Date: Sat, 25 Aug 2018 20:10:59 -0700 Subject: [PATCH 18/21] Different approach to the encoding issue in the help --- tests/test_cli.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index 4938231..a0e8bb0 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -153,10 +153,15 @@ def test_usage_string(tmpdir, capsys): assert EXPECTED_USAGE in out -@pytest.mark.xfail(platform.system() == "Windows" and six.PY3, - reason="Windows encoding problems") + def test_usage_string_fork(tmpdir, capsys): tmpdir.chdir() + + if platform.system() == "Windows" and six.PY3: + # There are encoding problems on Windows with the encoding of → + tmpdir.join(".bumpversion.cfg").write("""[bumpversion] + message: Bump version: {current_version} to {new_version} + tag_message: 'Bump version: {current_version} → {new_version}""") try: out = check_output('bumpversion --help', shell=True, stderr=subprocess.STDOUT) From b6fe568a20fca5e259cd63b1a3d3db8e6a43f3e9 Mon Sep 17 00:00:00 2001 From: Jeremy Carroll Date: Sat, 25 Aug 2018 20:56:50 -0700 Subject: [PATCH 19/21] oops missed one --- 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 a0e8bb0..d8e1049 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -156,12 +156,12 @@ def test_usage_string(tmpdir, capsys): def test_usage_string_fork(tmpdir, capsys): tmpdir.chdir() - + if platform.system() == "Windows" and six.PY3: # There are encoding problems on Windows with the encoding of → tmpdir.join(".bumpversion.cfg").write("""[bumpversion] message: Bump version: {current_version} to {new_version} - tag_message: 'Bump version: {current_version} → {new_version}""") + tag_message: 'Bump version: {current_version} to {new_version}""") try: out = check_output('bumpversion --help', shell=True, stderr=subprocess.STDOUT) From 29769c78b07e3f93dd6277a675b7d89b402a75e7 Mon Sep 17 00:00:00 2001 From: Jeremy Carroll Date: Sat, 25 Aug 2018 21:01:42 -0700 Subject: [PATCH 20/21] Moving windows/PY3 tag message from test into main code base --- bumpversion/__init__.py | 9 +++++++-- tests/test_cli.py | 6 ------ 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/bumpversion/__init__.py b/bumpversion/__init__.py index e0e5099..7c78fe0 100644 --- a/bumpversion/__init__.py +++ b/bumpversion/__init__.py @@ -819,12 +819,17 @@ def main(original_args=None): help='Tag name (only works with --tag)', default=defaults.get('tag_name', 'v{new_version}')) + if platform.system() == "Windows" and sys.version_info[0] == 3: + default_message = 'Bump version: {current_version} to {new_version}' + else: + default_message = 'Bump version: {current_version} → {new_version}' + parser3.add_argument('--tag-message', metavar='TAG_MESSAGE', dest='tag_message', - help='Tag message', default=defaults.get('tag_message', 'Bump version: {current_version} → {new_version}')) + help='Tag message', default=defaults.get('tag_message', default_message)) parser3.add_argument('--message', '-m', metavar='COMMIT_MSG', help='Commit message', - default=defaults.get('message', 'Bump version: {current_version} → {new_version}')) + default=defaults.get('message', default_message)) file_names = [] if 'files' in defaults: diff --git a/tests/test_cli.py b/tests/test_cli.py index d8e1049..66c6c6d 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -157,12 +157,6 @@ def test_usage_string(tmpdir, capsys): def test_usage_string_fork(tmpdir, capsys): tmpdir.chdir() - if platform.system() == "Windows" and six.PY3: - # There are encoding problems on Windows with the encoding of → - tmpdir.join(".bumpversion.cfg").write("""[bumpversion] - message: Bump version: {current_version} to {new_version} - tag_message: 'Bump version: {current_version} to {new_version}""") - try: out = check_output('bumpversion --help', shell=True, stderr=subprocess.STDOUT) except subprocess.CalledProcessError as e: From 8379713543556138c433d6c11d6fa707c75da76d Mon Sep 17 00:00:00 2001 From: Jeremy Carroll Date: Sat, 25 Aug 2018 21:08:56 -0700 Subject: [PATCH 21/21] Revert "Moving windows/PY3 tag message from test into main code base" This reverts commit 29769c78b07e3f93dd6277a675b7d89b402a75e7. --- bumpversion/__init__.py | 9 ++------- tests/test_cli.py | 6 ++++++ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/bumpversion/__init__.py b/bumpversion/__init__.py index 7c78fe0..e0e5099 100644 --- a/bumpversion/__init__.py +++ b/bumpversion/__init__.py @@ -819,17 +819,12 @@ def main(original_args=None): help='Tag name (only works with --tag)', default=defaults.get('tag_name', 'v{new_version}')) - if platform.system() == "Windows" and sys.version_info[0] == 3: - default_message = 'Bump version: {current_version} to {new_version}' - else: - default_message = 'Bump version: {current_version} → {new_version}' - parser3.add_argument('--tag-message', metavar='TAG_MESSAGE', dest='tag_message', - help='Tag message', default=defaults.get('tag_message', default_message)) + help='Tag message', default=defaults.get('tag_message', 'Bump version: {current_version} → {new_version}')) parser3.add_argument('--message', '-m', metavar='COMMIT_MSG', help='Commit message', - default=defaults.get('message', default_message)) + default=defaults.get('message', 'Bump version: {current_version} → {new_version}')) file_names = [] if 'files' in defaults: diff --git a/tests/test_cli.py b/tests/test_cli.py index 66c6c6d..d8e1049 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -157,6 +157,12 @@ def test_usage_string(tmpdir, capsys): def test_usage_string_fork(tmpdir, capsys): tmpdir.chdir() + if platform.system() == "Windows" and six.PY3: + # There are encoding problems on Windows with the encoding of → + tmpdir.join(".bumpversion.cfg").write("""[bumpversion] + message: Bump version: {current_version} to {new_version} + tag_message: 'Bump version: {current_version} to {new_version}""") + try: out = check_output('bumpversion --help', shell=True, stderr=subprocess.STDOUT) except subprocess.CalledProcessError as e: