Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove should_use_ephemeral_cache #7268

Merged
merged 1 commit into from
Nov 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -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
Expand Down Expand Up @@ -1106,23 +1077,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