Skip to content

Use PEP 508 rules when setting deps from extras #724

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

Merged
merged 11 commits into from
Jun 21, 2022
4 changes: 3 additions & 1 deletion python/pip_install/extract_wheels/lib/requirements.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import re
from typing import Dict, Optional, Set, Tuple

from pip._vendor.packaging.utils import canonicalize_name


def parse_extras(requirements_path: str) -> Dict[str, Set[str]]:
"""Parse over the requirements.txt file to find extras requested.
Expand Down Expand Up @@ -38,7 +40,7 @@ def _parse_requirement_for_extra(
matches = extras_pattern.match(requirement)
if matches:
return (
matches.group(1),
canonicalize_name(matches.group(1)),
{extra.strip() for extra in matches.group(2).split(",")},
)

Expand Down
2 changes: 2 additions & 0 deletions python/pip_install/extract_wheels/lib/requirements_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ def test_parses_requirement_for_extra(self) -> None:
("name[foo]", ("name", frozenset(["foo"]))),
("name[ Foo123 ]", ("name", frozenset(["Foo123"]))),
(" name1[ foo ] ", ("name1", frozenset(["foo"]))),
("Name[foo]", ("name", frozenset(["foo"]))),
("name_foo[bar]", ("name-foo", frozenset(["bar"]))),
(
"name [fred,bar] @ http://foo.com ; python_version=='2.7'",
("name", frozenset(["fred", "bar"])),
Expand Down
4 changes: 3 additions & 1 deletion python/pip_install/extract_wheels/lib/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import installer
import pkg_resources
from pip._vendor.packaging.utils import canonicalize_name


def current_umask() -> int:
Expand Down Expand Up @@ -38,7 +39,8 @@ def path(self) -> str:
@property
def name(self) -> str:
# TODO Also available as installer.sources.WheelSource.distribution
return str(self.metadata['Name'])
name = str(self.metadata['Name'])
return canonicalize_name(name)

@property
def metadata(self) -> email.message.Message:
Expand Down