From 647fc30a10ac43abfe047cb0c312ce24e5b9a6ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=BCtz?= Date: Thu, 20 Jul 2023 11:08:27 -0700 Subject: [PATCH] python310Packages.aiohttp: unvendor llhttp --- .../python-modules/aiohttp/default.nix | 27 +++++++-- .../aiohttp/unvendor-llhttp.patch | 60 +++++++++++++++++++ 2 files changed, 83 insertions(+), 4 deletions(-) create mode 100644 pkgs/development/python-modules/aiohttp/unvendor-llhttp.patch diff --git a/pkgs/development/python-modules/aiohttp/default.nix b/pkgs/development/python-modules/aiohttp/default.nix index a628dc040b5d2..b2722dd4bd4cd 100644 --- a/pkgs/development/python-modules/aiohttp/default.nix +++ b/pkgs/development/python-modules/aiohttp/default.nix @@ -1,10 +1,13 @@ { lib , stdenv , buildPythonPackage -, fetchPypi +, fetchFromGitHub +, substituteAll +, llhttp , fetchpatch , pythonOlder # build_requires +, cython , setuptools # install_requires , attrs @@ -37,12 +40,18 @@ buildPythonPackage rec { disabled = pythonOlder "3.6"; - src = fetchPypi { - inherit pname version; - hash = "sha256-uVUuxSzBR9vxlErHrJivdgLlHqLc0HbtGUyjwNHH0Lw="; + src = fetchFromGitHub { + owner = "aio-libs"; + repo = "aiohttp"; + rev = "refs/tags/v${version}"; + hash = "sha256-rsI26JtlGFjSc2jZqfUiIwtT8AwSd+5tICK+VTxuSGg="; }; patches = [ + (substituteAll { + src = ./unvendor-llhttp.patch; + inherit llhttp; + }) (fetchpatch { # https://github.com/aio-libs/aiohttp/pull/7260 # Merged upstream, should likely be dropped post-3.8.5 @@ -53,12 +62,21 @@ buildPythonPackage rec { postPatch = '' sed -i '/--cov/d' setup.cfg + + rm -r vendor + patchShebangs tools + touch .git # tools/gen.py uses .git to find the project root ''; nativeBuildInputs = [ + cython setuptools ]; + preBuild = '' + make cythonize + ''; + propagatedBuildInputs = [ attrs charset-normalizer @@ -118,6 +136,7 @@ buildPythonPackage rec { # Probably because we run `python -m pytest` instead of `pytest` in the hook. preCheck = '' cd tests + touch data.unknown_mime_type # has to be modified after 1 Jan 1990 '' + lib.optionalString stdenv.isDarwin '' # Work around "OSError: AF_UNIX path too long" export TMPDIR="/tmp" diff --git a/pkgs/development/python-modules/aiohttp/unvendor-llhttp.patch b/pkgs/development/python-modules/aiohttp/unvendor-llhttp.patch new file mode 100644 index 0000000000000..3804d497afd29 --- /dev/null +++ b/pkgs/development/python-modules/aiohttp/unvendor-llhttp.patch @@ -0,0 +1,60 @@ +diff --git a/Makefile b/Makefile +index 5769d2a1..f505dd81 100644 +--- a/Makefile ++++ b/Makefile +@@ -71,7 +71,7 @@ vendor/llhttp/node_modules: vendor/llhttp/package.json + generate-llhttp: .llhttp-gen + + .PHONY: cythonize +-cythonize: .install-cython $(PYXS:.pyx=.c) ++cythonize: $(PYXS:.pyx=.c) + + .install-deps: .install-cython $(PYXS:.pyx=.c) $(call to-hash,$(CYS) $(REQS)) + @python -m pip install -r requirements/dev.txt -c requirements/constraints.txt +diff --git a/aiohttp/_cparser.pxd b/aiohttp/_cparser.pxd +index 165dd61d..bc6bf86d 100644 +--- a/aiohttp/_cparser.pxd ++++ b/aiohttp/_cparser.pxd +@@ -10,7 +10,7 @@ from libc.stdint cimport ( + ) + + +-cdef extern from "../vendor/llhttp/build/llhttp.h": ++cdef extern from "@llhttp@/include/llhttp.h": + + struct llhttp__internal_s: + int32_t _index +diff --git a/setup.py b/setup.py +index 4d59a022..d87d5b69 100644 +--- a/setup.py ++++ b/setup.py +@@ -17,13 +17,6 @@ if sys.implementation.name != "cpython": + NO_EXTENSIONS = True + + +-if IS_GIT_REPO and not (HERE / "vendor/llhttp/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) +- sys.exit(2) +- +- + # NOTE: makefile cythonizes all Cython modules + + extensions = [ +@@ -33,12 +26,11 @@ extensions = [ + [ + "aiohttp/_http_parser.c", + "aiohttp/_find_header.c", +- "vendor/llhttp/build/c/llhttp.c", +- "vendor/llhttp/src/native/api.c", +- "vendor/llhttp/src/native/http.c", + ], + define_macros=[("LLHTTP_STRICT_MODE", 0)], +- include_dirs=["vendor/llhttp/build"], ++ include_dirs=["@llhttp@/include"], ++ library_dirs=["@llhttp@/lib"], ++ libraries=["llhttp"], + ), + Extension("aiohttp._helpers", ["aiohttp/_helpers.c"]), + Extension("aiohttp._http_writer", ["aiohttp/_http_writer.c"]),