diff --git a/packaging/markers.py b/packaging/markers.py index 1d61adaff..03d8cdefc 100644 --- a/packaging/markers.py +++ b/packaging/markers.py @@ -5,7 +5,6 @@ import operator import os import platform -import re import sys from typing import Any, Callable, Dict, List, Optional, Tuple, Union @@ -22,6 +21,7 @@ ) from .specifiers import InvalidSpecifier, Specifier +from .utils import canonicalize_name __all__ = [ "InvalidMarker", @@ -223,8 +223,10 @@ def _get_env(environment: Dict[str, str], name: str) -> str: def _normalize(*values: str, key: str) -> Tuple[str, ...]: # PEP 685 – Comparison of extra names for optional distribution dependencies # https://peps.python.org/pep-0685/ + # > When comparing extra names, tools MUST normalize the names being + # > compared using the semantics outlined in PEP 503 for names if key == "extra": - return tuple(re.sub(r"[-_.]+", "-", v).lower() for v in values) + return tuple(canonicalize_name(v) for v in values) # other environment markes don't have such standards return values