Skip to content

Commit

Permalink
Merge pull request #7268 from sbidoul/remove-should_use_ephem_cache-sbi
Browse files Browse the repository at this point in the history
remove should_use_ephemeral_cache
  • Loading branch information
chrahunt authored Nov 1, 2019
2 parents 5538244 + cdf09bf commit 2a2794e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 109 deletions.
1 change: 1 addition & 0 deletions news/7268.trivial
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
refactoring: remove should_use_ephemeral_cache
46 changes: 9 additions & 37 deletions src/pip/_internal/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -852,35 +852,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: Text
Expand Down Expand Up @@ -1146,23 +1117,24 @@ def build(
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

Expand Down
72 changes: 0 additions & 72 deletions tests/unit/test_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,78 +166,6 @@ def check_binary_allowed(req):
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(
Expand Down

0 comments on commit 2a2794e

Please sign in to comment.