about summary refs log tree commit diff
path: root/pkgs/development/python-modules/pyscard/default.nix
blob: 3fd9d3c2fbd46b10ec3c733e559183bc4deeda8d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
{
  lib,
  buildPythonPackage,
  fetchFromGitHub,
  PCSC,
  pcsclite,
  pkg-config,
  pytestCheckHook,
  setuptools,
  stdenv,
  swig,
}:

let
  # Package does not support configuring the pcsc library.
  withApplePCSC = stdenv.isDarwin;
in

buildPythonPackage rec {
  pname = "pyscard";
  version = "2.0.9";
  pyproject = true;

  src = fetchFromGitHub {
    owner = "LudovicRousseau";
    repo = "pyscard";
    rev = "refs/tags/${version}";
    hash = "sha256-DO4Ea+mlrWPpOLI8Eki+03UnsOXEhN2PAl0+gdN5sTo=";
  };

  build-system = [ setuptools ];

  nativeBuildInputs = [ swig ] ++ lib.optionals (!withApplePCSC) [ pkg-config ];

  buildInputs = if withApplePCSC then [ PCSC ] else [ pcsclite ];

  nativeCheckInputs = [ pytestCheckHook ];

  postPatch =
    if withApplePCSC then
      ''
        substituteInPlace smartcard/scard/winscarddll.c \
          --replace-fail "/System/Library/Frameworks/PCSC.framework/PCSC" \
                    "${PCSC}/Library/Frameworks/PCSC.framework/PCSC"
      ''
    else
      ''
        substituteInPlace setup.py --replace "pkg-config" "$PKG_CONFIG"
        substituteInPlace smartcard/scard/winscarddll.c \
          --replace-fail "libpcsclite.so.1" \
                    "${lib.getLib pcsclite}/lib/libpcsclite${stdenv.hostPlatform.extensions.sharedLibrary}"
      '';

  preCheck = ''
    # remove src module, so tests use the installed module instead
    rm -r smartcard
  '';

  disabledTests = [
    # AssertionError
    "test_hresult"
    "test_low_level"
  ];

  meta = with lib; {
    description = "Smartcard library for python";
    homepage = "https://pyscard.sourceforge.io/";
    changelog = "https://github.com/LudovicRousseau/pyscard/releases/tag/${version}";
    license = licenses.lgpl21Plus;
    maintainers = with maintainers; [ layus ];
  };
}