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: allow whitespace in list of extras for a package #2985

Merged
merged 3 commits into from
Sep 28, 2020
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
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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shoud we just use \s here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The range of \s is to wide. I don't think supporting e.g. tab characters here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I guess for this case it is fine (ish). For PEP 508, whitespace typically refers to "non-line breaking whitespace". That is narrowier than \s and but wider than . I doubt anyone is going to type in foo[a, \t b] 😏

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"]