Skip to content

Commit

Permalink
Merge branch 'encoding' into pre-commit-ci-update-config
Browse files Browse the repository at this point in the history
  • Loading branch information
coordt authored Feb 10, 2024
2 parents 491b4aa + c03476a commit 7f3d69a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
3 changes: 2 additions & 1 deletion bumpversion/config/create.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Module for creating a new config file."""

from pathlib import Path
from typing import Tuple

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

config = DEFAULTS.copy()
if Path(destination).exists():
destination_config = parse(Path(destination).read_text())
destination_config = parse(Path(destination).read_text(encoding="utf-8"))
else:
destination_config = document()

Expand Down
8 changes: 6 additions & 2 deletions bumpversion/config/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ def find_config_file(explicit_file: Union[str, Path, None] = None) -> Union[Path
[Path(explicit_file)] if explicit_file else [Path.cwd().joinpath(path) for path in CONFIG_FILE_SEARCH_ORDER]
)
return next(
(cfg_file for cfg_file in search_paths if cfg_file.exists() and "bumpversion]" in cfg_file.read_text()),
(
cfg_file
for cfg_file in search_paths
if cfg_file.exists() and "bumpversion]" in cfg_file.read_text(encoding="utf-8")
),
None,
)

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

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

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

Expand Down
3 changes: 2 additions & 1 deletion bumpversion/config/files_legacy.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""This module handles the legacy config file format."""

from __future__ import annotations

import re
Expand Down Expand Up @@ -102,7 +103,7 @@ def update_ini_config_file(
)

config_path = Path(config_file)
existing_config = config_path.read_text()
existing_config = config_path.read_text(encoding="utf-8")
if config_path.suffix == ".cfg" and cfg_current_version_regex.search(existing_config):
sub_str = f"\\g<section_prefix>{new_version}"
new_config = cfg_current_version_regex.sub(sub_str, existing_config)
Expand Down
3 changes: 2 additions & 1 deletion bumpversion/files.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Methods for changing files."""

import os.path
import re
from copy import deepcopy
Expand Down Expand Up @@ -331,7 +332,7 @@ def _update_toml_file(
"""Update a TOML file."""
import tomlkit

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

if value_before is None:
Expand Down

0 comments on commit 7f3d69a

Please sign in to comment.