From 1a7abe562b51163c0b8d1d6901ab25da52550483 Mon Sep 17 00:00:00 2001 From: jack1142 <6032823+jack1142@users.noreply.github.com> Date: Mon, 25 Jul 2022 17:01:22 +0200 Subject: [PATCH] Remove dependency on Unix tools in Windows --- test/test_environment.py | 2 +- unit_test/environment_test.py | 29 +++++++++++++++++++++++------ 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/test/test_environment.py b/test/test_environment.py index 6ad8ff9f..d2b75f0a 100644 --- a/test/test_environment.py +++ b/test/test_environment.py @@ -43,7 +43,7 @@ def test(tmp_path): project_dir, add_env={ "CIBW_ENVIRONMENT": """CIBW_TEST_VAR="a b c" CIBW_TEST_VAR_2=1 CIBW_TEST_VAR_3="$(echo 'test string 3')" PATH=$PATH:/opt/cibw_test_path""", - "CIBW_ENVIRONMENT_WINDOWS": '''CIBW_TEST_VAR="a b c" CIBW_TEST_VAR_2=1 CIBW_TEST_VAR_3="$(echo 'test string 3')" PATH="$PATH;/opt/cibw_test_path"''', + "CIBW_ENVIRONMENT_WINDOWS": '''CIBW_TEST_VAR="a b c" CIBW_TEST_VAR_2=1 CIBW_TEST_VAR_3="$(cmd /C echo test string 3)" PATH="$PATH;/opt/cibw_test_path"''', }, ) diff --git a/unit_test/environment_test.py b/unit_test/environment_test.py index c1d0a4a1..8c67b259 100644 --- a/unit_test/environment_test.py +++ b/unit_test/environment_test.py @@ -1,4 +1,5 @@ import os +import sys from cibuildwheel.environment import parse_environment @@ -28,7 +29,11 @@ def test_inheritance(): def test_shell_eval(): - environment_recipe = parse_environment('VAR="$(echo "a test" string)"') + if sys.platform == "win32": + env_string = 'VAR="$(cmd /C "echo a test string")"' + else: + env_string = 'VAR="$(echo "a test" string)"' + environment_recipe = parse_environment(env_string) env_copy = os.environ.copy() env_copy.pop("VAR", None) @@ -39,7 +44,11 @@ def test_shell_eval(): def test_shell_eval_and_env(): - environment_recipe = parse_environment('VAR="$(echo "$PREV_VAR" string)"') + if sys.platform == "win32": + env_string = 'VAR="$(cmd /C "echo $PREV_VAR string")"' + else: + env_string = 'VAR="$(echo "$PREV_VAR" string)"' + environment_recipe = parse_environment(env_string) environment_dict = environment_recipe.as_dictionary(prev_environment={"PREV_VAR": "1 2 3"}) @@ -73,7 +82,11 @@ def test_no_vars_pass_through(): def test_operators_inside_eval(): - environment_recipe = parse_environment('SOMETHING="$(echo a; echo b; echo c)"') + if sys.platform == "win32": + env_string = 'SOMETHING="$(cmd /C echo a; cmd /C echo b; cmd /C echo c)"' + else: + env_string = 'SOMETHING="$(echo a; echo b; echo c)"' + environment_recipe = parse_environment(env_string) # pass the existing process env so PATH is available environment_dict = environment_recipe.as_dictionary(os.environ.copy()) @@ -91,9 +104,13 @@ def test_substitution_with_backslash(): def test_awkwardly_quoted_variable(): - environment_recipe = parse_environment( - 'VAR2=something"like this""$VAR1"$VAR1$(echo "there is more")"$(echo "and more!")"' - ) + if sys.platform == "win32": + env_string = 'VAR2=something"like this""$VAR1"$VAR1$(cmd /C echo there is more)"$(cmd /C echo and more!)"' + else: + env_string = ( + 'VAR2=something"like this""$VAR1"$VAR1$(echo "there is more")"$(echo "and more!")"' + ) + environment_recipe = parse_environment(env_string) # pass the existing process env so PATH is available environment_dict = environment_recipe.as_dictionary({"VAR1": "but wait"})