Skip to content

Commit

Permalink
Merge pull request #411 from YannickJadoul/fix-docker-commandsubstitu…
Browse files Browse the repository at this point in the history
…tion

Fix command substitution in CIBW_ENVIRONMENT in Linux docker images
  • Loading branch information
joerick authored Jul 20, 2020
2 parents c0cb438 + 3142806 commit 726bcdf
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cibuildwheel/docker_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def get_environment(self) -> Dict[str, str]:

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:
Expand Down
3 changes: 3 additions & 0 deletions test/test_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@
# 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:
Expand Down
8 changes: 8 additions & 0 deletions unit_test/docker_container_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
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
Expand Down Expand Up @@ -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"

0 comments on commit 726bcdf

Please sign in to comment.