Skip to content

Commit

Permalink
append original toml during creation of poetry_content
Browse files Browse the repository at this point in the history
  • Loading branch information
finswimmer committed May 24, 2020
1 parent 4c741a8 commit 339859c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
19 changes: 6 additions & 13 deletions poetry/console/commands/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,11 @@ def handle(self):
with (Path.cwd() / "pyproject.toml").open() as toml_file:
original_toml = tomlkit.loads(toml_file.read())

try:
if original_toml["tool"]["poetry"]:
self.line(
"<error>A pyproject.toml file with a poetry section already exists.</error>"
)
return 1
except KeyError:
pass
if original_toml.get("tool", {}).get("poetry"):
self.line(
"<error>A pyproject.toml file with a poetry section already exists.</error>"
)
return 1

if original_toml.get("build-system"):
self.line(
Expand Down Expand Up @@ -205,7 +202,7 @@ def handle(self):
dev_dependencies=dev_requirements,
)

content = layout_.generate_poetry_content()
content = layout_.generate_poetry_content(original_toml)
if self.io.is_interactive():
self.line("<info>Generated file</info>")
self.line("")
Expand All @@ -220,10 +217,6 @@ def handle(self):
with (Path.cwd() / "pyproject.toml").open("w", encoding="utf-8") as f:
f.write(content)

if original_toml:
f.write("\n")
f.write(tomlkit.dumps(original_toml))

def _determine_requirements(
self, requires, allow_prereleases=False, source=None
): # type: (List[str], bool) -> List[Dict[str, str]]
Expand Down
9 changes: 7 additions & 2 deletions poetry/layouts/layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def create(self, path, with_tests=True):

self._write_poetry(path)

def generate_poetry_content(self):
def generate_poetry_content(self, original_toml):
template = POETRY_DEFAULT
if self._license:
template = POETRY_WITH_LICENSE
Expand Down Expand Up @@ -114,7 +114,12 @@ def generate_poetry_content(self):

content.add("build-system", build_system)

return dumps(content)
content = dumps(content)

if original_toml:
content += "\n" + dumps(original_toml)

return content

def _create_default(self, path, src=True):
raise NotImplementedError()
Expand Down

0 comments on commit 339859c

Please sign in to comment.