From e28e43e7f98dbe8d7f3cd0ef26b5137270092eef Mon Sep 17 00:00:00 2001 From: Yannick Jadoul Date: Mon, 20 Jul 2020 02:02:50 +0200 Subject: [PATCH 1/2] Fix test_environment's checks on a command substitution in an environment --- test/test_environment.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/test_environment.py b/test/test_environment.py index dd2de0ea..7de1c0bf 100644 --- a/test/test_environment.py +++ b/test/test_environment.py @@ -13,12 +13,15 @@ project_with_environment_asserts = test_projects.new_c_project( # explode if environment isn't correct, as set in CIBW_ENVIRONMENT CIBW_TEST_VAR = os.environ.get("CIBW_TEST_VAR") CIBW_TEST_VAR_2 = os.environ.get("CIBW_TEST_VAR_2") + CIBW_TEST_VAR_3 = os.environ.get("CIBW_TEST_VAR_3") PATH = os.environ.get("PATH") if CIBW_TEST_VAR != "a b c": raise Exception('CIBW_TEST_VAR should equal "a b c". It was "%s"' % CIBW_TEST_VAR) if CIBW_TEST_VAR_2 != "1": raise Exception('CIBW_TEST_VAR_2 should equal "1". It was "%s"' % CIBW_TEST_VAR_2) + if CIBW_TEST_VAR_3 != "test string 3": + raise Exception('CIBW_TEST_VAR_3 should equal "test string 3". It was "%s"' % CIBW_TEST_VAR_3) if "/opt/cibw_test_path" not in PATH: raise Exception('PATH should contain "/opt/cibw_test_path". It was "%s"' % PATH) if "$PATH" in PATH: From 3142806f4b02411995f2857992fa24f14d7e5d3e Mon Sep 17 00:00:00 2001 From: Yannick Jadoul Date: Mon, 20 Jul 2020 02:23:07 +0200 Subject: [PATCH 2/2] Capture output in DockerContainer.environment_executor to fix command substitutions in CIBW_ENVIRONMENT on Linux --- cibuildwheel/docker_container.py | 2 +- unit_test/docker_container_test.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/cibuildwheel/docker_container.py b/cibuildwheel/docker_container.py index c3b226aa..ecf9c52f 100644 --- a/cibuildwheel/docker_container.py +++ b/cibuildwheel/docker_container.py @@ -182,7 +182,7 @@ class DockerContainer: def environment_executor(self, command: List[str], environment: Dict[str, str]) -> str: # used as an EnvironmentExecutor to evaluate commands and capture output - return self.call(command, env=environment) + return self.call(command, env=environment, capture_output=True) def shell_quote(path: PurePath) -> str: diff --git a/unit_test/docker_container_test.py b/unit_test/docker_container_test.py index fed06174..a3b6f06d 100644 --- a/unit_test/docker_container_test.py +++ b/unit_test/docker_container_test.py @@ -8,6 +8,7 @@ from pathlib import Path, PurePath import pytest from cibuildwheel.docker_container import DockerContainer +from cibuildwheel.environment import EnvironmentAssignment # for these tests we use manylinux2014 images, because they're available on # multi architectures and include python3.8 @@ -145,3 +146,10 @@ def test_dir_operations(tmp_path: Path): container.copy_out(dst_dir, new_test_dir) assert test_binary_data == (new_test_dir / 'test.dat').read_bytes() + + +@pytest.mark.docker +def test_environment_executor(): + with DockerContainer(DEFAULT_IMAGE) as container: + assignment = EnvironmentAssignment("TEST=$(echo 42)") + assert assignment.evaluated_value({}, container.environment_executor) == "42"