diff --git a/cibuildwheel/bashlex_eval.py b/cibuildwheel/bashlex_eval.py index 57791b2c..2c61bc54 100644 --- a/cibuildwheel/bashlex_eval.py +++ b/cibuildwheel/bashlex_eval.py @@ -1,15 +1,14 @@ -import shlex import subprocess from typing import Callable, Dict, List, NamedTuple, Optional, Sequence import bashlex # type: ignore -# a function that takes a shell command and the environment, and returns the result -EnvironmentExecutor = Callable[[str, Dict[str, str]], str] +# a function that takes a command and the environment, and returns the result +EnvironmentExecutor = Callable[[List[str], Dict[str, str]], str] -def local_environment_executor(command: str, env: Dict[str, str]) -> str: - return subprocess.check_output(shlex.split(command), env=env, universal_newlines=True) +def local_environment_executor(command: List[str], env: Dict[str, str]) -> str: + return subprocess.check_output(command, env=env, universal_newlines=True) class NodeExecutionContext(NamedTuple): @@ -97,8 +96,7 @@ def evaluate_nodes_as_compound_command(nodes: Sequence[bashlex.ast.node], contex def evaluate_nodes_as_simple_command(nodes: List[bashlex.ast.node], context: NodeExecutionContext): - words = [evaluate_node(part, context=context) for part in nodes] - command = ' '.join(words) + command = [evaluate_node(part, context=context) for part in nodes] return context.executor(command, context.environment) diff --git a/cibuildwheel/docker_container.py b/cibuildwheel/docker_container.py index 41b2f42f..c3b226aa 100644 --- a/cibuildwheel/docker_container.py +++ b/cibuildwheel/docker_container.py @@ -180,9 +180,9 @@ class DockerContainer: 'import sys, json, os; json.dump(os.environ.copy(), sys.stdout)' ], capture_output=True)) - def environment_executor(self, command: str, environment: Dict[str, 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(shlex.split(command), env=environment) + return self.call(command, env=environment) def shell_quote(path: PurePath) -> str: diff --git a/unit_test/environment_test.py b/unit_test/environment_test.py index 0827cc0d..ab690a84 100644 --- a/unit_test/environment_test.py +++ b/unit_test/environment_test.py @@ -40,7 +40,7 @@ def test_inheritance(): def test_shell_eval(): - environment_recipe = parse_environment('VAR="$(echo "a test" string)"') + environment_recipe = parse_environment('VAR="$(echo "a test" string)"') env_copy = os.environ.copy() env_copy.pop('VAR', None) @@ -50,8 +50,8 @@ def test_shell_eval(): ) environment_cmds = environment_recipe.as_shell_commands() - assert environment_dict['VAR'] == 'a test string' - assert environment_cmds == ['export VAR="$(echo "a test" string)"'] + assert environment_dict['VAR'] == 'a test string' + assert environment_cmds == ['export VAR="$(echo "a test" string)"'] def test_shell_eval_and_env():