Skip to content

Commit 0aea9dc

Browse files
committed
Fixed logging output and output in general.
1 parent f5d1cab commit 0aea9dc

File tree

6 files changed

+37
-15
lines changed

6 files changed

+37
-15
lines changed

bumpversion/bump.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,12 @@ def do_bump(
7070
next_version_str = config.version_config.serialize(next_version, ctx)
7171
logger.info("New version will be '%s'", next_version_str)
7272

73+
if dry_run:
74+
logger.info("Dry run active, won't touch any files.")
75+
7376
ctx = get_context(config, version, next_version)
7477

7578
configured_files = resolve_file_config(config.files, config.version_config)
76-
7779
modify_files(configured_files, version, next_version, ctx, dry_run)
7880

7981
update_config_file(config_file, config.current_version, next_version_str, dry_run)

bumpversion/cli.py

+3
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ def bump(
160160
"""Change the version."""
161161
setup_logging(verbose)
162162

163+
logger.info("Starting BumpVersion %s", __version__)
164+
163165
overrides = get_overrides(
164166
allow_dirty=allow_dirty,
165167
current_version=current_version,
@@ -175,6 +177,7 @@ def bump(
175177
message=message,
176178
commit_args=commit_args,
177179
)
180+
178181
found_config_file = find_config_file(config_file)
179182
config = get_configuration(found_config_file, **overrides)
180183

bumpversion/config.py

+14-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import itertools
55
import logging
66
import re
7+
from difflib import context_diff
78
from pathlib import Path
89
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Union
910

@@ -227,7 +228,6 @@ def read_config_file(config_file: Union[str, Path, None] = None) -> Dict[str, An
227228
if config_path.suffix == ".cfg":
228229
return read_ini_file(config_path)
229230
elif config_path.suffix == ".toml":
230-
logger.info("Reading config file %s:", config_path)
231231
return read_toml_file(config_path)
232232
return {}
233233

@@ -363,7 +363,19 @@ def update_config_file(
363363
config_path,
364364
)
365365

366-
logger.info(new_config)
366+
logger.info(
367+
"\n".join(
368+
list(
369+
context_diff(
370+
existing_config.splitlines(),
371+
new_config.splitlines(),
372+
fromfile=f"before {config_path}",
373+
tofile=f"after {config_path}",
374+
lineterm="",
375+
)
376+
)
377+
)
378+
)
367379

368380
if not dry_run:
369381
config_path.write_text(new_config)

bumpversion/files.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Methods for changing files."""
22
import glob
33
import logging
4+
from difflib import context_diff
45
from typing import List, MutableMapping
56

67
from bumpversion.config import FileConfig
@@ -92,8 +93,6 @@ def replace_version(
9293
self, current_version: Version, new_version: Version, context: MutableMapping, dry_run: bool = False
9394
) -> None:
9495
"""Replace the current version with the new version."""
95-
from difflib import unified_diff
96-
9796
with open(self.path, "rt", encoding="utf-8") as f:
9897
file_content_before = f.read()
9998
file_new_lines = f.newlines[0] if isinstance(f.newlines, tuple) else f.newlines
@@ -115,12 +114,12 @@ def replace_version(
115114
logger.info(
116115
"\n".join(
117116
list(
118-
unified_diff(
117+
context_diff(
119118
file_content_before.splitlines(),
120119
file_content_after.splitlines(),
120+
fromfile=f"before {self.path}",
121+
tofile=f"after {self.path}",
121122
lineterm="",
122-
fromfile=f"a/{self.path}",
123-
tofile=f"b/{self.path}",
124123
)
125124
)
126125
)
@@ -207,7 +206,7 @@ def _check_files_contain_version(
207206
"""Make sure files exist and contain version string."""
208207
logger.info(
209208
"Asserting files %s contain the version string...",
210-
", ".join([str(f) for f in files]),
209+
", ".join({str(f.path) for f in files}),
211210
)
212211
for f in files:
213212
f.contains_version(current_version, context)

bumpversion/logging.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,7 @@ def setup_logging(verbose: int = 0) -> None:
1919
level=VERBOSITY.get(verbose, logging.DEBUG),
2020
format="%(message)s",
2121
datefmt="[%X]",
22-
handlers=[RichHandler(rich_tracebacks=True, tracebacks_suppress=[click])],
22+
handlers=[RichHandler(rich_tracebacks=True, show_path=False, show_time=False, tracebacks_suppress=[click])],
2323
)
24+
root_logger = logging.getLogger("")
25+
root_logger.setLevel(VERBOSITY.get(verbose, logging.DEBUG))

bumpversion/scm.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def commit(cls, message: str, current_version: str, new_version: str, extra_args
4747
env["BUMPVERSION_NEW_VERSION"] = new_version
4848

4949
try:
50-
subprocess.check_output([*cls._COMMIT_COMMAND, f.name, *extra_args], env=env)
50+
subprocess.run([*cls._COMMIT_COMMAND, f.name, *extra_args], env=env, capture_output=True, check=True)
5151
except subprocess.CalledProcessError as exc:
5252
err_msg = f"Failed to run {exc.cmd}: return code {exc.returncode}, output: {exc.output}"
5353
logger.exception(err_msg)
@@ -59,7 +59,7 @@ def commit(cls, message: str, current_version: str, new_version: str, extra_args
5959
def is_usable(cls) -> bool:
6060
"""Is the VCS implementation usable."""
6161
try:
62-
result = subprocess.run(cls._TEST_USABLE_COMMAND, check=True)
62+
result = subprocess.run(cls._TEST_USABLE_COMMAND, check=True, capture_output=True)
6363
return result.returncode == 0
6464
except (FileNotFoundError, PermissionError, NotADirectoryError, subprocess.CalledProcessError):
6565
return False
@@ -172,8 +172,12 @@ def latest_tag_info(cls, tag_pattern: str) -> SCMInfo:
172172
"""Return information about the latest tag."""
173173
try:
174174
# git-describe doesn't update the git-index, so we do that
175-
subprocess.run(["git", "update-index", "--refresh"], check=True)
175+
subprocess.run(["git", "update-index", "--refresh", "-q"], capture_output=True)
176+
except subprocess.CalledProcessError as e:
177+
logger.debug("Error when running git update-index: %s", e.stderr)
178+
return SCMInfo(tool=cls)
176179

180+
try:
177181
# get info about the latest tag in git
178182
# TODO: This only works if the tag name is prefixed with `v`.
179183
# Should allow for the configured format for the tag name.
@@ -188,8 +192,8 @@ def latest_tag_info(cls, tag_pattern: str) -> SCMInfo:
188192
]
189193
result = subprocess.run(git_cmd, text=True, check=True, capture_output=True)
190194
describe_out = result.stdout.strip().split("-")
191-
except subprocess.CalledProcessError:
192-
logger.debug("Error when running git describe")
195+
except subprocess.CalledProcessError as e:
196+
logger.debug("Error when running git describe: %s", e.stderr)
193197
return SCMInfo(tool=cls)
194198

195199
info = SCMInfo()

0 commit comments

Comments
 (0)