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.hostPlatform.isDarwin;
17in
18
19buildPythonPackage rec {
20 pname = "pyscard";
21 version = "2.2.0";
22 pyproject = true;
23
24 src = fetchFromGitHub {
25 owner = "LudovicRousseau";
26 repo = "pyscard";
27 rev = "refs/tags/${version}";
28 hash = "sha256-yZeP4Tcxnwb2My+XOsMtj+H8mNIf6JYf5tpOVUYjev0=";
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 ''
41 substituteInPlace pyproject.toml \
42 --replace-fail 'requires = ["setuptools","swig"]' 'requires = ["setuptools"]'
43 ''
44 + (
45 if withApplePCSC then
46 ''
47 substituteInPlace src/smartcard/scard/winscarddll.c \
48 --replace-fail "/System/Library/Frameworks/PCSC.framework/PCSC" \
49 "${PCSC}/Library/Frameworks/PCSC.framework/PCSC"
50 ''
51 else
52 ''
53 substituteInPlace setup.py --replace-fail "pkg-config" "$PKG_CONFIG"
54 substituteInPlace src/smartcard/scard/winscarddll.c \
55 --replace-fail "libpcsclite.so.1" \
56 "${lib.getLib pcsclite}/lib/libpcsclite${stdenv.hostPlatform.extensions.sharedLibrary}"
57 ''
58 );
59
60 meta = {
61 description = "Smartcard library for python";
62 homepage = "https://pyscard.sourceforge.io/";
63 changelog = "https://github.com/LudovicRousseau/pyscard/releases/tag/${version}";
64 license = lib.licenses.lgpl21Plus;
65 maintainers = with lib.maintainers; [ layus ];
66 };
67}