diff --git a/CHANGES/3828.feature b/CHANGES/3828.feature new file mode 100644 index 00000000000..7d31a2bb243 --- /dev/null +++ b/CHANGES/3828.feature @@ -0,0 +1,4 @@ +Disable implicit switch-back to pure python mode. The build fails loudly if aiohttp +cannot be compiled with C Accellerators. Use AIOHTTP_NO_EXTENSIONS=1 to explicitly +disable C Extensions complication and switch to Pure-Python mode. Note that Pure-Python +mode is significantly slower than compiled one. diff --git a/setup.py b/setup.py index 3b45c5db1c9..ea48b2c426a 100644 --- a/setup.py +++ b/setup.py @@ -1,16 +1,23 @@ +import os import pathlib import sys -from distutils.command.build_ext import build_ext -from distutils.errors import CCompilerError, DistutilsExecError, DistutilsPlatformError from setuptools import Extension, setup if sys.version_info < (3, 6): - raise RuntimeError("aiohttp 3.7+ requires Python 3.6+") + raise RuntimeError("aiohttp 3.x requires Python 3.6+") + +NO_EXTENSIONS = bool(os.environ.get("AIOHTTP_NO_EXTENSIONS")) # type: bool HERE = pathlib.Path(__file__).parent +IS_GIT_REPO = (HERE / ".git").exists() + + +if sys.implementation.name != "cpython": + NO_EXTENSIONS = True -if (HERE / ".git").exists() and not (HERE / "vendor/http-parser/README.md").exists(): + +if IS_GIT_REPO and not (HERE / "vendor/http-parser/README.md").exists(): print("Install submodules when building from git clone", file=sys.stderr) print("Hint:", file=sys.stderr) print(" git submodule update --init", file=sys.stderr) @@ -35,33 +42,10 @@ ] -class BuildFailed(Exception): - pass - - -class ve_build_ext(build_ext): - # This class allows C extension building to fail. - - def run(self): - try: - build_ext.run(self) - except (DistutilsPlatformError, FileNotFoundError): - raise BuildFailed() - - def build_extension(self, ext): - try: - build_ext.build_extension(self, ext) - except (CCompilerError, DistutilsExecError, DistutilsPlatformError, ValueError): - raise BuildFailed() - +build_type = "Pure" if NO_EXTENSIONS else "Accelerated" +setup_kwargs = {} if NO_EXTENSIONS else {"ext_modules": extensions} -try: - setup( - ext_modules=extensions, - cmdclass=dict(build_ext=ve_build_ext), - ) -except BuildFailed: - print("************************************************************") - print("Cannot compile C accelerator module, use pure python version") - print("************************************************************") - setup() +print("*********************", file=sys.stderr) +print("* {build_type} build *".format_map(locals()), file=sys.stderr) +print("*********************", file=sys.stderr) +setup(**setup_kwargs)