Skip to content

Commit

Permalink
Use TOMLFile.write for saving and remove newline
Browse files Browse the repository at this point in the history
  • Loading branch information
NimajnebEC committed Mar 24, 2023
1 parent c233715 commit 05ba928
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 9 deletions.
6 changes: 2 additions & 4 deletions src/poetry/console/commands/self/self_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,8 @@ def generate_system_pyproject(self) -> None:
for key in preserved:
content["tool"]["poetry"][key] = preserved[key] # type: ignore[index]

text = content.as_string().replace("\r\n", "\n") # remove carriage return
if text.endswith("\n\n"):
text = text[:-1] # remove extra newline if trailing newline already present
self.system_pyproject.write_text(text, encoding="utf-8")
pyproject = PyProjectTOML(self.system_pyproject)
pyproject.file.write(content)

def reset_poetry(self) -> None:
with directory(self.system_pyproject.parent):
Expand Down
1 change: 0 additions & 1 deletion src/poetry/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,6 @@ def create_pyproject_from_package(
content["extras"] = extras_section

pyproject = cast("TOMLDocument", pyproject)
pyproject.add(tomlkit.nl())

if path:
path.joinpath("pyproject.toml").write_text(
Expand Down
6 changes: 2 additions & 4 deletions tests/console/commands/self/test_system_pyproject.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def example_system_pyproject():
Dependency(plugin.name, "^1.2.3", groups=[SelfCommand.ADDITIONAL_PACKAGE_GROUP])
)
content = Factory.create_pyproject_from_package(package)
return content.as_string()[:-2] # remove trailing newlines
return content.as_string().strip("\n")


@pytest.mark.parametrize("existing_newlines", [0, 2])
Expand All @@ -37,9 +37,7 @@ def test_generate_system_pyproject_trailing_newline(
if c != "\n":
break

assert (existing_newlines < 2 and _i == 1) or (
existing_newlines > 1 and _i == existing_newlines
)
assert _i == existing_newlines


def test_generate_system_pyproject_carraige_returns(
Expand Down

0 comments on commit 05ba928

Please sign in to comment.