From 6c3b5c1942fe539226fad6bea4af9f1b2c275e45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=BCtz?= Date: Sun, 28 Feb 2021 11:32:30 +0100 Subject: [PATCH] pythonPackages.python_magic: fix build and run tests --- .../python-modules/python-magic/default.nix | 38 ++++++++++++------- .../python-magic/libmagic-path.patch | 17 +++++++++ 2 files changed, 42 insertions(+), 13 deletions(-) create mode 100644 pkgs/development/python-modules/python-magic/libmagic-path.patch diff --git a/pkgs/development/python-modules/python-magic/default.nix b/pkgs/development/python-modules/python-magic/default.nix index 5fb576e5f02f..6737f1260733 100644 --- a/pkgs/development/python-modules/python-magic/default.nix +++ b/pkgs/development/python-modules/python-magic/default.nix @@ -1,25 +1,37 @@ -{ buildPythonPackage, lib, fetchPypi, file, stdenv }: +{ lib +, stdenv +, python +, buildPythonPackage +, fetchFromGitHub +, substituteAll +, file +, glibcLocales +}: buildPythonPackage rec { pname = "python-magic"; version = "0.4.22"; - src = fetchPypi { - inherit pname version; - sha256 = "ca884349f2c92ce830e3f498c5b7c7051fe2942c3ee4332f65213b8ebff15a62"; + src = fetchFromGitHub { + owner = "ahupp"; + repo = "python-magic"; + rev = version; + sha256 = "0zbdjr5shijs0jayz7gycpx0kn6v2bh83dpanyajk2vmy47jvbd6"; }; - postPatch = '' - substituteInPlace magic.py --replace "ctypes.util.find_library('magic')" "'${file}/lib/libmagic${stdenv.hostPlatform.extensions.sharedLibrary}'" + patches = [ + (substituteAll { + src = ./libmagic-path.patch; + libmagic = "${file}/lib/libmagic${stdenv.hostPlatform.extensions.sharedLibrary}"; + }) + ]; + + checkInputs = [ glibcLocales ]; + + checkPhase = '' + LC_ALL="en_US.UTF-8" ${python.interpreter} test/test.py ''; - doCheck = false; - - # TODO: tests are failing - #checkPhase = '' - # ${python}/bin/${python.executable} ./test.py - #''; - meta = { description = "A python interface to the libmagic file type identification library"; homepage = "https://github.com/ahupp/python-magic"; diff --git a/pkgs/development/python-modules/python-magic/libmagic-path.patch b/pkgs/development/python-modules/python-magic/libmagic-path.patch new file mode 100644 index 000000000000..5a1dbec7d51b --- /dev/null +++ b/pkgs/development/python-modules/python-magic/libmagic-path.patch @@ -0,0 +1,17 @@ +diff --git a/magic/loader.py b/magic/loader.py +index 6b2bfcb..69778af 100644 +--- a/magic/loader.py ++++ b/magic/loader.py +@@ -5,11 +5,7 @@ import glob + def load_lib(): + libmagic = None + # Let's try to find magic or magic1 +- dll = ctypes.util.find_library('magic') \ +- or ctypes.util.find_library('magic1') \ +- or ctypes.util.find_library('cygmagic-1') \ +- or ctypes.util.find_library('libmagic-1') \ +- or ctypes.util.find_library('msys-magic-1') # for MSYS2 ++ dll = '@libmagic@' + + # necessary because find_library returns None if it doesn't find the library + if dll: