Skip to content

Commit

Permalink
Change write_bytes to write_text to preserve newlines
Browse files Browse the repository at this point in the history
  • Loading branch information
Nardi Lam committed Nov 20, 2023
1 parent be0ddf2 commit 3baf11b
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions poetry_dynamic_versioning/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ def _substitute_version(name: str, version: str, folders: Sequence[_FolderConfig
new_content = _substitute_version_in_text(version, original_content, config.patterns)
if original_content != new_content:
_state.projects[name].substitutions[file] = original_content
file.write_bytes(new_content.encode("utf-8"))
file.write_text(new_content, encoding="utf-8")


def _substitute_version_in_text(version: str, content: str, patterns: Sequence[_SubPattern]) -> str:
Expand Down Expand Up @@ -519,7 +519,7 @@ def _apply_version(
if not retain and not _state.cli_mode:
pyproject["tool"]["poetry-dynamic-versioning"]["enable"] = False # type: ignore

pyproject_path.write_bytes(tomlkit.dumps(pyproject).encode("utf-8"))
pyproject_path.write_text(tomlkit.dumps(pyproject), encoding="utf-8")

name = pyproject["tool"]["poetry"]["name"] # type: ignore

Expand All @@ -530,7 +530,7 @@ def _apply_version(
if not full_file.parent.exists():
full_file.parent.mkdir()
initial = textwrap.dedent(file_info["initial-content"])
full_file.write_bytes(initial.encode("utf-8"))
full_file.write_text(initial, encoding="utf-8")

_substitute_version(
name, # type: ignore
Expand Down Expand Up @@ -604,7 +604,7 @@ def _revert_version(retain: bool = False) -> None:
if file in persistent:
continue

file.write_bytes(content.encode("utf-8"))
file.write_text(content, encoding="utf-8")

# Reread pyproject.toml in case the substitutions affected it.
pyproject = tomlkit.parse(state.path.read_text(encoding="utf-8"))
Expand All @@ -614,6 +614,6 @@ def _revert_version(retain: bool = False) -> None:
if not retain and not _state.cli_mode:
pyproject["tool"]["poetry-dynamic-versioning"]["enable"] = True # type: ignore

state.path.write_bytes(tomlkit.dumps(pyproject).encode("utf-8"))
state.path.write_text(tomlkit.dumps(pyproject), encoding="utf-8")

_state.projects.clear()

0 comments on commit 3baf11b

Please sign in to comment.