From ccb17da60b05ac4ed2b8c937999e85e5b973e1f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Grzegorz=20=C5=9Aliwi=C5=84ski?= Date: Thu, 14 Nov 2019 17:33:22 +0100 Subject: [PATCH 1/2] Read and process Commands - closes #100 --- bumpversion/cli.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/bumpversion/cli.py b/bumpversion/cli.py index 5a7d5317..d822375b 100644 --- a/bumpversion/cli.py +++ b/bumpversion/cli.py @@ -2,6 +2,7 @@ from __future__ import unicode_literals import argparse +import subprocess from datetime import datetime import io import itertools @@ -113,6 +114,8 @@ def main(original_args=None): config, config_file, config_newlines, config_file_exists, args.new_version, args.dry_run, ) + _run_commands(defaults, args.dry_run,) + # commit and tag if vcs: context = _commit_to_vcs(files, context, config_file, config_file_exists, vcs, args, current_version, new_version) @@ -270,7 +273,7 @@ def _load_configuration(config_file, explicit_config, defaults): defaults.update(dict(config.items("bumpversion"))) - for listvaluename in ("serialize",): + for listvaluename in ("serialize", 'commands'): try: value = config.get("bumpversion", listvaluename) defaults[listvaluename] = list( @@ -628,6 +631,15 @@ def _update_config_file( ) +def _run_commands(defaults, dry_run): + """Run additional default commands.""" + for command in defaults.get('commands', []): + if dry_run: + print('Would run %s command', command) + else: + subprocess.check_output(command, shell=True) + + 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: From 56368c1392b4b63d7e0ffe4686938ab3ed8e975d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Grzegorz=20=C5=9Aliwi=C5=84ski?= Date: Mon, 18 Nov 2019 17:26:45 +0100 Subject: [PATCH 2/2] fixup: change print to logger.info --- bumpversion/cli.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bumpversion/cli.py b/bumpversion/cli.py index d822375b..236faf5b 100644 --- a/bumpversion/cli.py +++ b/bumpversion/cli.py @@ -635,7 +635,7 @@ def _run_commands(defaults, dry_run): """Run additional default commands.""" for command in defaults.get('commands', []): if dry_run: - print('Would run %s command', command) + logger.info('Would run %s command', command) else: subprocess.check_output(command, shell=True)