From b74333a94074d5bed6fa767af61ed02f5efbdf93 Mon Sep 17 00:00:00 2001 From: Joe Rickerby Date: Sun, 8 Apr 2018 18:25:18 +0100 Subject: [PATCH] Simplify prepare_command function and add deprecation warning --- cibuildwheel/__main__.py | 5 ++++- cibuildwheel/linux.py | 4 ++-- cibuildwheel/macos.py | 4 ++-- cibuildwheel/util.py | 11 ++++++++--- cibuildwheel/windows.py | 4 ++-- 5 files changed, 18 insertions(+), 10 deletions(-) diff --git a/cibuildwheel/__main__.py b/cibuildwheel/__main__.py index b8f1ac07..81fb2612 100644 --- a/cibuildwheel/__main__.py +++ b/cibuildwheel/__main__.py @@ -1,5 +1,5 @@ from __future__ import print_function -import argparse, os, subprocess, sys, textwrap +import argparse, os, subprocess, sys, textwrap, warnings import cibuildwheel import cibuildwheel.linux, cibuildwheel.windows, cibuildwheel.macos @@ -25,6 +25,9 @@ def get_option_from_environment(option_name, platform=None): def main(): + # enable deprecation warnings + warnings.filterwarnings("once", ".*", DeprecationWarning) + parser = argparse.ArgumentParser( description='Build wheels for all the platforms.', epilog=('Most options are supplied via environment variables. ' diff --git a/cibuildwheel/linux.py b/cibuildwheel/linux.py index e81e231a..b51be81c 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( - prepare_command(test_command, python='python', pip='pip', project='/project') if test_command else '' + prepare_command(test_command, project='/project') if test_command else '' ), before_build=shlex_quote( - prepare_command(before_build, python='python', pip='pip', project='/project') if before_build else '' + prepare_command(before_build, 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 1a90c410..569f14a9 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, project=abs_project_dir) + before_build_prepared = prepare_command(before_build, project=abs_project_dir) call(before_build_prepared, env=env, shell=True) # build the wheel @@ -120,7 +120,7 @@ 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_prepared = prepare_command(test_command, python=python, pip=pip, project=abs_project_dir) + test_command_prepared = prepare_command(test_command, 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 diff --git a/cibuildwheel/util.py b/cibuildwheel/util.py index 9b1e2ccf..763d9cf2 100644 --- a/cibuildwheel/util.py +++ b/cibuildwheel/util.py @@ -1,16 +1,21 @@ from fnmatch import fnmatch +import warnings -def prepare_command(command, python, pip, project): +def prepare_command(command, project): ''' - Preprocesses a command by expanding variables like {python} or {pip}. + Preprocesses a command by expanding variables like {project}. 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, project=project) + if '{python}' in command or '{pip}' in command: + warnings.warn("'{python}' and '{pip}' are no longer needed, and have been deprecated. Simply use 'python' or 'pip' instead.", + DeprecationWarning) + + return command.format(python='python', pip='pip', project=project) class BuildSkipper(object): diff --git a/cibuildwheel/windows.py b/cibuildwheel/windows.py index 42a38c80..1c3e5fbd 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', project=abs_project_dir) + before_build_prepared = prepare_command(before_build, project=abs_project_dir) shell([before_build_prepared], env=env) # build the wheel @@ -95,7 +95,7 @@ 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_prepared = prepare_command(test_command, python='python', pip='pip', project=abs_project_dir) + test_command_prepared = prepare_command(test_command, project=abs_project_dir) shell([test_command_prepared], cwd='c:\\', env=env) # we're all done here; move it to output