From cdf09bfc4a6181ab2d39a612add7ad089c8045e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bidoul=20=28ACSONE=29?= Date: Tue, 29 Oct 2019 09:01:05 +0100 Subject: [PATCH] remove should_use_ephemeral_cache --- news/7268.trivial | 1 + src/pip/_internal/wheel.py | 46 +++++------------------- tests/unit/test_wheel.py | 72 -------------------------------------- 3 files changed, 10 insertions(+), 109 deletions(-) create mode 100644 news/7268.trivial diff --git a/news/7268.trivial b/news/7268.trivial new file mode 100644 index 00000000000..052c8279189 --- /dev/null +++ b/news/7268.trivial @@ -0,0 +1 @@ +refactoring: remove should_use_ephemeral_cache diff --git a/src/pip/_internal/wheel.py b/src/pip/_internal/wheel.py index 451ca57e8b2..d95ff66a474 100644 --- a/src/pip/_internal/wheel.py +++ b/src/pip/_internal/wheel.py @@ -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 @@ 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 diff --git a/tests/unit/test_wheel.py b/tests/unit/test_wheel.py index b530bcb6920..05413f9074e 100644 --- a/tests/unit/test_wheel.py +++ b/tests/unit/test_wheel.py @@ -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(