From 0597088f64b7ac51940986c12c04127143a1ddfb Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Fri, 29 May 2020 17:24:01 -0400 Subject: [PATCH 1/3] 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) From 901ac79dbcd3b96d44a92f6a64a11c961ffec632 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Sun, 14 Jun 2020 11:25:14 -0400 Subject: [PATCH 2/3] review: Address review suggestion --- cibuildwheel/windows.py | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/cibuildwheel/windows.py b/cibuildwheel/windows.py index db0a063c..6a62b63d 100644 --- a/cibuildwheel/windows.py +++ b/cibuildwheel/windows.py @@ -149,25 +149,32 @@ 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') + return env + + +def pep_518_cp35_workaround(package_dir: str, env: Dict[str, str]) -> None: + """ + 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". + """ + + pyproject_path = os.path.join(package_dir, 'pyproject.toml') + + if os.path.exists(pyproject_path): + data = toml.load(pyproject_path) 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 + shell(['pip', 'install'] + requirements, env=env) def build(options: BuildOptions) -> None: @@ -195,6 +202,11 @@ def build(options: BuildOptions) -> None: before_build_prepared = prepare_command(options.before_build, project='.', package=options.package_dir) shell([before_build_prepared], env=env) + # activate the PEP 518 patch if on Windows Python 3.5 + # (will only have an effect if PEP 517 builds are used): + if config.version.startswith('3.5'): + pep_518_cp35_workaround(options.package_dir, env) + # build the wheel if os.path.exists(built_wheel_dir): shutil.rmtree(built_wheel_dir) From e6ac5274160279826b301a14514d3270fc575592 Mon Sep 17 00:00:00 2001 From: Joe Rickerby Date: Mon, 22 Jun 2020 12:08:40 +0100 Subject: [PATCH 3/3] Convert the workaround to use Path objects --- cibuildwheel/windows.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cibuildwheel/windows.py b/cibuildwheel/windows.py index 63b22b48..f8a50015 100644 --- a/cibuildwheel/windows.py +++ b/cibuildwheel/windows.py @@ -154,7 +154,7 @@ def setup_python(python_configuration: PythonConfiguration, dependency_constrain return env -def pep_518_cp35_workaround(package_dir: str, env: Dict[str, str]) -> None: +def pep_518_cp35_workaround(package_dir: Path, env: Dict[str, str]) -> None: """ 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. @@ -166,9 +166,9 @@ def pep_518_cp35_workaround(package_dir: str, env: Dict[str, str]) -> None: mostly "isolated". """ - pyproject_path = os.path.join(package_dir, 'pyproject.toml') + pyproject_path = package_dir / 'pyproject.toml' - if os.path.exists(pyproject_path): + if pyproject_path.exists(): data = toml.load(pyproject_path) requirements = ( data['build-system'].get('requires', [])