From a5f89fa7aad09c4d8b28c95e2b77d351c3c8e41d Mon Sep 17 00:00:00 2001 From: Yannick Jadoul Date: Sun, 16 Sep 2018 15:16:30 +0200 Subject: [PATCH] Adding CIBW_BUILD option and changing util.BuildSkipper to util.BuildSelector --- cibuildwheel/__main__.py | 8 ++++---- cibuildwheel/linux.py | 4 ++-- cibuildwheel/macos.py | 4 ++-- cibuildwheel/util.py | 13 ++++++++----- cibuildwheel/windows.py | 4 ++-- 5 files changed, 18 insertions(+), 15 deletions(-) diff --git a/cibuildwheel/__main__.py b/cibuildwheel/__main__.py index dc00ce54..2ae108d3 100644 --- a/cibuildwheel/__main__.py +++ b/cibuildwheel/__main__.py @@ -4,7 +4,7 @@ import argparse, os, subprocess, sys, textwrap import cibuildwheel import cibuildwheel.linux, cibuildwheel.windows, cibuildwheel.macos from cibuildwheel.environment import parse_environment, EnvironmentParseError -from cibuildwheel.util import BuildSkipper, Unbuffered +from cibuildwheel.util import BuildSelector, Unbuffered def get_option_from_environment(option_name, platform=None, default=None): ''' @@ -83,7 +83,7 @@ def main(): project_dir = args.project_dir before_build = get_option_from_environment('CIBW_BEFORE_BUILD', platform=platform) build_verbosity = get_option_from_environment('CIBW_BUILD_VERBOSITY', platform=platform, default='') - skip_config = os.environ.get('CIBW_SKIP', '') + build_config, skip_config = os.environ.get('CIBW_BUILD', '*'), os.environ.get('CIBW_SKIP', '') environment_config = get_option_from_environment('CIBW_ENVIRONMENT', platform=platform, default='') try: @@ -99,7 +99,7 @@ def main(): traceback.print_exc(None, sys.stderr) exit(2) - skip = BuildSkipper(skip_config) + selection = BuildSelector(build_config, skip_config) # Add CIBUILDWHEEL environment variable # This needs to be passed on to the docker container in linux.py @@ -134,7 +134,7 @@ def main(): test_requires=test_requires, before_build=before_build, build_verbosity=build_verbosity, - skip=skip, + selection=selection, environment=environment, ) diff --git a/cibuildwheel/linux.py b/cibuildwheel/linux.py index a3eb19f9..400295cc 100644 --- a/cibuildwheel/linux.py +++ b/cibuildwheel/linux.py @@ -9,7 +9,7 @@ except ImportError: from pipes import quote as shlex_quote -def build(project_dir, package_name, output_dir, test_command, test_requires, before_build, build_verbosity, skip, environment, manylinux1_images): +def build(project_dir, package_name, output_dir, test_command, test_requires, before_build, build_verbosity, selection, environment, manylinux1_images): try: subprocess.check_call(['docker', '--version']) except: @@ -36,7 +36,7 @@ def build(project_dir, package_name, output_dir, test_command, test_requires, be ] # skip builds as required - python_configurations = [c for c in python_configurations if not skip(c.identifier)] + python_configurations = [c for c in python_configurations if selection(c.identifier)] platforms = [ ('manylinux1_x86_64', manylinux1_images.get('x86_64') or 'quay.io/pypa/manylinux1_x86_64'), diff --git a/cibuildwheel/macos.py b/cibuildwheel/macos.py index 6ba8dcdb..f45bb1f6 100644 --- a/cibuildwheel/macos.py +++ b/cibuildwheel/macos.py @@ -10,7 +10,7 @@ except ImportError: from .util import prepare_command, get_build_verbosity_extra_flags -def build(project_dir, package_name, output_dir, test_command, test_requires, before_build, build_verbosity, skip, environment): +def build(project_dir, package_name, output_dir, test_command, test_requires, before_build, build_verbosity, selection, environment): PythonConfiguration = namedtuple('PythonConfiguration', ['version', 'identifier', 'url']) python_configurations = [ PythonConfiguration(version='2.7', identifier='cp27-macosx_10_6_intel', url='https://www.python.org/ftp/python/2.7.15/python-2.7.15-macosx10.6.pkg'), @@ -42,7 +42,7 @@ def build(project_dir, package_name, output_dir, test_command, test_requires, be call(['curl', '-L', '-o', get_pip_script, get_pip_url]) for config in python_configurations: - if skip(config.identifier): + if not selection(config.identifier): print('cibuildwheel: Skipping build %s' % config.identifier, file=sys.stderr) continue diff --git a/cibuildwheel/util.py b/cibuildwheel/util.py index 7db3edaa..160e8c20 100644 --- a/cibuildwheel/util.py +++ b/cibuildwheel/util.py @@ -21,15 +21,18 @@ def get_build_verbosity_extra_flags(level): return [] -class BuildSkipper(object): - def __init__(self, skip_config): - self.patterns = skip_config.split() +class BuildSelector(object): + def __init__(self, build_config, skip_config): + self.build_patterns = build_config.split() + self.skip_patterns = skip_config.split() def __call__(self, build_id): - return any(fnmatch(build_id, pattern) for pattern in self.patterns) + def match_any(patterns): + return any(fnmatch(build_id, pattern) for pattern in patterns) + return match_any(self.build_patterns) and not match_any(self.skip_patterns) def __repr__(self): - return 'BuildSkipper(%r)' % ' '.join(self.patterns) + return 'BuildSelector({!r} - {!r})'.format(' '.join(self.build_patterns), ' '.join(self.skip_patterns)) # Taken from https://stackoverflow.com/a/107717 diff --git a/cibuildwheel/windows.py b/cibuildwheel/windows.py index 4118bd33..34dafb0c 100644 --- a/cibuildwheel/windows.py +++ b/cibuildwheel/windows.py @@ -10,7 +10,7 @@ from glob import glob from .util import prepare_command, get_build_verbosity_extra_flags -def build(project_dir, package_name, output_dir, test_command, test_requires, before_build, build_verbosity, skip, environment): +def build(project_dir, package_name, output_dir, test_command, test_requires, before_build, build_verbosity, selection, environment): # run_with_env is a cmd file that sets the right environment variables to run_with_env = os.path.join(tempfile.gettempdir(), 'appveyor_run_with_env.cmd') if not os.path.exists(run_with_env): @@ -45,7 +45,7 @@ def build(project_dir, package_name, output_dir, test_command, test_requires, be built_wheel_dir = os.path.join(temp_dir, 'built_wheel') for config in python_configurations: - if skip(config.identifier): + if not selection(config.identifier): print('cibuildwheel: Skipping build %s' % config.identifier, file=sys.stderr) continue