Simplify prepare_command function and add deprecation warning
This commit is contained in:
@@ -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. '
|
||||
|
||||
@@ -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()),
|
||||
)
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user