Merge pull request #268619 from tweag/lib-descriptions
[NixPkgs.git] / pkgs / development / python-modules / pyscard / default.nix
blob6e7a1ec29cbeda81651ca20e18a20a56df449501
1 { lib
2 , stdenv
3 , fetchFromGitHub
4 , buildPythonPackage
5 , setuptools
6 , pkg-config
7 , swig
8 , pcsclite
9 , PCSC
10 , pytestCheckHook
13 let
14   # Package does not support configuring the pcsc library.
15   withApplePCSC = stdenv.isDarwin;
18 buildPythonPackage rec {
19   version = "2.0.7";
20   pname = "pyscard";
21   pyproject = true;
23   src = fetchFromGitHub {
24     owner = "LudovicRousseau";
25     repo = "pyscard";
26     rev = "refs/tags/${version}";
27     hash = "sha256-nkDI1OPQ4SsNhWkg53ZTsG7j0+mvpkJI7dsyaOl1a/8=";
28   };
30   nativeBuildInputs = [
31     setuptools
32     swig
33   ] ++ lib.optionals (!withApplePCSC) [
34     pkg-config
35   ];
37   buildInputs = if withApplePCSC then [ PCSC ] else [ pcsclite ];
39   nativeCheckInputs = [
40     pytestCheckHook
41   ];
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     '';
55   preCheck = ''
56     # remove src module, so tests use the installed module instead
57     rm -r smartcard
58   '';
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   };