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

Fix: Misconfiguration in ask dependency interactive #7569

Merged
merged 5 commits into from
Mar 4, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 7 additions & 2 deletions src/poetry/console/commands/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,11 @@ def _determine_requirements(
)
question.set_validator(self._validate_package)

follow_up_question = self.create_question(
"\nAdd a package (leave blank to skip):"
)
follow_up_question.set_validator(self._validate_package)

package = self.ask(question)
while package:
constraint = self._parse_requirements([package])[0]
Expand All @@ -303,7 +308,7 @@ def _determine_requirements(
):
self.line(f"Adding <info>{package}</info>")
result.append(constraint)
package = self.ask("\nAdd a package (leave blank to skip):")
package = self.ask(follow_up_question)
continue

canonicalized_name = canonicalize_name(constraint["name"])
Expand Down Expand Up @@ -371,7 +376,7 @@ def _determine_requirements(
result.append(constraint)

if self.io.is_interactive():
package = self.ask("\nAdd a package (leave blank to skip):")
package = self.ask(follow_up_question)

return result

Expand Down
2 changes: 1 addition & 1 deletion src/poetry/utils/dependency_specification.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def _parse_dependency_specification_simple(
require: DependencySpec = {}

if " " in pair:
name, version = pair.split(" ", 2)
name, version = pair.split(" ", 1)
extras_m = re.search(r"\[([\w\d,-_]+)\]$", name)
if extras_m:
extras = [e.strip() for e in extras_m.group(1).split(",")]
Expand Down
8 changes: 2 additions & 6 deletions tests/console/commands/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -595,9 +595,6 @@ def test_interactive_with_file_dependency(
def test_interactive_with_wrong_dependency_inputs(
tester: CommandTester, repo: TestRepository
):
repo.add_package(get_package("pendulum", "2.0.0"))
repo.add_package(get_package("pytest", "3.6.0"))

inputs = [
"my-package", # Package name
"1.2.3", # Version
Expand All @@ -606,10 +603,8 @@ def test_interactive_with_wrong_dependency_inputs(
"MIT", # License
"^3.8", # Python
"", # Interactive packages
"foo 1.19.2",
PabloEmidio marked this conversation as resolved.
Show resolved Hide resolved
"pendulum 2.0.0 foo", # Package name and constraint (invalid)
"pendulum 2.0.0", # Package name and constraint (invalid)
"pendulum 2.0.0", # Package name and constraint (invalid)
"pendulum 2.0.0", # Package name and constraint (invalid)
"pendulum@^2.0.0", # Package name and constraint (valid)
"", # End package selection
"", # Interactive dev packages
Expand All @@ -633,6 +628,7 @@ def test_interactive_with_wrong_dependency_inputs(

[tool.poetry.dependencies]
python = "^3.8"
foo = "1.19.2"
pendulum = "^2.0.0"

[tool.poetry.group.dev.dependencies]
Expand Down