From 19299a004a44d00fe7da449f2a1dad4c6a43b0b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bidoul=20=28ACSONE=29?= Date: Tue, 27 Aug 2019 19:01:04 +0200 Subject: [PATCH] Remove cache_available parameter of should_cache For readbility: no need to ask if we can cache if we have no cache. --- src/pip/_internal/wheel.py | 21 ++++++--------------- tests/unit/test_wheel.py | 21 ++++++++------------- 2 files changed, 14 insertions(+), 28 deletions(-) diff --git a/src/pip/_internal/wheel.py b/src/pip/_internal/wheel.py index b1b91a85ef8..e698cb371fe 100644 --- a/src/pip/_internal/wheel.py +++ b/src/pip/_internal/wheel.py @@ -819,18 +819,11 @@ def should_build( def should_cache( req, # type: InstallRequirement format_control, # type: FormatControl - cache_available, # type: bool ): # type: (...) -> Optional[bool] """ Return whether to build an InstallRequirement object using the - wheel cache. - - :param cache_available: whether a cache directory is available for the - should_unpack=True case. - - :return: True to use the persistent cache, - False to use the ephemeral cache. + wheel cache, assuming the wheel cache is available. """ if req.editable: # don't cache editable requirements because they can @@ -855,12 +848,11 @@ def should_cache( link = req.link base, ext = link.splitext() - if cache_available and _contains_egg_info(base): + if _contains_egg_info(base): return True # Otherwise, build the wheel just for this run using the ephemeral - # cache since we are either in the case of e.g. a local directory, or - # no cache directory is available to use. + # cache since we are either in the case of e.g. a local directory. return False @@ -1100,10 +1092,9 @@ def build( format_control=format_control, ): continue - use_ephemeral_cache = not should_cache( - req, - format_control=format_control, - cache_available=cache_available, + use_ephemeral_cache = ( + not cache_available or + not should_cache(req, format_control=format_control) ) buildset.append((req, use_ephemeral_cache)) diff --git a/tests/unit/test_wheel.py b/tests/unit/test_wheel.py index 055f810b533..c3accdf4e57 100644 --- a/tests/unit/test_wheel.py +++ b/tests/unit/test_wheel.py @@ -133,28 +133,23 @@ def test_should_build(req, need_wheel, disallow_binaries, expected): @pytest.mark.parametrize( - "req, disallow_binaries, cache_available, expected", + "req, disallow_binaries, expected", [ - (ReqMock(editable=True), False, True, False), - (ReqMock(editable=True), False, False, False), - (ReqMock(source_dir=None), False, True, False), - (ReqMock(source_dir=None), False, False, False), - (ReqMock(link=Link("git+https://g.c/org/repo")), False, True, False), - (ReqMock(link=Link("git+https://g.c/org/repo")), False, False, False), - (ReqMock(link=Link("https://g.c/dist.tgz")), False, True, False), - (ReqMock(link=Link("https://g.c/dist.tgz")), False, False, False), - (ReqMock(link=Link("https://g.c/dist-2.0.4.tgz")), False, True, True), - (ReqMock(link=Link("https://g.c/dist-2.0.4.tgz")), False, False, False), + (ReqMock(editable=True), False, False), + (ReqMock(source_dir=None), False, False), + (ReqMock(link=Link("git+https://g.c/org/repo")), False, False), + (ReqMock(link=Link("https://g.c/dist.tgz")), False, False), + (ReqMock(link=Link("https://g.c/dist-2.0.4.tgz")), False, True), ], ) def test_should_cache( - req, disallow_binaries, cache_available, expected + req, disallow_binaries, expected ): format_control = FormatControl() if disallow_binaries: format_control.disallow_binaries() should_cache = wheel.should_cache( - req, format_control=format_control, cache_available=cache_available + req, format_control=format_control, ) assert should_cache is expected