Commit 7fac6769 by Dan Rose Committed by GitHub

handle poetry init non-interactive dependencies (#2899)

* handle poetry init non-interactive dependencies

1. in non-interactive mode, suppress "This command will guide you through..."
2. in interactive mode, respect command line --dependency if the user chooses NO for "Would you like to define your main dependencies interactively?"
parent b34cd718
......@@ -86,6 +86,7 @@ The <c1>init</c1> command creates a basic <comment>pyproject.toml</> file in the
vcs_config = GitConfig()
if self.io.is_interactive():
self.line("")
self.line(
"This command will guide you through creating your <info>pyproject.toml</> config."
......@@ -154,6 +155,7 @@ The <c1>init</c1> command creates a basic <comment>pyproject.toml</> file in the
)
python = self.ask(question)
if self.io.is_interactive():
self.line("")
requirements = {}
......@@ -175,11 +177,13 @@ The <c1>init</c1> command creates a basic <comment>pyproject.toml</> file in the
)
help_displayed = False
if self.confirm(question, True):
if self.io.is_interactive():
self.line(help_message)
help_displayed = True
requirements.update(
self._format_requirements(self._determine_requirements([]))
)
if self.io.is_interactive():
self.line("")
dev_requirements = {}
......@@ -192,12 +196,13 @@ The <c1>init</c1> command creates a basic <comment>pyproject.toml</> file in the
"Would you like to define your development dependencies interactively?"
)
if self.confirm(question, True):
if not help_displayed:
if self.io.is_interactive() and not help_displayed:
self.line(help_message)
dev_requirements.update(
self._format_requirements(self._determine_requirements([]))
)
if self.io.is_interactive():
self.line("")
layout_ = layout("standard")(
......@@ -317,6 +322,7 @@ The <c1>init</c1> command creates a basic <comment>pyproject.toml</> file in the
if package is not False:
requires.append(constraint)
if self.io.is_interactive():
package = self.ask("\nAdd a package:")
return requires
......
......@@ -81,6 +81,28 @@ def test_basic_interactive(tester, init_basic_inputs, init_basic_toml):
assert init_basic_toml in tester.io.fetch_output()
def test_noninteractive(app, mocker, poetry, repo, tmp_path):
command = app.find("init")
command._pool = poetry.pool
repo.add_package(get_package("pytest", "3.6.0"))
p = mocker.patch("poetry.utils._compat.Path.cwd")
p.return_value = tmp_path
tester = CommandTester(command)
args = "--name my-package --dependency pytest"
tester.execute(args=args, interactive=False)
expected = "Using version ^3.6.0 for pytest\n"
assert tester.io.fetch_output() == expected
assert "" == tester.io.fetch_error()
toml_content = (tmp_path / "pyproject.toml").read_text()
assert 'name = "my-package"' in toml_content
assert 'pytest = "^3.6.0"' in toml_content
def test_interactive_with_dependencies(tester, repo):
repo.add_package(get_package("django-pendulum", "0.1.6-pre4"))
repo.add_package(get_package("pendulum", "2.0.0"))
......
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