Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
94 changes: 51 additions & 43 deletions cibuildwheel/platforms/ios.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import subprocess
import sys
import textwrap
from collections.abc import Sequence, Set
from collections.abc import Iterator, Sequence, Set
from pathlib import Path
from typing import assert_never

Expand Down Expand Up @@ -42,6 +42,17 @@
from .macos import install_cpython as install_build_cpython


def split_command(lst: list[str]) -> Iterator[list[str]]:
Comment thread
joerick marked this conversation as resolved.
Outdated
Comment thread
joerick marked this conversation as resolved.
Outdated
items = list[str]()
Comment thread
henryiii marked this conversation as resolved.
Outdated
for item in lst:
if item == "&&":
yield items
items = []
else:
items.append(item)
yield items


@dataclasses.dataclass(frozen=True, kw_only=True)
class PythonConfiguration:
version: str
Expand Down Expand Up @@ -618,14 +629,15 @@ def build(options: Options, tmp_path: Path) -> None:
)
raise errors.FatalError(msg)

test_command_parts = shlex.split(build_options.test_command)
if test_command_parts[0:2] != ["python", "-m"]:
first_part = test_command_parts[0]
if first_part == "pytest":
# pytest works exactly the same as a module, so we
# can just run it as a module.
log.warning(
unwrap_preserving_paragraphs(f"""
test_command_list = shlex.split(build_options.test_command)
for test_command_parts in split_command(test_command_list):
match test_command_parts:
case ["python", "-m", *rest]:
final_command = rest
case ["pytest", *rest]:
# pytest works exactly the same as a module, so we
# can just run it as a module.
Comment thread
joerick marked this conversation as resolved.
Outdated
msg = unwrap_preserving_paragraphs(f"""
iOS tests configured with a test command which doesn't start
with 'python -m'. iOS tests must execute python modules - other
entrypoints are not supported.
Expand All @@ -636,43 +648,39 @@ def build(options: Options, tmp_path: Path) -> None:

Test command: {build_options.test_command!r}
""")
log.warning(msg)
final_command = ["pytest", *rest]
case _:
msg = unwrap_preserving_paragraphs(
f"""
iOS tests configured with a test command which doesn't start
with 'python -m'. iOS tests must execute python modules - other
entrypoints are not supported.

Test command: {build_options.test_command!r}
"""
)
raise errors.FatalError(msg)

try:
call(
"python",
testbed_path,
"run",
*(["--verbose"] if build_options.build_verbosity > 0 else []),
"--",
*final_command,
env=test_env,
)
else:
msg = unwrap_preserving_paragraphs(
f"""
iOS tests configured with a test command which doesn't start
with 'python -m'. iOS tests must execute python modules - other
entrypoints are not supported.

Test command: {build_options.test_command!r}
"""
)
raise errors.FatalError(msg)
else:
# the testbed run command actually doesn't want the
# python -m prefix - it's implicit, so we remove it
# here.
test_command_parts = test_command_parts[2:]

try:
call(
"python",
testbed_path,
"run",
*(["--verbose"] if build_options.build_verbosity > 0 else []),
"--",
*test_command_parts,
env=test_env,
)
failed = False
except subprocess.CalledProcessError:
failed = True
failed = False
except subprocess.CalledProcessError:
failed = True
Comment thread
joerick marked this conversation as resolved.
Outdated

log.step_end(success=not failed)
log.step_end(success=not failed)

if failed:
log.error(f"Test suite failed on {config.identifier}")
sys.exit(1)
if failed:
log.error(f"Test suite failed on {config.identifier}")
sys.exit(1)

# We're all done here; move it to output (overwrite existing)
if compatible_wheel is None:
Expand Down
5 changes: 4 additions & 1 deletion test/test_ios.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def test_ios_platforms(tmp_path, build_config, monkeypatch, capfd):
"CIBW_BUILD": "cp313-*",
"CIBW_XBUILD_TOOLS": "does-exist",
"CIBW_TEST_SOURCES": "tests",
"CIBW_TEST_COMMAND": "python -m unittest discover tests test_platform.py",
"CIBW_TEST_COMMAND": "python -m this && python -m unittest discover tests test_platform.py",
"CIBW_BUILD_VERBOSITY": "1",
**build_config,
},
Expand All @@ -102,6 +102,9 @@ def test_ios_platforms(tmp_path, build_config, monkeypatch, capfd):
captured = capfd.readouterr()
assert "'does-exist' will be included in the cross-build environment" in captured.out

# Make sure the first command ran
assert "Zen of Python" in captured.out


@pytest.mark.serial
def test_no_test_sources(tmp_path, capfd):
Expand Down