1{ lib 2, stdenv 3, fetchFromGitHub 4, buildPythonPackage 5, setuptools 6, pkg-config 7, swig 8, pcsclite 9, PCSC 10, pytestCheckHook 11}: 12 13let 14 # Package does not support configuring the pcsc library. 15 withApplePCSC = stdenv.isDarwin; 16in 17 18buildPythonPackage rec { 19 version = "2.0.7"; 20 pname = "pyscard"; 21 pyproject = true; 22 23 src = fetchFromGitHub { 24 owner = "LudovicRousseau"; 25 repo = "pyscard"; 26 rev = "refs/tags/${version}"; 27 hash = "sha256-nkDI1OPQ4SsNhWkg53ZTsG7j0+mvpkJI7dsyaOl1a/8="; 28 }; 29 30 nativeBuildInputs = [ 31 setuptools 32 swig 33 ] ++ lib.optionals (!withApplePCSC) [ 34 pkg-config 35 ]; 36 37 buildInputs = if withApplePCSC then [ PCSC ] else [ pcsclite ]; 38 39 nativeCheckInputs = [ 40 pytestCheckHook 41 ]; 42 43 postPatch = 44 if withApplePCSC then '' 45 substituteInPlace smartcard/scard/winscarddll.c \ 46 --replace "/System/Library/Frameworks/PCSC.framework/PCSC" \ 47 "${PCSC}/Library/Frameworks/PCSC.framework/PCSC" 48 '' else '' 49 substituteInPlace setup.py --replace "pkg-config" "$PKG_CONFIG" 50 substituteInPlace smartcard/scard/winscarddll.c \ 51 --replace "libpcsclite.so.1" \ 52 "${lib.getLib pcsclite}/lib/libpcsclite${stdenv.hostPlatform.extensions.sharedLibrary}" 53 ''; 54 55 preCheck = '' 56 # remove src module, so tests use the installed module instead 57 rm -r smartcard 58 ''; 59 60 meta = with lib; { 61 homepage = "https://pyscard.sourceforge.io/"; 62 description = "Smartcard library for python"; 63 license = licenses.lgpl21; 64 maintainers = with maintainers; [ layus ]; 65 }; 66}