Skip to content

Commit 2a2794e

Browse files
authored
Merge pull request #7268 from sbidoul/remove-should_use_ephem_cache-sbi
remove should_use_ephemeral_cache
2 parents 5538244 + cdf09bf commit 2a2794e

File tree

3 files changed

+10
-109
lines changed

3 files changed

+10
-109
lines changed

news/7268.trivial

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
refactoring: remove should_use_ephemeral_cache

src/pip/_internal/wheel.py

+9-37
Original file line numberDiff line numberDiff line change
@@ -852,35 +852,6 @@ def should_cache(
852852
return False
853853

854854

855-
def should_use_ephemeral_cache(
856-
req, # type: InstallRequirement
857-
should_unpack, # type: bool
858-
cache_available, # type: bool
859-
check_binary_allowed, # type: BinaryAllowedPredicate
860-
):
861-
# type: (...) -> Optional[bool]
862-
"""Return whether to build an InstallRequirement object using the
863-
ephemeral cache.
864-
865-
:param cache_available: whether a cache directory is available for the
866-
should_unpack=True case.
867-
868-
:return: True or False to build the requirement with ephem_cache=True
869-
or False, respectively; or None not to build the requirement.
870-
"""
871-
if not should_build(req, not should_unpack, check_binary_allowed):
872-
return None
873-
if not should_unpack:
874-
# i.e. pip wheel, not pip install;
875-
# return False, knowing that the caller will never cache
876-
# in this case anyway, so this return merely means "build it".
877-
# TODO improve this behavior
878-
return False
879-
if not cache_available:
880-
return True
881-
return not should_cache(req, check_binary_allowed)
882-
883-
884855
def format_command_result(
885856
command_args, # type: List[str]
886857
command_output, # type: Text
@@ -1146,23 +1117,24 @@ def build(
11461117
cache_available = bool(self.wheel_cache.cache_dir)
11471118

11481119
for req in requirements:
1149-
ephem_cache = should_use_ephemeral_cache(
1120+
if not should_build(
11501121
req,
1151-
should_unpack=should_unpack,
1152-
cache_available=cache_available,
1122+
need_wheel=not should_unpack,
11531123
check_binary_allowed=self.check_binary_allowed,
1154-
)
1155-
if ephem_cache is None:
1124+
):
11561125
continue
11571126

11581127
# Determine where the wheel should go.
11591128
if should_unpack:
1160-
if ephem_cache:
1129+
if (
1130+
cache_available and
1131+
should_cache(req, self.check_binary_allowed)
1132+
):
1133+
output_dir = self.wheel_cache.get_path_for_link(req.link)
1134+
else:
11611135
output_dir = self.wheel_cache.get_ephem_path_for_link(
11621136
req.link
11631137
)
1164-
else:
1165-
output_dir = self.wheel_cache.get_path_for_link(req.link)
11661138
else:
11671139
output_dir = self._wheel_dir
11681140

tests/unit/test_wheel.py

-72
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)