Skip to content

Commit c03476a

Browse files
committed
Fix encoding when reading text.
Fixes #68
1 parent 0c3e7e8 commit c03476a

File tree

4 files changed

+12
-5
lines changed

4 files changed

+12
-5
lines changed

bumpversion/config/create.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Module for creating a new config file."""
2+
23
from pathlib import Path
34
from typing import Tuple
45

@@ -57,7 +58,7 @@ def get_defaults_from_dest(destination: str) -> Tuple[dict, TOMLDocument]:
5758

5859
config = DEFAULTS.copy()
5960
if Path(destination).exists():
60-
destination_config = parse(Path(destination).read_text())
61+
destination_config = parse(Path(destination).read_text(encoding="utf-8"))
6162
else:
6263
destination_config = document()
6364

bumpversion/config/files.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ def find_config_file(explicit_file: Union[str, Path, None] = None) -> Union[Path
3939
[Path(explicit_file)] if explicit_file else [Path.cwd().joinpath(path) for path in CONFIG_FILE_SEARCH_ORDER]
4040
)
4141
return next(
42-
(cfg_file for cfg_file in search_paths if cfg_file.exists() and "bumpversion]" in cfg_file.read_text()),
42+
(
43+
cfg_file
44+
for cfg_file in search_paths
45+
if cfg_file.exists() and "bumpversion]" in cfg_file.read_text(encoding="utf-8")
46+
),
4347
None,
4448
)
4549

@@ -91,7 +95,7 @@ def read_toml_file(file_path: Path) -> Dict[str, Any]:
9195
import tomlkit
9296

9397
# Load the TOML file
94-
toml_data = tomlkit.parse(file_path.read_text()).unwrap()
98+
toml_data = tomlkit.parse(file_path.read_text(encoding="utf-8")).unwrap()
9599

96100
return toml_data.get("tool", {}).get("bumpversion", {})
97101

bumpversion/config/files_legacy.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""This module handles the legacy config file format."""
2+
23
from __future__ import annotations
34

45
import re
@@ -102,7 +103,7 @@ def update_ini_config_file(
102103
)
103104

104105
config_path = Path(config_file)
105-
existing_config = config_path.read_text()
106+
existing_config = config_path.read_text(encoding="utf-8")
106107
if config_path.suffix == ".cfg" and cfg_current_version_regex.search(existing_config):
107108
sub_str = f"\\g<section_prefix>{new_version}"
108109
new_config = cfg_current_version_regex.sub(sub_str, existing_config)

bumpversion/files.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Methods for changing files."""
2+
23
import os.path
34
import re
45
from copy import deepcopy
@@ -331,7 +332,7 @@ def _update_toml_file(
331332
"""Update a TOML file."""
332333
import tomlkit
333334

334-
toml_data = tomlkit.parse(self.path.read_text())
335+
toml_data = tomlkit.parse(self.path.read_text(encoding="utf-8"))
335336
value_before = get_nested_value(toml_data, self.file_change.key_path)
336337

337338
if value_before is None:

0 commit comments

Comments
 (0)