From 2ebde4c078db7e82f94c0a9c37982e008357e572 Mon Sep 17 00:00:00 2001 From: Yannick Jadoul Date: Sun, 8 Apr 2018 17:01:54 +0200 Subject: [PATCH] Reverting removal of `prepare_command` to maintain backwards compatibility of configurations with {python} and {pip} --- cibuildwheel/linux.py | 5 ++++- cibuildwheel/macos.py | 5 ++++- cibuildwheel/util.py | 12 ++++++++++++ cibuildwheel/windows.py | 5 +++-- 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/cibuildwheel/linux.py b/cibuildwheel/linux.py index 9b6ab4d1..cd7a7136 100644 --- a/cibuildwheel/linux.py +++ b/cibuildwheel/linux.py @@ -1,6 +1,7 @@ from __future__ import print_function import os, subprocess, sys from collections import namedtuple +from .util import prepare_command try: from shlex import quote as shlex_quote @@ -104,7 +105,9 @@ def build(project_dir, package_name, output_dir, test_command, test_requires, be test_command=shlex_quote( test_command.format(project='/project') if test_command else '' ), - before_build=shlex_quote(before_build or ''), + before_build=shlex_quote( + prepare_command(before_build, python='python', pip='pip') if before_build else '' + ), environment_exports='\n'.join(environment.as_shell_commands()), ) diff --git a/cibuildwheel/macos.py b/cibuildwheel/macos.py index 6829e835..d0de6f2e 100644 --- a/cibuildwheel/macos.py +++ b/cibuildwheel/macos.py @@ -7,6 +7,8 @@ try: except ImportError: from pipes import quote as shlex_quote +from .util import prepare_command + def build(project_dir, package_name, output_dir, test_command, test_requires, before_build, skip, environment): PythonConfiguration = namedtuple('PythonConfiguration', ['version', 'identifier', 'url']) @@ -83,7 +85,8 @@ def build(project_dir, package_name, output_dir, test_command, test_requires, be # run the before_build command if before_build: - call(before_build, env=env, shell=True) + before_build_prepared = prepare_command(before_build, python='python', pip='pip') + call(before_build_prepared, env=env, shell=True) # build the wheel call(['pip', 'wheel', abs_project_dir, '-w', '/tmp/built_wheel', '--no-deps'], env=env) diff --git a/cibuildwheel/util.py b/cibuildwheel/util.py index e15d2ddd..d860beeb 100644 --- a/cibuildwheel/util.py +++ b/cibuildwheel/util.py @@ -1,6 +1,18 @@ from fnmatch import fnmatch +def prepare_command(command, python, pip): + ''' + Preprocesses a command by expanding variables like {python} or {pip}. + + For example, used for the before_build option, where the user would + like to run a command like `python setup.py test`. If the command should run on + Python 3, the user could write `{python} setup.py test`. This command would expand + it out to python2 or python3 as appropriate. + ''' + return command.format(python=python, pip=pip) + + class BuildSkipper(object): def __init__(self, skip_config): self.patterns = skip_config.split() diff --git a/cibuildwheel/windows.py b/cibuildwheel/windows.py index 1ea37128..3c962af9 100644 --- a/cibuildwheel/windows.py +++ b/cibuildwheel/windows.py @@ -7,7 +7,7 @@ except ImportError: from collections import namedtuple from glob import glob -from .util import Unbuffered +from .util import prepare_command, Unbuffered def build(project_dir, package_name, output_dir, test_command, test_requires, before_build, skip, environment): @@ -78,7 +78,8 @@ def build(project_dir, package_name, output_dir, test_command, test_requires, be # run the before_build command if before_build: - shell([before_build], env=env) + before_build_prepared = prepare_command(before_build, python='python', pip='pip') + shell([before_build_prepared], env=env) # build the wheel shell(['pip', 'wheel', abs_project_dir, '-w', built_wheel_dir, '--no-deps'], env=env)