Simplify prepare_command function and add deprecation warning

This commit is contained in:
Joe Rickerby
2018-04-08 18:25:18 +01:00
parent 4655311a7a
commit b74333a940
5 changed files with 18 additions and 10 deletions
+4 -1
View File
@@ -1,5 +1,5 @@
from __future__ import print_function from __future__ import print_function
import argparse, os, subprocess, sys, textwrap import argparse, os, subprocess, sys, textwrap, warnings
import cibuildwheel import cibuildwheel
import cibuildwheel.linux, cibuildwheel.windows, cibuildwheel.macos import cibuildwheel.linux, cibuildwheel.windows, cibuildwheel.macos
@@ -25,6 +25,9 @@ def get_option_from_environment(option_name, platform=None):
def main(): def main():
# enable deprecation warnings
warnings.filterwarnings("once", ".*", DeprecationWarning)
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
description='Build wheels for all the platforms.', description='Build wheels for all the platforms.',
epilog=('Most options are supplied via environment variables. ' epilog=('Most options are supplied via environment variables. '
+2 -2
View File
@@ -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), pybin_paths=' '.join(c.path+'/bin' for c in platform_configs),
test_requires=' '.join(test_requires), test_requires=' '.join(test_requires),
test_command=shlex_quote( 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( 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()), environment_exports='\n'.join(environment.as_shell_commands()),
) )
+2 -2
View File
@@ -93,7 +93,7 @@ def build(project_dir, package_name, output_dir, test_command, test_requires, be
# run the before_build command # run the before_build command
if before_build: 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) call(before_build_prepared, env=env, shell=True)
# build the wheel # 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 # run the tests from $HOME, with an absolute path in the command
# (this ensures that Python runs the tests against the installed wheel # (this ensures that Python runs the tests against the installed wheel
# and not the repo code) # 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) call(shlex.split(test_command_prepared), cwd=os.environ['HOME'], env=env)
# we're all done here; move it to output # we're all done here; move it to output
+8 -3
View File
@@ -1,16 +1,21 @@
from fnmatch import fnmatch 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 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 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 Python 3, the user could write `{python} setup.py test`. This command would expand
it out to python2 or python3 as appropriate. 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): class BuildSkipper(object):
+2 -2
View File
@@ -78,7 +78,7 @@ def build(project_dir, package_name, output_dir, test_command, test_requires, be
# run the before_build command # run the before_build command
if before_build: 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) shell([before_build_prepared], env=env)
# build the wheel # 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 # run the tests from c:\, with an absolute path in the command
# (this ensures that Python runs the tests against the installed wheel # (this ensures that Python runs the tests against the installed wheel
# and not the repo code) # 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) shell([test_command_prepared], cwd='c:\\', env=env)
# we're all done here; move it to output # we're all done here; move it to output