guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

11/13: gnu: python-magic: Work around crash on .crx files.


From: guix-commits
Subject: 11/13: gnu: python-magic: Work around crash on .crx files.
Date: Thu, 16 Dec 2021 16:23:14 -0500 (EST)

mbakke pushed a commit to branch master
in repository guix.

commit 1f4319886a9523ee46033f1d28b15f564bab4312
Author: Marius Bakke <marius@gnu.org>
AuthorDate: Thu Dec 16 21:10:34 2021 +0100

    gnu: python-magic: Work around crash on .crx files.
    
    * gnu/packages/patches/python-magic-python-bytecode.patch: New file.
    * gnu/local.mk (dist_patch_DATA): Adjust accordingly.
    * gnu/packages/python-xyz.scm (python-magic)[source](patches): Add it.
    [inputs]: Add FILE-NEXT.
    [arguments]: While at it, remove input labels.
    * gnu/packages/diffoscope.scm (diffoscope)[native-inputs]: Add FILE-NEXT.
---
 gnu/local.mk                                          |  1 +
 gnu/packages/diffoscope.scm                           |  6 ++++++
 .../patches/python-magic-python-bytecode.patch        | 19 +++++++++++++++++++
 gnu/packages/python-xyz.scm                           |  9 ++++++---
 4 files changed, 32 insertions(+), 3 deletions(-)

diff --git a/gnu/local.mk b/gnu/local.mk
index afe7c08..274acb9 100644
--- a/gnu/local.mk
+++ b/gnu/local.mk
@@ -1673,6 +1673,7 @@ dist_patch_DATA =                                         
\
   %D%/packages/patches/python-pyflakes-test-location.patch     \
   %D%/packages/patches/python-flint-includes.patch             \
   %D%/packages/patches/python-libxml2-utf8.patch               \
+  %D%/packages/patches/python-magic-python-bytecode.patch      \
   %D%/packages/patches/python-matplotlib-run-under-wayland-gtk3.patch  \
   %D%/packages/patches/python-memcached-syntax-warnings.patch  \
   %D%/packages/patches/python-mox3-python3.6-compat.patch      \
diff --git a/gnu/packages/diffoscope.scm b/gnu/packages/diffoscope.scm
index 696270d..bfcdf05 100644
--- a/gnu/packages/diffoscope.scm
+++ b/gnu/packages/diffoscope.scm
@@ -34,6 +34,7 @@
   #:use-module (gnu packages compression)
   #:use-module (gnu packages cpio)
   #:use-module (gnu packages dbm)
+  #:use-module (gnu packages file)      ;for 'file-next'
   #:use-module (gnu packages gettext)
   #:use-module (gnu packages ghostscript)
   #:use-module (gnu packages gnome)
@@ -184,6 +185,11 @@
                      ("dtc" ,dtc)
                      ("e2fsprogs" ,e2fsprogs)
                      ("ffmpeg" ,ffmpeg)
+
+                     ;; XXX: Must be the same version as python-magic uses;
+                     ;; remove when 'file' is updated.
+                     ("file" ,file-next)
+
                      ("fpc" ,fpc)
                      ("gettext" ,gettext-minimal)
                      ("ghostscript" ,ghostscript)
diff --git a/gnu/packages/patches/python-magic-python-bytecode.patch 
b/gnu/packages/patches/python-magic-python-bytecode.patch
new file mode 100644
index 0000000..997fb4e
--- /dev/null
+++ b/gnu/packages/patches/python-magic-python-bytecode.patch
@@ -0,0 +1,19 @@
+File 5.41 changed the MIME type of Python bytecode; adjust accordingly.
+
+Taken from upstream:
+
+  
https://github.com/ahupp/python-magic/commit/0ae7e7ceac0e80e03adc75c858bb378c0427331a
+
+diff --git a/test/test.py b/test/test.py
+index 0c4621c..e443b84 100755
+--- a/test/test.py
++++ b/test/test.py
+@@ -90,7 +90,7 @@ def test_mime_types(self):
+         try:
+             m = magic.Magic(mime=True)
+             self.assert_values(m, {
+-                'magic._pyc_': ('application/octet-stream', 
'text/x-bytecode.python'),
++                'magic._pyc_': ('application/octet-stream', 
'text/x-bytecode.python', 'application/x-bytecode.python'),
+                 'test.pdf': 'application/pdf',
+                 'test.gz': ('application/gzip', 'application/x-gzip'),
+                 'test.snappy.parquet': 'application/octet-stream',
diff --git a/gnu/packages/python-xyz.scm b/gnu/packages/python-xyz.scm
index be40a02..13d883c 100644
--- a/gnu/packages/python-xyz.scm
+++ b/gnu/packages/python-xyz.scm
@@ -14614,6 +14614,7 @@ syntax highlighting, markdown and more to the 
terminal.")
        (method git-fetch)
        (uri (git-reference (url home-page) (commit version)))
        (file-name (git-file-name name version))
+       (patches (search-patches "python-magic-python-bytecode.patch"))
        (sha256
         (base32
          "17jalhjbfd600lzfz296m0nvgp6c7vx1mgz82jbzn8hgdzknf4w0"))))
@@ -14628,10 +14629,10 @@ syntax highlighting, markdown and more to the 
terminal.")
                   ;; python-magic to fail.
                   (add-before 'build 'hard-code-path-to-libmagic
                     (lambda* (#:key inputs #:allow-other-keys)
-                      (let ((file (assoc-ref inputs "file")))
+                      (let ((magic (search-input-file inputs 
"/lib/libmagic.so")))
                         (substitute* "magic/loader.py"
                           (("find_library\\('magic'\\)")
-                           (string-append "'" file "/lib/libmagic.so'"))))))
+                           (string-append "'" magic "'"))))))
                   (replace 'check
                     (lambda* (#:key tests? #:allow-other-keys)
                       ;; The test suite mandates this variable.
@@ -14645,7 +14646,9 @@ syntax highlighting, markdown and more to the 
terminal.")
      (list which))
     (inputs
      ;; python-magic needs to be able to find libmagic.so.
-     (list file))
+     ;; Use a newer version because 5.39 returns bogus for some archives
+     ;; (notably Chromium .crx extensions), which breaks e.g. 'diffoscope'.
+     (list file-next))
     (synopsis "File type identification using libmagic")
     (description
      "This module uses ctypes to access the libmagic file type



reply via email to

[Prev in Thread] Current Thread [Next in Thread]