From c1f155c0f2e506f1f8553a8a72ab9bbefcc82ade Mon Sep 17 00:00:00 2001 From: Grzegorz Bokota Date: Fri, 15 May 2020 13:13:13 +0200 Subject: [PATCH] add environment evaluation --- cibuildwheel/linux.py | 16 +++++++++++++++- cibuildwheel/macos.py | 3 ++- cibuildwheel/windows.py | 3 ++- docs/options.md | 2 ++ test/14_before_all/cibuildwheel_test.py | 3 ++- test/14_before_all/setup.py | 2 +- 6 files changed, 24 insertions(+), 5 deletions(-) diff --git a/cibuildwheel/linux.py b/cibuildwheel/linux.py index 8bbda24d..aa672f7b 100644 --- a/cibuildwheel/linux.py +++ b/cibuildwheel/linux.py @@ -135,7 +135,21 @@ def build(options: BuildOptions) -> None: if options.before_all: before_all_prepared = prepare_command(options.before_all, project='/project', package=options.package_dir) - call(['docker', 'exec', '-i', container_name] + shell_cmd, universal_newlines=True, input=before_all_prepared) + task = """ + PS4=' + ' + + set -o errexit + set -o xtrace + + {environment_exports} + + {before_all_prepared} + + """.format( + environment_exports='\n'.join(options.environment.as_shell_commands()), + before_all_prepared=before_all_prepared + ) + call(['docker', 'exec', '-i', container_name] + shell_cmd, universal_newlines=True, input=task) for config in platform_configs: if options.dependency_constraints: diff --git a/cibuildwheel/macos.py b/cibuildwheel/macos.py index 3e67b534..d9d892b9 100644 --- a/cibuildwheel/macos.py +++ b/cibuildwheel/macos.py @@ -177,8 +177,9 @@ def build(options: BuildOptions) -> None: repaired_wheel_dir = temp_dir / 'repaired_wheel' if options.before_all: + env = options.environment.as_dictionary(prev_environment=os.environ) before_all_prepared = prepare_command(options.before_all, project='.', package=options.package_dir) - call([before_all_prepared], shell=True) + call([before_all_prepared], shell=True, env=env) python_configurations = get_python_configurations(options.build_selector) diff --git a/cibuildwheel/windows.py b/cibuildwheel/windows.py index 73628c7f..bae831de 100644 --- a/cibuildwheel/windows.py +++ b/cibuildwheel/windows.py @@ -163,8 +163,9 @@ def build(options: BuildOptions) -> None: download('https://dist.nuget.org/win-x86-commandline/latest/nuget.exe', nuget) if options.before_all: + env = options.environment.as_dictionary(prev_environment=os.environ) before_all_prepared = prepare_command(options.before_all, project='.', package=options.package_dir) - shell([before_all_prepared]) + shell([before_all_prepared], env=env) python_configurations = get_python_configurations(options.build_selector) for config in python_configurations: diff --git a/docs/options.md b/docs/options.md index 0d61060d..ad2326d8 100644 --- a/docs/options.md +++ b/docs/options.md @@ -198,6 +198,8 @@ This option is added mainly for linux build, because linux wheels are build in i The placeholder `{package}` can be used here; it will be replaced by the path to the package being built by `cibuildwheel`. +For windows and macos `CIBW_BEFORE_ALL` python interpreter is same as `cibuildwheel` is run. For linux it is default interpreter for docker image. + Platform-specific variants also available:
`CIBW_BEFORE_ALL_MACOS` | `CIBW_BEFORE_ALL_WINDOWS` | `CIBW_BEFORE_ALL_LINUX` diff --git a/test/14_before_all/cibuildwheel_test.py b/test/14_before_all/cibuildwheel_test.py index d5be005a..1b7c8d03 100644 --- a/test/14_before_all/cibuildwheel_test.py +++ b/test/14_before_all/cibuildwheel_test.py @@ -13,7 +13,8 @@ def test(): actual_wheels = utils.cibuildwheel_run(project_dir, add_env={ # write python version information to a temporary file, this is # checked in setup.py - 'CIBW_BEFORE_ALL': '''python -c "open('{project}/text_info.txt', 'w').write('sample text')"''', + 'CIBW_BEFORE_ALL': '''python -c "import os;open('{project}/text_info.txt', 'w').write('sample text '+os.environ.get('TEST_VAL', ''))"''', + 'CIBW_ENVIRONMENT': "TEST_VAL='123'" }) # also check that we got the right wheels diff --git a/test/14_before_all/setup.py b/test/14_before_all/setup.py index d1cf0f48..bdcadcaa 100644 --- a/test/14_before_all/setup.py +++ b/test/14_before_all/setup.py @@ -9,7 +9,7 @@ with open("text_info.txt") as f: stored_text = f.read() print("## stored text: " + stored_text) -assert stored_text == "sample text" +assert stored_text == "sample text 123" setup(