Skip to content

Commit 7a1fada

Browse files
committed
Fold canonicalize-ireq-extras logic into copy_install_requirement
1 parent f13c20f commit 7a1fada

File tree

3 files changed

+9
-18
lines changed

3 files changed

+9
-18
lines changed

piptools/_compat/pip_compat.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
if TYPE_CHECKING:
2424
from pip._internal.metadata.importlib import Distribution as _ImportLibDist
2525

26-
from ..utils import PIP_VERSION, canonicalize_ireq
26+
from ..utils import PIP_VERSION, copy_install_requirement
2727

2828

2929
@dataclass(frozen=True)
@@ -89,8 +89,7 @@ def parse_requirements(
8989
file_link = FileLink(install_req.link.url)
9090
file_link._url = parsed_req.requirement
9191
install_req.link = file_link
92-
canonicalize_ireq(install_req)
93-
yield install_req
92+
yield copy_install_requirement(install_req)
9493

9594

9695
def create_wheel_cache(cache_dir: str, format_control: str | None = None) -> WheelCache:

piptools/build.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
from pip._vendor.packaging.markers import Marker
1818
from pip._vendor.packaging.requirements import Requirement
1919

20-
from .utils import canonicalize_ireq, install_req_from_line
20+
from .utils import copy_install_requirement, install_req_from_line
2121

2222
if sys.version_info >= (3, 11):
2323
import tomllib
@@ -231,7 +231,7 @@ def _prepare_requirements(
231231
replaced_package_name = req.replace(package_name, str(package_dir), 1)
232232
parts = parse_req_from_line(replaced_package_name, comes_from)
233233

234-
yield canonicalize_ireq(
234+
yield copy_install_requirement(
235235
InstallRequirement(
236236
parts.requirement,
237237
comes_from,

piptools/utils.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -93,20 +93,8 @@ def comment(text: str) -> str:
9393
return click.style(text, fg="green")
9494

9595

96-
def canonicalize_ireq(ireq: InstallRequirement) -> InstallRequirement:
97-
"""
98-
Return a copy of ireq with canonicalized extras strings
99-
"""
100-
ireq = copy_install_requirement(
101-
ireq, extras=set(map(canonicalize_name, ireq.extras))
102-
)
103-
if ireq.req:
104-
ireq.req.extras = set(ireq.extras)
105-
return ireq
106-
107-
10896
def install_req_from_line(*args: Any, **kwargs: Any) -> InstallRequirement:
109-
return canonicalize_ireq(_install_req_from_line(*args, **kwargs))
97+
return copy_install_requirement(_install_req_from_line(*args, **kwargs))
11098

11199

112100
def make_install_requirement(
@@ -536,6 +524,10 @@ def copy_install_requirement(
536524
if "req" not in kwargs:
537525
kwargs["req"] = copy.deepcopy(template.req)
538526

527+
kwargs["extras"] = set(map(canonicalize_name, kwargs["extras"]))
528+
if kwargs["req"]:
529+
kwargs["req"].extras = set(kwargs["extras"])
530+
539531
ireq = InstallRequirement(**kwargs)
540532

541533
# If the original_link was None, keep it so. Passing `link` as an

0 commit comments

Comments
 (0)