diff --git a/piptools/_compat/pip_compat.py b/piptools/_compat/pip_compat.py index 9d961e21..acee118f 100644 --- a/piptools/_compat/pip_compat.py +++ b/piptools/_compat/pip_compat.py @@ -22,7 +22,7 @@ if TYPE_CHECKING: from pip._internal.metadata.importlib import Distribution as _ImportLibDist -from ..utils import PIP_VERSION, canonicalize_ireq +from ..utils import PIP_VERSION, copy_install_requirement @dataclass(frozen=True) @@ -72,7 +72,7 @@ def parse_requirements( for parsed_req in _parse_requirements( filename, session, finder=finder, options=options, constraint=constraint ): - yield canonicalize_ireq( + yield copy_install_requirement( install_req_from_parsed_requirement(parsed_req, isolated=isolated) ) diff --git a/piptools/build.py b/piptools/build.py index 08fd0cde..a5a8f4dc 100644 --- a/piptools/build.py +++ b/piptools/build.py @@ -15,7 +15,7 @@ from pip._internal.req import InstallRequirement from pip._internal.req.constructors import parse_req_from_line -from .utils import canonicalize_ireq, install_req_from_line +from .utils import copy_install_requirement, install_req_from_line PYPROJECT_TOML = "pyproject.toml" @@ -141,7 +141,7 @@ def _prepare_requirements( replaced_package_name = req.replace(package_name, str(package_dir), 1) parts = parse_req_from_line(replaced_package_name, comes_from) - yield canonicalize_ireq( + yield copy_install_requirement( InstallRequirement( parts.requirement, comes_from, diff --git a/piptools/utils.py b/piptools/utils.py index e0c9fe20..a501fa9c 100644 --- a/piptools/utils.py +++ b/piptools/utils.py @@ -93,20 +93,8 @@ def comment(text: str) -> str: return click.style(text, fg="green") -def canonicalize_ireq(ireq: InstallRequirement) -> InstallRequirement: - """ - Return a copy of ireq with canonicalized extras strings - """ - ireq = copy_install_requirement( - ireq, extras=set(map(canonicalize_name, ireq.extras)) - ) - if ireq.req: - ireq.req.extras = set(ireq.extras) - return ireq - - def install_req_from_line(*args: Any, **kwargs: Any) -> InstallRequirement: - return canonicalize_ireq(_install_req_from_line(*args, **kwargs)) + return copy_install_requirement(_install_req_from_line(*args, **kwargs)) def make_install_requirement( @@ -531,6 +519,10 @@ def copy_install_requirement( if "req" not in kwargs: kwargs["req"] = copy.deepcopy(template.req) + kwargs["extras"] = set(map(canonicalize_name, kwargs["extras"])) + if kwargs["req"]: + kwargs["req"].extras = set(kwargs["extras"]) + ireq = InstallRequirement(**kwargs) # If the original_link was None, keep it so. Passing `link` as an