Simplify check_binary_allowed

check_binary_allowed is only used to check
if a wheel needs to be built in 'pip install' mode.
It mixed format control and pep517 mode check.

We change it so it checks allowed formats only,
which leads to better readability of _should_build().
This commit is contained in:
Stéphane Bidoul 2020-12-31 12:33:14 +01:00
parent c383ec3b41
commit 06f1eff024
No known key found for this signature in database
GPG Key ID: BCAB2555446B5B92
3 changed files with 35 additions and 7 deletions

View File

@ -50,8 +50,6 @@ def get_check_binary_allowed(format_control):
# type: (FormatControl) -> BinaryAllowedPredicate
def check_binary_allowed(req):
# type: (InstallRequirement) -> bool
if req.use_pep517:
return True
canonical_name = canonicalize_name(req.name)
allowed_formats = format_control.get_allowed_formats(canonical_name)
return "binary" in allowed_formats

View File

@ -68,6 +68,9 @@ def _should_build(
if req.editable or not req.source_dir:
return False
if req.use_pep517:
return True
if not check_binary_allowed(req):
logger.info(
"Skipping wheel build for %s, due to binaries "
@ -75,7 +78,7 @@ def _should_build(
)
return False
if not req.use_pep517 and not is_wheel_installed():
if not is_wheel_installed():
# we don't build legacy requirements if wheel is not installed
logger.info(
"Using legacy 'setup.py install' for %s, "

View File

@ -53,17 +53,44 @@ class ReqMock:
@pytest.mark.parametrize(
"req, disallow_binaries, expected",
[
(ReqMock(), False, True),
(ReqMock(), True, False),
# When binaries are allowed, we build.
(ReqMock(use_pep517=True), False, True),
(ReqMock(use_pep517=False), False, True),
# When binaries are disallowed, we don't build, unless pep517 is
# enabled.
(ReqMock(use_pep517=True), True, True),
(ReqMock(use_pep517=False), True, False),
# We don't build constraints.
(ReqMock(constraint=True), False, False),
# We don't build reqs that are already wheels.
(ReqMock(is_wheel=True), False, False),
# We don't build editables.
(ReqMock(editable=True), False, False),
(ReqMock(source_dir=None), False, False),
# By default (i.e. when binaries are allowed), VCS requirements
# should be built in install mode.
(ReqMock(link=Link("git+https://g.c/org/repo")), False, True),
(
ReqMock(link=Link("git+https://g.c/org/repo"), use_pep517=True),
False,
True,
),
(
ReqMock(link=Link("git+https://g.c/org/repo"), use_pep517=False),
False,
True,
),
# Disallowing binaries, however, should cause them not to be built.
(ReqMock(link=Link("git+https://g.c/org/repo")), True, False),
# unless pep517 is enabled.
(
ReqMock(link=Link("git+https://g.c/org/repo"), use_pep517=True),
True,
True,
),
(
ReqMock(link=Link("git+https://g.c/org/repo"), use_pep517=False),
True,
False,
),
],
)
def test_should_build_for_install_command(req, disallow_binaries, expected):