diff --git a/appveyor.yml b/appveyor.yml index f7f7e3b9..b3eaebc5 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -14,7 +14,7 @@ build: off init: - cmd: set PATH=C:\Python37;C:\Python37\Scripts;%PATH% -install: python -m pip install -r requirements-dev.txt +install: python -m pip install --retries 3 -r requirements-dev.txt # the '-u' flag is required so the output is in the correct order. # See https://github.com/joerick/cibuildwheel/pull/24 for more info. diff --git a/bin/make_dependency_update_pr.py b/bin/make_dependency_update_pr.py new file mode 100755 index 00000000..adfb21e0 --- /dev/null +++ b/bin/make_dependency_update_pr.py @@ -0,0 +1,75 @@ +#!/usr/bin/env python3 + +import os +import time +from pathlib import Path +from subprocess import run + +import click +import textwrap + + +def shell(cmd, **kwargs): + return run([cmd], shell=True, **kwargs) + + +def git_repo_has_changes(): + unstaged_changes = shell('git diff-index --quiet HEAD --').returncode != 0 + staged_changes = shell('git diff-index --quiet --cached HEAD --').returncode != 0 + return unstaged_changes or staged_changes + + +@click.command() +def main(): + project_root = Path(__file__).parent / '..' + os.chdir(project_root) + + if git_repo_has_changes(): + print('Your git repo has uncommitted changes. Commit or stash before continuing.') + exit(1) + + previous_branch = shell('git rev-parse --abbrev-ref HEAD', + check=True, + capture_output=True, + encoding='utf8').stdout.strip() + + shell('git fetch origin', check=True) + + timestamp = time.strftime('%Y-%m-%dT%H-%M-%S', time.gmtime()) + branch_name = f'update-constraints-{timestamp}' + + shell(f'git checkout -b {branch_name} origin/master', check=True) + + try: + shell('bin/update_dependencies.py', check=True) + + if not git_repo_has_changes(): + print('Done: no constraint updates required.') + return + + shell('git commit -a -m "Update dependencies"', check=True) + run( + [ + 'gh', 'pr', 'create', + '--repo', 'joerick/cibuildwheel', + '--base', 'master', + '--title', 'Update dependencies', + '--body', textwrap.dedent(f''' + Update the versions of our dependencies. + + PR generated by `{os.path.basename(__file__)}`. + ''') + ], + check=True + ) + + print('Done.') + finally: + # remove any local changes + shell('git checkout -- .') + shell(f'git checkout {previous_branch}', check=True) + shell(f'git branch -D --force {branch_name}', check=True) + + +if __name__ == '__main__': + main.main(standalone_mode=True) diff --git a/bin/update_constraints.py b/bin/update_dependencies.py similarity index 96% rename from bin/update_constraints.py rename to bin/update_dependencies.py index 50aaf515..ff7d511c 100755 --- a/bin/update_constraints.py +++ b/bin/update_dependencies.py @@ -84,7 +84,9 @@ for image in images: digest = latest_tag['images'][0]['digest'] pinned_tag = next( - tag for tag in tags if tag['images'][0]['digest'] == digest + tag + for tag in tags + if tag != latest_tag and tag['images'][0]['digest'] == digest ) tag_name = pinned_tag['name'] diff --git a/cibuildwheel/macos.py b/cibuildwheel/macos.py index 2fbd4c55..b62b1e83 100644 --- a/cibuildwheel/macos.py +++ b/cibuildwheel/macos.py @@ -108,52 +108,38 @@ def install_pypy(version, url): return installation_bin_path -def build(project_dir, output_dir, test_command, before_test, test_requires, test_extras, before_build, build_verbosity, build_selector, repair_command, environment, dependency_constraints): - abs_project_dir = os.path.abspath(project_dir) - temp_dir = tempfile.mkdtemp(prefix='cibuildwheel') - built_wheel_dir = os.path.join(temp_dir, 'built_wheel') - repaired_wheel_dir = os.path.join(temp_dir, 'repaired_wheel') +def setup_python(python_configuration, dependency_constraint_flags, environment): + if python_configuration.identifier.startswith('cp'): + installation_bin_path = install_cpython(python_configuration.version, python_configuration.url) + elif python_configuration.identifier.startswith('pp'): + installation_bin_path = install_pypy(python_configuration.version, python_configuration.url) + else: + raise ValueError("Unknown Python implementation") + + env = os.environ.copy() + env['PATH'] = os.pathsep.join([ + SYMLINKS_DIR, + installation_bin_path, + env['PATH'], + ]) - python_configurations = get_python_configurations(build_selector) - - for config in python_configurations: - if config.identifier.startswith('cp'): - installation_bin_path = install_cpython(config.version, config.url) - elif config.identifier.startswith('pp'): - installation_bin_path = install_pypy(config.version, config.url) - else: - raise ValueError("Unknown Python implementation") - - env = os.environ.copy() - env['PATH'] = os.pathsep.join([ - SYMLINKS_DIR, - installation_bin_path, - env['PATH'], - ]) - - # Fix issue with site.py setting the wrong `sys.prefix`, `sys.exec_prefix`, - # `sys.path`, ... for PyPy: https://foss.heptapod.net/pypy/pypy/issues/3175 - # Also fix an issue with the shebang of installed scripts inside the - # testing virtualenv- see https://github.com/theacodes/nox/issues/44 and - # https://github.com/pypa/virtualenv/issues/620 - # Also see https://github.com/python/cpython/pull/9516 - env.pop('__PYVENV_LAUNCHER__', None) - env = environment.as_dictionary(prev_environment=env) - - # check what version we're on - call(['which', 'python'], env=env) - call(['python', '--version'], env=env) - which_python = subprocess.check_output(['which', 'python'], env=env, universal_newlines=True).strip() - if which_python != '/tmp/cibw_bin/python': - print("cibuildwheel: python available on PATH doesn't match our installed instance. If you have modified PATH, ensure that you don't overwrite cibuildwheel's entry or insert python above it.", file=sys.stderr) - exit(1) - - dependency_constraint_flags = [] - if dependency_constraints: - dependency_constraint_flags = [ - '-c', dependency_constraints.get_for_python_version(config.version) - ] + # Fix issue with site.py setting the wrong `sys.prefix`, `sys.exec_prefix`, + # `sys.path`, ... for PyPy: https://foss.heptapod.net/pypy/pypy/issues/3175 + # Also fix an issue with the shebang of installed scripts inside the + # testing virtualenv- see https://github.com/theacodes/nox/issues/44 and + # https://github.com/pypa/virtualenv/issues/620 + # Also see https://github.com/python/cpython/pull/9516 + env.pop('__PYVENV_LAUNCHER__', None) + env = environment.as_dictionary(prev_environment=env) + # check what version we're on + call(['which', 'python'], env=env) + call(['python', '--version'], env=env) + which_python = subprocess.check_output(['which', 'python'], env=env, universal_newlines=True).strip() + if which_python != '/tmp/cibw_bin/python': + print("cibuildwheel: python available on PATH doesn't match our installed instance. If you have modified PATH, ensure that you don't overwrite cibuildwheel's entry or insert python above it.", file=sys.stderr) + exit(1) + # install pip & wheel call(['python', get_pip_script] + dependency_constraint_flags, env=env, cwd="/tmp") assert os.path.exists(os.path.join(installation_bin_path, 'pip')) @@ -165,18 +151,40 @@ def build(project_dir, output_dir, test_command, before_test, test_requires, tes exit(1) call(['pip', 'install', '--upgrade', 'setuptools', 'wheel', 'delocate'] + dependency_constraint_flags, env=env) - # Set MACOSX_DEPLOYMENT_TARGET to 10.9, if the user didn't set it. - # CPython 3.5 defaults to 10.6, and pypy defaults to 10.3, causing - # warnings and potential problems if it's left unset. - env.setdefault('MACOSX_DEPLOYMENT_TARGET', '10.9') - - if config.version == '3.5': - # Cross-compilation platform override - CPython 3.5 has an - # i386/x86_64 version of Python, but we only want a x64_64 build - env.setdefault('_PYTHON_HOST_PLATFORM', 'macosx-10.9-x86_64') +# Set MACOSX_DEPLOYMENT_TARGET to 10.9, if the user didn't set it. +# CPython 3.5 defaults to 10.6, and pypy defaults to 10.3, causing +# warnings and potential problems if it's left unset. +env.setdefault('MACOSX_DEPLOYMENT_TARGET', '10.9') + + if config.version == '3.5': + # Cross-compilation platform override - CPython 3.5 has an + # i386/x86_64 version of Python, but we only want a x64_64 build + env.setdefault('_PYTHON_HOST_PLATFORM', 'macosx-10.9-x86_64') # https://github.com/python/cpython/blob/a5ed2fe0eedefa1649aa93ee74a0bafc8e628a10/Lib/_osx_support.py#L260 env.setdefault('ARCHFLAGS', '-arch x86_64') + return env + + +def build(project_dir, output_dir, test_command, before_test, test_requires, test_extras, before_build, build_verbosity, build_selector, repair_command, environment, dependency_constraints): + abs_project_dir = os.path.abspath(project_dir) + temp_dir = tempfile.mkdtemp(prefix='cibuildwheel') + built_wheel_dir = os.path.join(temp_dir, 'built_wheel') + repaired_wheel_dir = os.path.join(temp_dir, 'repaired_wheel') + + python_configurations = get_python_configurations(build_selector) + + for config in python_configurations: + + dependency_constraint_flags = [] + if dependency_constraints: + dependency_constraint_flags = [ + '-c', dependency_constraints.get_for_python_version(config.version) + ] + + env = setup_python(config, dependency_constraint_flags, environment) + + # run the before_build command if before_build: before_build_prepared = prepare_command(before_build, project=abs_project_dir) diff --git a/cibuildwheel/windows.py b/cibuildwheel/windows.py index 4aadd6d2..11cc33f1 100644 --- a/cibuildwheel/windows.py +++ b/cibuildwheel/windows.py @@ -89,6 +89,58 @@ def install_pypy(version, arch, url): return installation_path +def setup_python(python_configuration, dependency_constraint_flags, environment): + nuget = 'C:\\cibw\\nuget.exe' + if not os.path.exists(nuget): + download('https://dist.nuget.org/win-x86-commandline/latest/nuget.exe', nuget) + + if python_configuration.identifier.startswith('cp'): + installation_path = install_cpython(python_configuration.version, python_configuration.arch, nuget) + elif python_configuration.identifier.startswith('pp'): + installation_path = install_pypy(python_configuration.version, python_configuration.arch, python_configuration.url) + else: + raise ValueError("Unknown Python implementation") + + assert os.path.exists(os.path.join(installation_path, 'python.exe')) + + # set up PATH and environment variables for run_with_env + env = os.environ.copy() + env['PYTHON_VERSION'] = python_configuration.version + env['PYTHON_ARCH'] = python_configuration.arch + env['PATH'] = os.pathsep.join([ + installation_path, + os.path.join(installation_path, 'Scripts'), + env['PATH'] + ]) + # update env with results from CIBW_ENVIRONMENT + env = environment.as_dictionary(prev_environment=env) + + # for the logs - check we're running the right version of python + shell(['where', 'python'], env=env) + shell(['python', '--version'], env=env) + shell(['python', '-c', '"import struct; print(struct.calcsize(\'P\') * 8)"'], env=env) + where_python = subprocess.check_output(['where', 'python'], env=env, universal_newlines=True).splitlines()[0].strip() + if where_python != os.path.join(installation_path, 'python.exe'): + print("cibuildwheel: python available on PATH doesn't match our installed instance. If you have modified PATH, ensure that you don't overwrite cibuildwheel's entry or insert python above it.", file=sys.stderr) + exit(1) + + # make sure pip is installed + if not os.path.exists(os.path.join(installation_path, 'Scripts', 'pip.exe')): + shell(['python', get_pip_script] + dependency_constraint_flags, env=env, cwd="C:\\cibw") + assert os.path.exists(os.path.join(installation_path, 'Scripts', 'pip.exe')) + where_pip = subprocess.check_output(['where', 'pip'], env=env, universal_newlines=True).splitlines()[0].strip() + if where_pip.strip() != os.path.join(installation_path, 'Scripts', 'pip.exe'): + print("cibuildwheel: pip available on PATH doesn't match our installed instance. If you have modified PATH, ensure that you don't overwrite cibuildwheel's entry or insert pip above it.", file=sys.stderr) + exit(1) + + # prepare the Python environment + shell(['python', '-m', 'pip', 'install', '--upgrade', 'pip'] + dependency_constraint_flags, env=env) + shell(['pip', '--version'], env=env) + shell(['pip', 'install', '--upgrade', 'setuptools', 'wheel'] + dependency_constraint_flags, env=env) + + return env + + def build(project_dir, output_dir, test_command, before_test, test_requires, test_extras, before_build, build_verbosity, build_selector, repair_command, environment, dependency_constraints): abs_project_dir = os.path.abspath(project_dir) temp_dir = tempfile.mkdtemp(prefix='cibuildwheel') @@ -101,56 +153,14 @@ def build(project_dir, output_dir, test_command, before_test, test_requires, tes python_configurations = get_python_configurations(build_selector) for config in python_configurations: - # install Python - if config.identifier.startswith('cp'): - installation_path = install_cpython(config.version, config.arch, nuget) - elif config.identifier.startswith('pp'): - installation_path = install_pypy(config.version, config.arch, config.url) - else: - raise ValueError("Unknown Python implementation") - - assert os.path.exists(os.path.join(installation_path, 'python.exe')) - - # set up PATH and environment variables for run_with_env - env = os.environ.copy() - env['PYTHON_VERSION'] = config.version - env['PYTHON_ARCH'] = config.arch - env['PATH'] = os.pathsep.join([ - installation_path, - os.path.join(installation_path, 'Scripts'), - env['PATH'] - ]) - # update env with results from CIBW_ENVIRONMENT - env = environment.as_dictionary(prev_environment=env) - - # for the logs - check we're running the right version of python - shell(['where', 'python'], env=env) - shell(['python', '--version'], env=env) - shell(['python', '-c', '"import struct; print(struct.calcsize(\'P\') * 8)"'], env=env) - where_python = subprocess.check_output(['where', 'python'], env=env, universal_newlines=True).splitlines()[0].strip() - if where_python != os.path.join(installation_path, 'python.exe'): - print("cibuildwheel: python available on PATH doesn't match our installed instance. If you have modified PATH, ensure that you don't overwrite cibuildwheel's entry or insert python above it.", file=sys.stderr) - exit(1) - dependency_constraint_flags = [] if dependency_constraints: dependency_constraint_flags = [ '-c', dependency_constraints.get_for_python_version(config.version) ] - # make sure pip is installed - if not os.path.exists(os.path.join(installation_path, 'Scripts', 'pip.exe')): - shell(['python', get_pip_script] + dependency_constraint_flags, env=env, cwd="C:\\cibw") - assert os.path.exists(os.path.join(installation_path, 'Scripts', 'pip.exe')) - where_pip = subprocess.check_output(['where', 'pip'], env=env, universal_newlines=True).splitlines()[0].strip() - if where_pip.strip() != os.path.join(installation_path, 'Scripts', 'pip.exe'): - print("cibuildwheel: pip available on PATH doesn't match our installed instance. If you have modified PATH, ensure that you don't overwrite cibuildwheel's entry or insert pip above it.", file=sys.stderr) - exit(1) - - # prepare the Python environment - shell(['python', '-m', 'pip', 'install', '--upgrade', 'pip'] + dependency_constraint_flags, env=env) - shell(['pip', '--version'], env=env) - shell(['pip', 'install', '--upgrade', 'setuptools', 'wheel'] + dependency_constraint_flags, env=env) + # install Python + env = setup_python(config, dependency_constraint_flags, environment) # run the before_build command if before_build: diff --git a/requirements-dev.txt b/requirements-dev.txt index df361eba..f838e3f2 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -4,3 +4,4 @@ pytest mkdocs==1.0.4 pip-tools requests +click diff --git a/setup.cfg b/setup.cfg index b2c53158..c5d51ac7 100644 --- a/setup.cfg +++ b/setup.cfg @@ -8,5 +8,6 @@ exclude = .git/, env/, env2/, + env??/, .venv/, site/ diff --git a/test/shared/utils.py b/test/shared/utils.py index fe7937ff..0b463334 100644 --- a/test/shared/utils.py +++ b/test/shared/utils.py @@ -81,59 +81,60 @@ def expected_wheels(package_name, package_version, manylinux_versions=None, # {python tag} and {abi tag} are closely related to the python interpreter used to build the wheel # so we'll merge them below as python_abi_tag - python_abi_tags = ['cp35-cp35m', 'cp36-cp36m', 'cp37-cp37m', 'cp38-cp38'] - extra_x86_python_abi_tags = ['cp27-cp27m', 'pp27-pypy_73', 'pp36-pypy36_pp73'] - - if platform == 'linux': - if pm.machine() not in ['x86_64', 'i686']: - if manylinux_versions is None: - manylinux_versions = ['manylinux2014'] - architectures = {'cp': [pm.machine()]} + if manylinux_versions is None: + if pm.machine() == 'x86_64': + manylinux_versions = ['manylinux1', 'manylinux2010'] else: - if manylinux_versions is None: - manylinux_versions = ['manylinux1', 'manylinux2010'] - python_abi_tags += extra_x86_python_abi_tags + manylinux_versions = ['manylinux2014'] + + python_abi_tags = ['cp35-cp35m', 'cp36-cp36m', 'cp37-cp37m', 'cp38-cp38'] + + if pm.machine() in ['x86_64', 'AMD64', 'x86']: + python_abi_tags += ['cp27-cp27m', 'pp27-pypy_73', 'pp36-pypy36_pp73'] + + if platform == 'linux': python_abi_tags.append('cp27-cp27mu') # python 2.7 has 2 different ABI on manylinux - architectures = {'cp': ['x86_64', 'i686'], 'pp': ['x86_64']} - platform_tags = {} - for python_implemention in architectures: - platform_tags[python_implemention] = [ - '{manylinux_version}_{architecture}'.format( - manylinux_version=manylinux_version, architecture=architecture) - for architecture in architectures[python_implemention] + + wheels = [] + + for python_abi_tag in python_abi_tags: + platform_tags = [] + + if platform == 'linux': + architectures = [pm.machine()] + + if pm.machine() == 'x86_64' and python_abi_tag.startswith('cp'): + architectures.append('i686') + + platform_tags = [ + '{}_{}'.format(manylinux_version, architecture) + for architecture in architectures for manylinux_version in manylinux_versions ] - def get_platform_tags(python_abi_tag): - return platform_tags[python_abi_tag[:2]] - elif platform == 'windows': - python_abi_tags += extra_x86_python_abi_tags - platform_tags = {'cp': ['win32', 'win_amd64'], 'pp': ['win32']} + elif platform == 'windows': + if python_abi_tag.startswith('cp'): + platform_tags = ['win32', 'win_amd64'] + else: + platform_tags = ['win32'] - def get_platform_tags(python_abi_tag): - return platform_tags[python_abi_tag[:2]] + elif platform == 'macos': + platform_tags = ['macosx_{}_x86_64'.format(macosx_deployment_target.replace('.', '_'))] - elif platform == 'macos': - python_abi_tags += extra_x86_python_abi_tags + else: + raise Exception('unsupported platform') - def get_platform_tags(python_abi_tag): - return ['macosx_{}_x86_64'.format(macosx_deployment_target.replace('.', '_'))] - else: - raise Exception('unsupported platform') - - templates = [] - for python_abi_tag in python_abi_tags: - for platform_tag in get_platform_tags(python_abi_tag): - templates.append('{package_name}-{package_version}-{python_abi_tag}-{platform_tag}.whl'.format( + for platform_tag in platform_tags: + wheels.append('{package_name}-{package_version}-{python_abi_tag}-{platform_tag}.whl'.format( package_name=package_name, package_version=package_version, python_abi_tag=python_abi_tag, platform_tag=platform_tag )) if IS_WINDOWS_RUNNING_ON_TRAVIS: # Python 2.7 isn't supported on Travis. - templates = [t for t in templates if '-cp27-' not in t and '-pp2' not in t] + wheels = [w for w in wheels if '-cp27-' not in w and '-pp2' not in w] - return templates + return wheels platform = None