From 0597088f64b7ac51940986c12c04127143a1ddfb Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Fri, 29 May 2020 17:24:01 -0400 Subject: [PATCH] Adding PEP 518 test --- cibuildwheel/windows.py | 19 ++++++++++++++++++ setup.py | 2 +- test/test_pep518.py | 44 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 test/test_pep518.py diff --git a/cibuildwheel/windows.py b/cibuildwheel/windows.py index 9f33ad91..db0a063c 100644 --- a/cibuildwheel/windows.py +++ b/cibuildwheel/windows.py @@ -5,6 +5,7 @@ import sys import tempfile from glob import glob from zipfile import ZipFile +import toml from typing import Dict, List, Optional, NamedTuple @@ -148,6 +149,24 @@ def setup_python(python_configuration: PythonConfiguration, dependency_constrain shell(['pip', '--version'], env=env) shell(['pip', 'install', '--upgrade', 'setuptools', 'wheel'] + dependency_constraint_flags, env=env) + # Python 3.5 PEP 518 hack (see https://github.com/pypa/pip/issues/8392#issuecomment-639563494) + # Basically, nuget's Python is an embedded Python distribution, which is not supported by pip. + # Before version 3.6, there was no way to disable the "embedded" behavior, including the ignoring + # of environment variables, including the ones pip uses to setup PEP 518 builds. + # + # The fix here is as suggested in that issue; we manually setup the PEP 518 requirements. Since we + # are in a fresh environment (except for pinned cibuildweel dependencies), the build is already + # mostly "isolated". + if python_configuration.version.startswith('3.5') and os.path.exists('pyproject.toml'): + data = toml.load('pyproject.toml') + requirements = ( + data['build-system'].get('requires', []) + if 'build-system' in data + else [] + ) + if requirements: + shell(['pip', 'install'] + requirements + dependency_constraint_flags, env=env) + return env diff --git a/setup.py b/setup.py index 3e4c90cb..68dbff3a 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ with io.open(os.path.join(this_directory, 'README.md'), encoding='utf-8') as f: setup( name='cibuildwheel', version='1.4.2', - install_requires=['bashlex!=0.13'], + install_requires=['bashlex!=0.13', 'toml'], description="Build Python wheels on CI with minimal configuration.", long_description=long_description, long_description_content_type='text/markdown', diff --git a/test/test_pep518.py b/test/test_pep518.py new file mode 100644 index 00000000..7d5f5081 --- /dev/null +++ b/test/test_pep518.py @@ -0,0 +1,44 @@ +import textwrap +from . import test_projects +from . import utils + +basic_project = test_projects.new_c_project( + setup_py_add=textwrap.dedent( + """ + # Will fail if PEP 518 does work + import requests + assert requests.__version__ == "2.23.0", "Requests found but wrong version ({0})".format(requests.__version__) + + # Just making sure environment is still set + import os + if os.environ.get("CIBUILDWHEEL", "0") != "1": + raise Exception("CIBUILDWHEEL environment variable is not set to 1") + """ + ) +) + +basic_project.files[ + "pyproject.toml" +] = """ +[build-system] +requires = [ + "setuptools>=42", + "wheel", + "requests==2.23.0" +] + +build-backend = "setuptools.build_meta" +""" + + +def test_pep518(tmp_path): + + project_dir = tmp_path / "project" + basic_project.generate(project_dir) + + # build the wheels + actual_wheels = utils.cibuildwheel_run(project_dir) + + # check that the expected wheels are produced + expected_wheels = utils.expected_wheels("spam", "0.1.0") + assert set(actual_wheels) == set(expected_wheels)