Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

layout: make original toml content optional #3008

Merged
merged 3 commits into from
Oct 1, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ Create a new virtual environment if one doesn't already exist.
Defaults to `true`.

!!!note:
When setting this configuration to `false`, the Python environment used must have `pip`
When setting this configuration to `false`, the Python environment used must have `pip`
installed and available.

### `virtualenvs.in-project`: boolean
Expand Down
2 changes: 1 addition & 1 deletion poetry/console/commands/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def handle(self):
dev_dependencies=dev_requirements,
)

content = layout_.generate_poetry_content(pyproject)
content = layout_.generate_poetry_content(original=pyproject)
if self.io.is_interactive():
self.line("<info>Generated file</info>")
self.line("")
Expand Down
9 changes: 6 additions & 3 deletions poetry/layouts/layout.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from typing import TYPE_CHECKING
from typing import Optional

from tomlkit import dumps
from tomlkit import loads
Expand Down Expand Up @@ -86,7 +87,9 @@ def create(self, path, with_tests=True):

self._write_poetry(path)

def generate_poetry_content(self, original_toml): # type: ("PyProjectTOML") -> str
def generate_poetry_content(
self, original=None
): # type: (Optional["PyProjectTOML"]) -> str
template = POETRY_DEFAULT
if self._license:
template = POETRY_WITH_LICENSE
Expand Down Expand Up @@ -121,8 +124,8 @@ def generate_poetry_content(self, original_toml): # type: ("PyProjectTOML") ->

content = dumps(content)

if original_toml.file.exists():
content = dumps(original_toml.data) + "\n" + content
if original and original.file.exists():
content = dumps(original.data) + "\n" + content

return content

Expand Down