1
1
Fork 0
mirror of https://github.com/pypa/pip synced 2023-12-13 21:30:23 +01:00

remove should_use_ephemeral_cache

This commit is contained in:
Stéphane Bidoul (ACSONE) 2019-10-29 09:01:05 +01:00
parent 3ff414be9f
commit cdf09bfc4a
No known key found for this signature in database
GPG key ID: BCAB2555446B5B92
3 changed files with 10 additions and 109 deletions

1
news/7268.trivial Normal file
View file

@ -0,0 +1 @@
refactoring: remove should_use_ephemeral_cache

View file

@ -838,35 +838,6 @@ def should_cache(
return False
def should_use_ephemeral_cache(
req, # type: InstallRequirement
should_unpack, # type: bool
cache_available, # type: bool
check_binary_allowed, # type: BinaryAllowedPredicate
):
# type: (...) -> Optional[bool]
"""Return whether to build an InstallRequirement object using the
ephemeral cache.
:param cache_available: whether a cache directory is available for the
should_unpack=True case.
:return: True or False to build the requirement with ephem_cache=True
or False, respectively; or None not to build the requirement.
"""
if not should_build(req, not should_unpack, check_binary_allowed):
return None
if not should_unpack:
# i.e. pip wheel, not pip install;
# return False, knowing that the caller will never cache
# in this case anyway, so this return merely means "build it".
# TODO improve this behavior
return False
if not cache_available:
return True
return not should_cache(req, check_binary_allowed)
def format_command_result(
command_args, # type: List[str]
command_output, # type: str
@ -1106,23 +1077,24 @@ class WheelBuilder(object):
cache_available = bool(self.wheel_cache.cache_dir)
for req in requirements:
ephem_cache = should_use_ephemeral_cache(
if not should_build(
req,
should_unpack=should_unpack,
cache_available=cache_available,
need_wheel=not should_unpack,
check_binary_allowed=self.check_binary_allowed,
)
if ephem_cache is None:
):
continue
# Determine where the wheel should go.
if should_unpack:
if ephem_cache:
if (
cache_available and
should_cache(req, self.check_binary_allowed)
):
output_dir = self.wheel_cache.get_path_for_link(req.link)
else:
output_dir = self.wheel_cache.get_ephem_path_for_link(
req.link
)
else:
output_dir = self.wheel_cache.get_path_for_link(req.link)
else:
output_dir = self._wheel_dir

View file

@ -166,78 +166,6 @@ def test_should_cache(
assert should_cache is expected
@pytest.mark.parametrize(
"base_name, should_unpack, cache_available, expected",
[
('pendulum-2.0.4', False, False, False),
# The following cases test should_unpack=True.
# Test _contains_egg_info() returning True.
('pendulum-2.0.4', True, True, False),
('pendulum-2.0.4', True, False, True),
# Test _contains_egg_info() returning False.
('pendulum', True, True, True),
('pendulum', True, False, True),
],
)
def test_should_use_ephemeral_cache__issue_6197(
base_name, should_unpack, cache_available, expected,
):
"""
Regression test for: https://github.com/pypa/pip/issues/6197
"""
req = make_test_install_req(base_name=base_name)
assert not req.is_wheel
assert not req.link.is_vcs
always_true = Mock(return_value=True)
ephem_cache = wheel.should_use_ephemeral_cache(
req, should_unpack=should_unpack,
cache_available=cache_available, check_binary_allowed=always_true,
)
assert ephem_cache is expected
@pytest.mark.parametrize(
"disallow_binaries, expected",
[
# By default (i.e. when binaries are allowed), VCS requirements
# should be built.
(False, True),
# Disallowing binaries, however, should cause them not to be built.
(True, None),
],
)
def test_should_use_ephemeral_cache__disallow_binaries_and_vcs_checkout(
disallow_binaries, expected,
):
"""
Test that disallowing binaries (e.g. from passing --global-option)
causes should_use_ephemeral_cache() to return None for VCS checkouts.
"""
req = Requirement('pendulum')
link = Link(url='git+https://git.example.com/pendulum.git')
req = InstallRequirement(
req=req,
comes_from=None,
constraint=False,
editable=False,
link=link,
source_dir='/tmp/pip-install-9py5m2z1/pendulum',
)
assert not req.is_wheel
assert req.link.is_vcs
check_binary_allowed = Mock(return_value=not disallow_binaries)
# The cache_available value doesn't matter for this test.
ephem_cache = wheel.should_use_ephemeral_cache(
req, should_unpack=True,
cache_available=True, check_binary_allowed=check_binary_allowed,
)
assert ephem_cache is expected
def test_format_command_result__INFO(caplog):
caplog.set_level(logging.INFO)
actual = wheel.format_command_result(