From 67712a4e8c5f83ee7d14c0dfe223c0b5b84e7ac7 Mon Sep 17 00:00:00 2001 From: wxt <3264117476@qq.com> Date: Wed, 25 Dec 2024 20:07:58 +0800 Subject: [PATCH] python312Packages.pgpy: fix build --- .../python-modules/pgpy/default.nix | 24 +++++++--- .../python-modules/pgpy/pr-443.patch | 45 +++++++++++++++++++ 2 files changed, 63 insertions(+), 6 deletions(-) create mode 100644 pkgs/development/python-modules/pgpy/pr-443.patch diff --git a/pkgs/development/python-modules/pgpy/default.nix b/pkgs/development/python-modules/pgpy/default.nix index d9366a7542768..09b810b3b46b2 100644 --- a/pkgs/development/python-modules/pgpy/default.nix +++ b/pkgs/development/python-modules/pgpy/default.nix @@ -5,6 +5,7 @@ buildPythonPackage, setuptools, pyasn1, + fetchpatch, cryptography, pytestCheckHook, }: @@ -15,7 +16,7 @@ buildPythonPackage rec { disabled = pythonOlder "3.6"; - format = "pyproject"; + pyproject = true; src = fetchFromGitHub { owner = "SecurityInnovation"; @@ -24,24 +25,35 @@ buildPythonPackage rec { hash = "sha256-47YiHNxmjyCOYHHUV3Zyhs3Att9HZtCXYfbN34ooTxU="; }; - nativeBuildInputs = [ setuptools ]; + build-system = [ setuptools ]; - propagatedBuildInputs = [ + dependencies = [ pyasn1 cryptography ]; + patches = [ + # https://github.com/SecurityInnovation/PGPy/issues/462 + ./pr-443.patch + ]; + + postPatch = '' + # https://github.com/SecurityInnovation/PGPy/issues/472 + substituteInPlace tests/test_10_exceptions.py \ + --replace-fail ", 512" ", 1024" # We need longer test key because pgp deprecated length=512 + ''; + nativeCheckInputs = [ pytestCheckHook ]; - meta = with lib; { + meta = { homepage = "https://github.com/SecurityInnovation/PGPy"; description = "Pretty Good Privacy for Python"; longDescription = '' PGPy is a Python library for implementing Pretty Good Privacy into Python programs, conforming to the OpenPGP specification per RFC 4880. ''; - license = licenses.bsd3; - maintainers = with maintainers; [ + license = lib.licenses.bsd3; + maintainers = with lib.maintainers; [ eadwu dotlambda ]; diff --git a/pkgs/development/python-modules/pgpy/pr-443.patch b/pkgs/development/python-modules/pgpy/pr-443.patch new file mode 100644 index 0000000000000..4ae677f401d19 --- /dev/null +++ b/pkgs/development/python-modules/pgpy/pr-443.patch @@ -0,0 +1,45 @@ +From 221a1f15a42f3ef76ccafcddf66b7c4ade391bff Mon Sep 17 00:00:00 2001 +From: Daniel Kahn Gillmor +Date: Sat, 11 Feb 2023 12:17:00 -0500 +Subject: [PATCH] drop use of imghdr + +imghdr is deprecated and will be removed in python 3.13 (see https://peps.python.org/pep-0594/#imghdr) + +The relevant code in imghdr is just: + +``` +def test_jpeg(h, f): + """JPEG data with JFIF or Exif markers; and raw JPEG""" + if h[6:10] in (b'JFIF', b'Exif'): + return 'jpeg' + elif h[:4] == b'\xff\xd8\xff\xdb': + return 'jpeg' +``` + +So we transplant it directly +--- + pgpy/constants.py | 4 +--- + 1 file changed, 1 insertion(+), 3 deletions(-) + +diff --git a/pgpy/constants.py b/pgpy/constants.py +index 28a4561a..983916d4 100644 +--- a/pgpy/constants.py ++++ b/pgpy/constants.py +@@ -2,7 +2,6 @@ + """ + import bz2 + import hashlib +-import imghdr + import os + import zlib + import warnings +@@ -429,8 +428,7 @@ class ImageEncoding(IntEnum): + + @classmethod + def encodingof(cls, imagebytes): +- type = imghdr.what(None, h=imagebytes) +- if type == 'jpeg': ++ if imagebytes[6:10] in (b'JFIF', b'Exif') or imagebytes[:4] == b'\xff\xd8\xff\xdb': + return ImageEncoding.JPEG + return ImageEncoding.Unknown # pragma: no cover +