diff --git a/README.md b/README.md index 02ffa2cc..ebb1ba7d 100644 --- a/README.md +++ b/README.md @@ -196,7 +196,7 @@ A shell command to run before building the wheel. This option allows you to run If dependencies are required to build your wheel (for example if you include a header from a Python module), set this to `pip install .`, and the dependencies will be installed automatically by pip. However, this means your package will be built twice - if your package takes a long time to build, you might wish to manually list the dependencies here instead. -The active Python binary can be accessed using `python`, and pip with `pip`; `cibuildwheel` makes sure the right version of Python and pip will be executed. +The active Python binary can be accessed using `python`, and pip with `pip`; `cibuildwheel` makes sure the right version of Python and pip will be executed. `{project}` can be used as a placeholder for the absolute path to the project's root. Example: `pip install .` Example: `pip install pybind11` diff --git a/cibuildwheel/linux.py b/cibuildwheel/linux.py index cd7a7136..e81e231a 100644 --- a/cibuildwheel/linux.py +++ b/cibuildwheel/linux.py @@ -103,10 +103,10 @@ def build(project_dir, package_name, output_dir, test_command, test_requires, be pybin_paths=' '.join(c.path+'/bin' for c in platform_configs), test_requires=' '.join(test_requires), test_command=shlex_quote( - test_command.format(project='/project') if test_command else '' + prepare_command(test_command, python='python', pip='pip', project='/project') if test_command else '' ), before_build=shlex_quote( - prepare_command(before_build, python='python', pip='pip') if before_build else '' + prepare_command(before_build, python='python', pip='pip', project='/project') if before_build else '' ), environment_exports='\n'.join(environment.as_shell_commands()), ) diff --git a/cibuildwheel/macos.py b/cibuildwheel/macos.py index 73194c72..1a90c410 100644 --- a/cibuildwheel/macos.py +++ b/cibuildwheel/macos.py @@ -93,7 +93,7 @@ def build(project_dir, package_name, output_dir, test_command, test_requires, be # run the before_build command if before_build: - before_build_prepared = prepare_command(before_build, python='python', pip='pip') + before_build_prepared = prepare_command(before_build, python=python, pip=pip, project=abs_project_dir) call(before_build_prepared, env=env, shell=True) # build the wheel @@ -120,8 +120,8 @@ def build(project_dir, package_name, output_dir, test_command, test_requires, be # run the tests from $HOME, with an absolute path in the command # (this ensures that Python runs the tests against the installed wheel # and not the repo code) - test_command_absolute = test_command.format(project=abs_project_dir) - call(shlex.split(test_command_absolute), cwd=os.environ['HOME'], env=env) + test_command_prepared = prepare_command(test_command, python=python, pip=pip, project=abs_project_dir) + call(shlex.split(test_command_prepared), cwd=os.environ['HOME'], env=env) # we're all done here; move it to output shutil.move(delocated_wheel, output_dir) diff --git a/cibuildwheel/util.py b/cibuildwheel/util.py index d860beeb..9b1e2ccf 100644 --- a/cibuildwheel/util.py +++ b/cibuildwheel/util.py @@ -1,7 +1,7 @@ from fnmatch import fnmatch -def prepare_command(command, python, pip): +def prepare_command(command, python, pip, project): ''' Preprocesses a command by expanding variables like {python} or {pip}. @@ -10,7 +10,7 @@ def prepare_command(command, python, pip): 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) + return command.format(python=python, pip=pip, project=project) class BuildSkipper(object): diff --git a/cibuildwheel/windows.py b/cibuildwheel/windows.py index 3c962af9..42a38c80 100644 --- a/cibuildwheel/windows.py +++ b/cibuildwheel/windows.py @@ -78,7 +78,7 @@ def build(project_dir, package_name, output_dir, test_command, test_requires, be # run the before_build command if before_build: - before_build_prepared = prepare_command(before_build, python='python', pip='pip') + before_build_prepared = prepare_command(before_build, python='python', pip='pip', project=abs_project_dir) shell([before_build_prepared], env=env) # build the wheel @@ -95,8 +95,8 @@ def build(project_dir, package_name, output_dir, test_command, test_requires, be # run the tests from c:\, with an absolute path in the command # (this ensures that Python runs the tests against the installed wheel # and not the repo code) - test_command_absolute = test_command.format(project=abs_project_dir) - shell([test_command_absolute], cwd='c:\\', env=env) + test_command_prepared = prepare_command(test_command, python='python', pip='pip', project=abs_project_dir) + shell([test_command_prepared], cwd='c:\\', env=env) # we're all done here; move it to output shutil.move(built_wheel, output_dir)