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 May 13, 2024
1 parent f13c20f commit 7a1fada
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 18 deletions.
5 changes: 2 additions & 3 deletions piptools/_compat/pip_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,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 @@ -89,8 +89,7 @@ def parse_requirements(
file_link = FileLink(install_req.link.url)
file_link._url = parsed_req.requirement
install_req.link = file_link
canonicalize_ireq(install_req)
yield install_req
yield copy_install_requirement(install_req)


def create_wheel_cache(cache_dir: str, format_control: str | None = None) -> WheelCache:
Expand Down
4 changes: 2 additions & 2 deletions piptools/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from pip._vendor.packaging.markers import Marker
from pip._vendor.packaging.requirements import Requirement

from .utils import canonicalize_ireq, install_req_from_line
from .utils import copy_install_requirement, install_req_from_line

if sys.version_info >= (3, 11):
import tomllib
Expand Down Expand Up @@ -231,7 +231,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 @@ -536,6 +524,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 7a1fada

Please sign in to comment.