Files
cibuildwheel/cibuildwheel/__main__.py
T

142 lines
5.4 KiB
Python
Raw Normal View History

2017-03-19 20:57:51 +00:00
from __future__ import print_function
2017-04-13 15:02:04 +01:00
import argparse, os, subprocess, sys, textwrap
2017-03-19 20:57:51 +00:00
2017-04-13 15:02:04 +01:00
import cibuildwheel
import cibuildwheel.linux, cibuildwheel.windows, cibuildwheel.macos
2017-04-11 22:57:42 +01:00
from cibuildwheel.util import BuildSkipper
2017-03-19 20:57:51 +00:00
def get_option_from_environment(option_name, platform=None):
'''
Returns an option from the environment, optionally scoped by the platform.
Example:
get_option_from_environment('CIBW_COLOR', platform='macos')
This will return the value of CIBW_COLOR_MACOS if it exists, otherwise the value of
CIBW_COLOR.
'''
if platform:
option = os.environ.get('%s_%s' % (option_name, platform.upper()))
if option is not None:
return option
return os.environ.get(option_name)
2017-03-19 20:57:51 +00:00
def main():
parser = argparse.ArgumentParser(
description='Build wheels for all the platforms.',
epilog=('Most options are supplied via environment variables. '
'See https://github.com/joerick/cibuildwheel#options for info.'))
parser.add_argument('--platform',
choices=['auto', 'linux', 'macos', 'windows'],
2017-03-23 11:19:14 +00:00
default=os.environ.get('CIBW_PLATFORM', 'auto'),
2017-03-19 20:57:51 +00:00
help=('Platform to build for. For "linux" you need docker running, on Mac '
'or Linux. For "macos", you need a Mac machine, and note that this '
'script is going to automatically install MacPython on your system, '
'so don\'t run on your development machine. For "windows", you need to '
'run in Windows, and it will build and test for all versions of '
'Python at C:\\PythonXX[-x64]. Default: auto.'))
parser.add_argument('--output-dir',
default=os.environ.get('CIBW_OUTPUT_DIR', 'wheelhouse'),
help='Destination folder for the wheels.')
parser.add_argument('project_dir',
default='.',
nargs='?',
help=('Path to the project that you want wheels for. Default: the current '
'directory.'))
args = parser.parse_args()
if args.platform != 'auto':
platform = args.platform
else:
if os.environ.get('TRAVIS_OS_NAME') == 'linux':
platform = 'linux'
elif os.environ.get('TRAVIS_OS_NAME') == 'osx':
platform = 'macos'
elif 'APPVEYOR' in os.environ:
platform = 'windows'
else:
2017-06-27 18:18:20 +01:00
print('cibuildwheel: Unable to detect platform. cibuildwheel should run on your CI server, '
'Travis CI and Appveyor are supported. You can run on your development '
'machine using the --platform argument. Check --help output for more '
'information.',
file=sys.stderr)
exit(2)
2017-03-19 20:57:51 +00:00
output_dir = args.output_dir
test_command = os.environ.get('CIBW_TEST_COMMAND', None)
test_requires = os.environ.get('CIBW_TEST_REQUIRES', '').split()
project_dir = args.project_dir
before_build = get_option_from_environment('CIBW_BEFORE_BUILD', platform=platform)
2017-04-11 22:57:42 +01:00
skip_config = os.environ.get('CIBW_SKIP', '')
skip = BuildSkipper(skip_config)
2017-03-19 20:57:51 +00:00
try:
project_setup_py = os.path.join(project_dir, 'setup.py')
2017-07-02 17:11:15 -05:00
name_output = subprocess.check_output([sys.executable, project_setup_py, '--name'],
universal_newlines=True)
2017-04-13 14:22:27 +01:00
# the last line of output is the name
package_name = name_output.strip().splitlines()[-1]
2017-03-19 20:57:51 +00:00
except subprocess.CalledProcessError as err:
if not os.path.exists(project_setup_py):
print('cibuildwheel: Could not find setup.py at root of project', file=sys.stderr)
exit(2)
else:
print('cibuildwheel: Failed to get name of the package. Command was %s' % err.cmd,
file=sys.stderr)
exit(2)
if package_name == '' or package_name == 'UNKNOWN':
2017-03-19 21:27:29 +00:00
print('cibuildwheel: Invalid package name "%s". Check your setup.py' % package_name,
2017-03-19 20:57:51 +00:00
file=sys.stderr)
exit(2)
2017-04-13 15:02:04 +01:00
build_options = dict(
2017-03-19 20:57:51 +00:00
project_dir=project_dir,
package_name=package_name,
output_dir=output_dir,
test_command=test_command,
test_requires=test_requires,
before_build=before_build,
2017-04-11 22:57:42 +01:00
skip=skip,
2017-03-19 20:57:51 +00:00
)
2017-04-13 15:02:04 +01:00
print_preamble(platform, build_options)
2017-07-02 18:02:27 -05:00
if not os.path.exists(output_dir):
os.mkdir(output_dir)
2017-03-19 20:57:51 +00:00
if platform == 'linux':
2017-04-13 15:02:04 +01:00
cibuildwheel.linux.build(**build_options)
2017-03-19 20:57:51 +00:00
elif platform == 'windows':
2017-04-13 15:02:04 +01:00
cibuildwheel.windows.build(**build_options)
2017-03-19 20:57:51 +00:00
elif platform == 'macos':
2017-04-13 15:02:04 +01:00
cibuildwheel.macos.build(**build_options)
2017-03-19 20:57:51 +00:00
else:
2017-03-19 21:27:29 +00:00
raise Exception('Unsupported platform')
2017-03-19 20:57:51 +00:00
2017-04-13 15:02:04 +01:00
def print_preamble(platform, build_options):
print(textwrap.dedent('''
_ _ _ _ _ _ _
___|_| |_ _ _|_| |_| |_ _ _| |_ ___ ___| |
| _| | . | | | | | . | | | | | -_| -_| |
|___|_|___|___|_|_|___|_____|_|_|___|___|_|
'''))
print('cibuildwheel version %s\n' % cibuildwheel.__version__)
print('Build options:')
print(' platform: %r' % platform)
for option, value in build_options.items():
print(' %s: %r' % (option, value))
print('\nHere we go!\n')
2017-03-19 20:57:51 +00:00
if __name__ == '__main__':
main()