Skip to content

Commit

Permalink
Remove cache_available parameter of should_cache
Browse files Browse the repository at this point in the history
For readbility: no need to ask if we can cache if we have no cache.
  • Loading branch information
sbidoul committed Aug 27, 2019
1 parent d4b1b15 commit 19299a0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 28 deletions.
21 changes: 6 additions & 15 deletions src/pip/_internal/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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


Expand Down Expand Up @@ -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))

Expand Down
21 changes: 8 additions & 13 deletions tests/unit/test_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 19299a0

Please sign in to comment.