Skip to content

Commit

Permalink
Fold canonicalize-ireq-extras logic into copy_install_requirement
Browse files Browse the repository at this point in the history
  • Loading branch information
AndydeCleyre committed Mar 3, 2024
1 parent 78f2897 commit d0feb26
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 17 deletions.
4 changes: 2 additions & 2 deletions piptools/_compat/pip_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
)

Expand Down
4 changes: 2 additions & 2 deletions piptools/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -139,7 +139,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,
Expand Down
18 changes: 5 additions & 13 deletions piptools/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit d0feb26

Please sign in to comment.