From e6391b286815efdfea7d0e9a770c1da97acf5014 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment?= Date: Sun, 12 May 2024 19:04:14 +0200 Subject: [PATCH 1/3] python312Packages.http-parser: fix build for python3.12 (use of deprecated module) --- .../python-modules/http-parser/default.nix | 5 +++ .../http-parser/imp-importlib.diff | 31 +++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 pkgs/development/python-modules/http-parser/imp-importlib.diff diff --git a/pkgs/development/python-modules/http-parser/default.nix b/pkgs/development/python-modules/http-parser/default.nix index 05cd4397dbf9..57710e6743b0 100644 --- a/pkgs/development/python-modules/http-parser/default.nix +++ b/pkgs/development/python-modules/http-parser/default.nix @@ -32,6 +32,11 @@ buildPythonPackage rec { "http_parser" ]; + # The imp module is deprecated since version 3.4, and was removed in 3.12 + # https://docs.python.org/3.11/library/imp.html + # Fix from: https://github.com/benoitc/http-parser/pull/101/ + patches = [ ./imp-importlib.diff ]; + nativeCheckInputs = [ pytestCheckHook ]; diff --git a/pkgs/development/python-modules/http-parser/imp-importlib.diff b/pkgs/development/python-modules/http-parser/imp-importlib.diff new file mode 100644 index 000000000000..e8b166a9c099 --- /dev/null +++ b/pkgs/development/python-modules/http-parser/imp-importlib.diff @@ -0,0 +1,31 @@ +diff --git a/setup.py b/setup.py +index 5c3f768..04de1d0 100644 +--- a/setup.py ++++ b/setup.py +@@ -9,7 +9,8 @@ from distutils.errors import CCompilerError, DistutilsExecError, \ + from distutils.command.build_ext import build_ext + from distutils.command.sdist import sdist as _sdist + import glob +-from imp import load_source ++import importlib.machinery ++import importlib.util + import io + import os + import shutil +@@ -28,6 +29,16 @@ if sys.platform == 'win32' and sys.version_info > (2, 6): + # find the compiler + ext_errors += (IOError,) + ++ ++def load_source(modname, filename): ++ loader = importlib.machinery.SourceFileLoader(modname, filename) ++ spec = importlib.util.spec_from_file_location( ++ modname, filename, loader=loader) ++ module = importlib.util.module_from_spec(spec) ++ loader.exec_module(module) ++ return module ++ ++ + http_parser = load_source("http_parser", os.path.join("http_parser", + "__init__.py")) + From bd53c79a73c3b1103e0f013a1ef6067d44065392 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment?= Date: Sun, 12 May 2024 19:25:13 +0200 Subject: [PATCH 2/3] python312Packages.http-parser: format file with `nixfmt-rfc-style` --- .../python-modules/http-parser/default.nix | 27 +++++++++---------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/pkgs/development/python-modules/http-parser/default.nix b/pkgs/development/python-modules/http-parser/default.nix index 57710e6743b0..2ffc08beb200 100644 --- a/pkgs/development/python-modules/http-parser/default.nix +++ b/pkgs/development/python-modules/http-parser/default.nix @@ -1,9 +1,10 @@ -{ lib -, buildPythonPackage -, fetchFromGitHub -, cython -, setuptools -, pytestCheckHook +{ + lib, + buildPythonPackage, + fetchFromGitHub, + cython, + setuptools, + pytestCheckHook, }: buildPythonPackage rec { @@ -28,23 +29,19 @@ buildPythonPackage rec { make -B ''; - pythonImportsCheck = [ - "http_parser" - ]; + pythonImportsCheck = [ "http_parser" ]; # The imp module is deprecated since version 3.4, and was removed in 3.12 # https://docs.python.org/3.11/library/imp.html # Fix from: https://github.com/benoitc/http-parser/pull/101/ patches = [ ./imp-importlib.diff ]; - nativeCheckInputs = [ - pytestCheckHook - ]; + nativeCheckInputs = [ pytestCheckHook ]; - meta = with lib; { + meta = { description = "HTTP request/response parser for python in C"; homepage = "https://github.com/benoitc/http-parser"; - license = licenses.mit; - maintainers = with maintainers; [ ]; + license = lib.licenses.mit; + maintainers = [ ]; }; } From ed0e7323a8d517b080862037fd7aa379475f8728 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment?= Date: Sun, 12 May 2024 21:43:45 +0200 Subject: [PATCH 3/3] python312Packages.http-parser: use fetchpatch Co-authored-by: annaleeleaves <168274788+annaleeleaves@users.noreply.github.com> --- .../python-modules/http-parser/default.nix | 8 ++++- .../http-parser/imp-importlib.diff | 31 ------------------- 2 files changed, 7 insertions(+), 32 deletions(-) delete mode 100644 pkgs/development/python-modules/http-parser/imp-importlib.diff diff --git a/pkgs/development/python-modules/http-parser/default.nix b/pkgs/development/python-modules/http-parser/default.nix index 2ffc08beb200..7e53465939f2 100644 --- a/pkgs/development/python-modules/http-parser/default.nix +++ b/pkgs/development/python-modules/http-parser/default.nix @@ -5,6 +5,7 @@ cython, setuptools, pytestCheckHook, + fetchpatch, }: buildPythonPackage rec { @@ -34,7 +35,12 @@ buildPythonPackage rec { # The imp module is deprecated since version 3.4, and was removed in 3.12 # https://docs.python.org/3.11/library/imp.html # Fix from: https://github.com/benoitc/http-parser/pull/101/ - patches = [ ./imp-importlib.diff ]; + patches = [ + (fetchpatch { + url = "https://github.com/benoitc/http-parser/commit/4d4984ce129253f9de475bfd3c683301c916e8b1.patch"; + hash = "sha256-d3k1X41/D9PpPWsDety2AiYyLv9LJIhpkOo3a6qKcB8="; + }) + ]; nativeCheckInputs = [ pytestCheckHook ]; diff --git a/pkgs/development/python-modules/http-parser/imp-importlib.diff b/pkgs/development/python-modules/http-parser/imp-importlib.diff deleted file mode 100644 index e8b166a9c099..000000000000 --- a/pkgs/development/python-modules/http-parser/imp-importlib.diff +++ /dev/null @@ -1,31 +0,0 @@ -diff --git a/setup.py b/setup.py -index 5c3f768..04de1d0 100644 ---- a/setup.py -+++ b/setup.py -@@ -9,7 +9,8 @@ from distutils.errors import CCompilerError, DistutilsExecError, \ - from distutils.command.build_ext import build_ext - from distutils.command.sdist import sdist as _sdist - import glob --from imp import load_source -+import importlib.machinery -+import importlib.util - import io - import os - import shutil -@@ -28,6 +29,16 @@ if sys.platform == 'win32' and sys.version_info > (2, 6): - # find the compiler - ext_errors += (IOError,) - -+ -+def load_source(modname, filename): -+ loader = importlib.machinery.SourceFileLoader(modname, filename) -+ spec = importlib.util.spec_from_file_location( -+ modname, filename, loader=loader) -+ module = importlib.util.module_from_spec(spec) -+ loader.exec_module(module) -+ return module -+ -+ - http_parser = load_source("http_parser", os.path.join("http_parser", - "__init__.py")) -