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