Skip to content

Commit cdf09bf

Browse files
committed
remove should_use_ephemeral_cache
1 parent 3ff414b commit cdf09bf

File tree

3 files changed

+10
-109
lines changed

3 files changed

+10
-109
lines changed

news/7268.trivial

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
refactoring: remove should_use_ephemeral_cache

src/pip/_internal/wheel.py

Lines changed: 9 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -838,35 +838,6 @@ def should_cache(
838838
return False
839839

840840

841-
def should_use_ephemeral_cache(
842-
req, # type: InstallRequirement
843-
should_unpack, # type: bool
844-
cache_available, # type: bool
845-
check_binary_allowed, # type: BinaryAllowedPredicate
846-
):
847-
# type: (...) -> Optional[bool]
848-
"""Return whether to build an InstallRequirement object using the
849-
ephemeral cache.
850-
851-
:param cache_available: whether a cache directory is available for the
852-
should_unpack=True case.
853-
854-
:return: True or False to build the requirement with ephem_cache=True
855-
or False, respectively; or None not to build the requirement.
856-
"""
857-
if not should_build(req, not should_unpack, check_binary_allowed):
858-
return None
859-
if not should_unpack:
860-
# i.e. pip wheel, not pip install;
861-
# return False, knowing that the caller will never cache
862-
# in this case anyway, so this return merely means "build it".
863-
# TODO improve this behavior
864-
return False
865-
if not cache_available:
866-
return True
867-
return not should_cache(req, check_binary_allowed)
868-
869-
870841
def format_command_result(
871842
command_args, # type: List[str]
872843
command_output, # type: str
@@ -1106,23 +1077,24 @@ def build(
11061077
cache_available = bool(self.wheel_cache.cache_dir)
11071078

11081079
for req in requirements:
1109-
ephem_cache = should_use_ephemeral_cache(
1080+
if not should_build(
11101081
req,
1111-
should_unpack=should_unpack,
1112-
cache_available=cache_available,
1082+
need_wheel=not should_unpack,
11131083
check_binary_allowed=self.check_binary_allowed,
1114-
)
1115-
if ephem_cache is None:
1084+
):
11161085
continue
11171086

11181087
# Determine where the wheel should go.
11191088
if should_unpack:
1120-
if ephem_cache:
1089+
if (
1090+
cache_available and
1091+
should_cache(req, self.check_binary_allowed)
1092+
):
1093+
output_dir = self.wheel_cache.get_path_for_link(req.link)
1094+
else:
11211095
output_dir = self.wheel_cache.get_ephem_path_for_link(
11221096
req.link
11231097
)
1124-
else:
1125-
output_dir = self.wheel_cache.get_path_for_link(req.link)
11261098
else:
11271099
output_dir = self._wheel_dir
11281100

tests/unit/test_wheel.py

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -166,78 +166,6 @@ def check_binary_allowed(req):
166166
assert should_cache is expected
167167

168168

169-
@pytest.mark.parametrize(
170-
"base_name, should_unpack, cache_available, expected",
171-
[
172-
('pendulum-2.0.4', False, False, False),
173-
# The following cases test should_unpack=True.
174-
# Test _contains_egg_info() returning True.
175-
('pendulum-2.0.4', True, True, False),
176-
('pendulum-2.0.4', True, False, True),
177-
# Test _contains_egg_info() returning False.
178-
('pendulum', True, True, True),
179-
('pendulum', True, False, True),
180-
],
181-
)
182-
def test_should_use_ephemeral_cache__issue_6197(
183-
base_name, should_unpack, cache_available, expected,
184-
):
185-
"""
186-
Regression test for: https://github.com/pypa/pip/issues/6197
187-
"""
188-
req = make_test_install_req(base_name=base_name)
189-
assert not req.is_wheel
190-
assert not req.link.is_vcs
191-
192-
always_true = Mock(return_value=True)
193-
194-
ephem_cache = wheel.should_use_ephemeral_cache(
195-
req, should_unpack=should_unpack,
196-
cache_available=cache_available, check_binary_allowed=always_true,
197-
)
198-
assert ephem_cache is expected
199-
200-
201-
@pytest.mark.parametrize(
202-
"disallow_binaries, expected",
203-
[
204-
# By default (i.e. when binaries are allowed), VCS requirements
205-
# should be built.
206-
(False, True),
207-
# Disallowing binaries, however, should cause them not to be built.
208-
(True, None),
209-
],
210-
)
211-
def test_should_use_ephemeral_cache__disallow_binaries_and_vcs_checkout(
212-
disallow_binaries, expected,
213-
):
214-
"""
215-
Test that disallowing binaries (e.g. from passing --global-option)
216-
causes should_use_ephemeral_cache() to return None for VCS checkouts.
217-
"""
218-
req = Requirement('pendulum')
219-
link = Link(url='git+https://git.example.com/pendulum.git')
220-
req = InstallRequirement(
221-
req=req,
222-
comes_from=None,
223-
constraint=False,
224-
editable=False,
225-
link=link,
226-
source_dir='/tmp/pip-install-9py5m2z1/pendulum',
227-
)
228-
assert not req.is_wheel
229-
assert req.link.is_vcs
230-
231-
check_binary_allowed = Mock(return_value=not disallow_binaries)
232-
233-
# The cache_available value doesn't matter for this test.
234-
ephem_cache = wheel.should_use_ephemeral_cache(
235-
req, should_unpack=True,
236-
cache_available=True, check_binary_allowed=check_binary_allowed,
237-
)
238-
assert ephem_cache is expected
239-
240-
241169
def test_format_command_result__INFO(caplog):
242170
caplog.set_level(logging.INFO)
243171
actual = wheel.format_command_result(

0 commit comments

Comments
 (0)