Skip to content

Commit

Permalink
Remove various extras normalization workarounds
Browse files Browse the repository at this point in the history
  • Loading branch information
sbidoul committed Oct 1, 2023
1 parent cab0a56 commit 3af04b6
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 28 deletions.
8 changes: 1 addition & 7 deletions src/pip/_internal/req/req_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
is_installable_dir,
redact_auth_from_url,
)
from pip._internal.utils.packaging import safe_extra
from pip._internal.utils.subprocess import runner_with_spinner_message
from pip._internal.utils.temp_dir import TempDirectory, tempdir_kinds
from pip._internal.utils.unpacking import unpack_file
Expand Down Expand Up @@ -272,12 +271,7 @@ def match_markers(self, extras_requested: Optional[Iterable[str]] = None) -> boo
extras_requested = ("",)
if self.markers is not None:
return any(
self.markers.evaluate({"extra": extra})
# TODO: Remove these two variants when packaging is upgraded to
# support the marker comparison logic specified in PEP 685.
or self.markers.evaluate({"extra": safe_extra(extra)})
or self.markers.evaluate({"extra": canonicalize_name(extra)})
for extra in extras_requested
self.markers.evaluate({"extra": extra}) for extra in extras_requested
)
else:
return True
Expand Down
10 changes: 1 addition & 9 deletions src/pip/_internal/resolution/resolvelib/candidates.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,14 +430,6 @@ def __init__(
) -> None:
self.base = base
self.extras = frozenset(canonicalize_name(e) for e in extras)
# If any extras are requested in their non-normalized forms, keep track
# of their raw values. This is needed when we look up dependencies
# since PEP 685 has not been implemented for marker-matching, and using
# the non-normalized extra for lookup ensures the user can select a
# non-normalized extra in a package with its non-normalized form.
# TODO: Remove this attribute when packaging is upgraded to support the
# marker comparison logic specified in PEP 685.
self._unnormalized_extras = extras.difference(self.extras)

def __str__(self) -> str:
name, rest = str(self.base).split(" ", 1)
Expand Down Expand Up @@ -523,7 +515,7 @@ def _calculate_valid_requested_extras(self) -> FrozenSet[str]:
candidate doesn't support. Any unsupported extras are dropped, and each
cause a warning to be logged here.
"""
requested_extras = self.extras.union(self._unnormalized_extras)
requested_extras = self.extras
valid_extras = frozenset(
extra
for extra in requested_extras
Expand Down
14 changes: 2 additions & 12 deletions tests/functional/test_install_extras.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,24 +152,14 @@ def test_install_fails_if_extra_at_end(
script.scratch_path / "requirements.txt",
expect_error=True,
)
assert "Extras after version" in result.stderr
assert "Invalid requirement: 'requires_simple_extra>=0.1[extra]'" in result.stderr


@pytest.mark.parametrize(
"specified_extra, requested_extra",
[
("Hop_hOp-hoP", "Hop_hOp-hoP"),
pytest.param(
"Hop_hOp-hoP",
"hop-hop-hop",
marks=pytest.mark.xfail(
reason=(
"matching a normalized extra request against an"
"unnormalized extra in metadata requires PEP 685 support "
"in packaging (see pypa/pip#11445)."
),
),
),
("Hop_hOp-hoP", "hop-hop-hop"),
("hop-hop-hop", "Hop_hOp-hoP"),
],
)
Expand Down

0 comments on commit 3af04b6

Please sign in to comment.