Commit d75c5a53 by Arun Babu Neelicattu Committed by finswimmer

init: handle pyproject exceptions for existing file

Resolves: #3073
parent c3212bef
...@@ -13,6 +13,7 @@ from typing import Union ...@@ -13,6 +13,7 @@ from typing import Union
from cleo import option from cleo import option
from tomlkit import inline_table from tomlkit import inline_table
from poetry.core.pyproject import PyProjectException
from poetry.core.pyproject.toml import PyProjectTOML from poetry.core.pyproject.toml import PyProjectTOML
from poetry.utils._compat import OrderedDict from poetry.utils._compat import OrderedDict
from poetry.utils._compat import Path from poetry.utils._compat import Path
...@@ -378,7 +379,7 @@ The <c1>init</c1> command creates a basic <comment>pyproject.toml</> file in the ...@@ -378,7 +379,7 @@ The <c1>init</c1> command creates a basic <comment>pyproject.toml</> file in the
try: try:
cwd = self.poetry.file.parent cwd = self.poetry.file.parent
except RuntimeError: except (PyProjectException, RuntimeError):
cwd = Path.cwd() cwd = Path.cwd()
for requirement in requirements: for requirement in requirements:
......
...@@ -621,6 +621,42 @@ line-length = 88 ...@@ -621,6 +621,42 @@ line-length = 88
) )
def test_init_non_interactive_existing_pyproject_add_dependency(
tester, source_dir, init_basic_inputs, repo
):
pyproject_file = source_dir / "pyproject.toml"
existing_section = """
[tool.black]
line-length = 88
"""
pyproject_file.write_text(decode(existing_section))
repo.add_package(get_package("foo", "1.19.2"))
tester.execute(
"--author 'Your Name <you@example.com>' "
"--name 'my-package' "
"--python '^3.6' "
"--dependency foo",
interactive=False,
)
expected = """\
[tool.poetry]
name = "my-package"
version = "0.1.0"
description = ""
authors = ["Your Name <you@example.com>"]
[tool.poetry.dependencies]
python = "^3.6"
foo = "^1.19.2"
[tool.poetry.dev-dependencies]
"""
assert "{}\n{}".format(existing_section, expected) in pyproject_file.read_text()
def test_init_existing_pyproject_with_build_system_fails( def test_init_existing_pyproject_with_build_system_fails(
tester, source_dir, init_basic_inputs tester, source_dir, init_basic_inputs
): ):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment