python311Packages.pyscard: modernize, stop propagating PCSC/pcsclite as they are not python packages

This commit is contained in:
Nick Cao 2023-11-14 15:48:48 -05:00
parent ab4a6dc639
commit 03db50d77b
No known key found for this signature in database

View file

@ -1,10 +1,13 @@
{ lib { lib
, stdenv , stdenv
, fetchPypi , fetchFromGitHub
, buildPythonPackage , buildPythonPackage
, setuptools
, pkg-config
, swig , swig
, pcsclite , pcsclite
, PCSC , PCSC
, pytestCheckHook
}: }:
let let
@ -15,28 +18,45 @@ in
buildPythonPackage rec { buildPythonPackage rec {
version = "2.0.7"; version = "2.0.7";
pname = "pyscard"; pname = "pyscard";
pyproject = true;
src = fetchPypi { src = fetchFromGitHub {
inherit pname version; owner = "LudovicRousseau";
hash = "sha256-J4BUUl+nX76LEEYNh+3NA6cK2U1oixE0Xkc5mH+Fwb8="; repo = "pyscard";
rev = "refs/tags/${version}";
hash = "sha256-nkDI1OPQ4SsNhWkg53ZTsG7j0+mvpkJI7dsyaOl1a/8=";
}; };
postPatch = if withApplePCSC then '' nativeBuildInputs = [
substituteInPlace smartcard/scard/winscarddll.c \ setuptools
--replace "/System/Library/Frameworks/PCSC.framework/PCSC" \ swig
"${PCSC}/Library/Frameworks/PCSC.framework/PCSC" ] ++ lib.optionals (!withApplePCSC) [
'' else '' pkg-config
substituteInPlace smartcard/scard/winscarddll.c \ ];
--replace "libpcsclite.so.1" \
"${lib.getLib pcsclite}/lib/libpcsclite${stdenv.hostPlatform.extensions.sharedLibrary}" buildInputs = if withApplePCSC then [ PCSC ] else [ pcsclite ];
nativeCheckInputs = [
pytestCheckHook
];
postPatch =
if withApplePCSC then ''
substituteInPlace smartcard/scard/winscarddll.c \
--replace "/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 "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
''; '';
env.NIX_CFLAGS_COMPILE = lib.optionalString (! withApplePCSC)
"-I ${lib.getDev pcsclite}/include/PCSC";
propagatedBuildInputs = if withApplePCSC then [ PCSC ] else [ pcsclite ];
nativeBuildInputs = [ swig ];
meta = with lib; { meta = with lib; {
homepage = "https://pyscard.sourceforge.io/"; homepage = "https://pyscard.sourceforge.io/";
description = "Smartcard library for python"; description = "Smartcard library for python";