diff --git a/python/pip_install/extract_wheels/lib/requirements.py b/python/pip_install/extract_wheels/lib/requirements.py index cfab339673..caf20d0f79 100644 --- a/python/pip_install/extract_wheels/lib/requirements.py +++ b/python/pip_install/extract_wheels/lib/requirements.py @@ -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. @@ -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(",")}, ) diff --git a/python/pip_install/extract_wheels/lib/requirements_test.py b/python/pip_install/extract_wheels/lib/requirements_test.py index 0ee425571f..4fe4d92e32 100644 --- a/python/pip_install/extract_wheels/lib/requirements_test.py +++ b/python/pip_install/extract_wheels/lib/requirements_test.py @@ -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"])), diff --git a/python/pip_install/extract_wheels/lib/wheel.py b/python/pip_install/extract_wheels/lib/wheel.py index 74a963f382..6dab311637 100644 --- a/python/pip_install/extract_wheels/lib/wheel.py +++ b/python/pip_install/extract_wheels/lib/wheel.py @@ -8,6 +8,7 @@ import installer import pkg_resources +from pip._vendor.packaging.utils import canonicalize_name def current_umask() -> int: @@ -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: