Skip to content

Commit

Permalink
init: allow whitespaces in package extras (#2985)
Browse files Browse the repository at this point in the history
This fix allows having whitespaces in the list of extras during poetry 
add and init, e.g. `databases[postgresql, sqlite]`.

Resolves: #2980
  • Loading branch information
finswimmer authored Sep 28, 2020
1 parent d4eb422 commit 5b94aa8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion poetry/console/commands/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ def _parse_requirements(
for requirement in requirements:
requirement = requirement.strip()
extras = []
extras_m = re.search(r"\[([\w\d,-_]+)\]$", requirement)
extras_m = re.search(r"\[([\w\d,-_ ]+)\]$", requirement)
if extras_m:
extras = [e.strip() for e in extras_m.group(1).split(",")]
requirement, _ = requirement.split("[")
Expand Down
9 changes: 9 additions & 0 deletions tests/console/commands/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -556,3 +556,12 @@ def test_predefined_and_interactive_dev_dependencies(tester, repo):
assert expected in output
assert 'pytest-requests = "^0.2.0"' in output
assert 'pytest = "^3.6.0"' in output


def test_add_package_with_extras_and_whitespace(tester):
result = tester._command._parse_requirements(["databases[postgresql, sqlite]"])

assert result[0]["name"] == "databases"
assert len(result[0]["extras"]) == 2
assert "postgresql" in result[0]["extras"]
assert "sqlite" in result[0]["extras"]

0 comments on commit 5b94aa8

Please sign in to comment.