1{ stdenv, buildPythonPackage, isPy27, isPyPy, fetchPypi, libffi, pycparser, pytest }:
2
3if isPyPy then null else buildPythonPackage rec {
4 pname = "cffi";
5 version = "1.11.4";
6 name = "${pname}-${version}";
7
8 src = fetchPypi {
9 inherit pname version;
10 sha256 = "df9083a992b17a28cd4251a3f5c879e0198bb26c9e808c4647e0a18739f1d11d";
11 };
12
13 outputs = [ "out" "dev" ];
14
15 propagatedBuildInputs = [ libffi pycparser ];
16 buildInputs = [ pytest ];
17
18 # On Darwin, the cffi tests want to hit libm a lot, and look for it in a global
19 # impure search path. It's obnoxious how much repetition there is, and how difficult
20 # it is to get it to search somewhere else (since we do actually have a libm symlink in libSystem)
21 prePatch = stdenv.lib.optionalString stdenv.isDarwin ''
22 substituteInPlace testing/cffi0/test_parsing.py \
23 --replace 'lib_m = "m"' 'lib_m = "System"' \
24 --replace '"libm" in name' '"libSystem" in name'
25 substituteInPlace testing/cffi0/test_unicode_literals.py --replace 'lib_m = "m"' 'lib_m = "System"'
26 substituteInPlace testing/cffi0/test_zdistutils.py --replace 'self.lib_m = "m"' 'self.lib_m = "System"'
27 substituteInPlace testing/cffi1/test_recompiler.py --replace 'lib_m = "m"' 'lib_m = "System"'
28 substituteInPlace testing/cffi0/test_function.py --replace "lib_m = 'm'" "lib_m = 'System'"
29 substituteInPlace testing/cffi0/test_verify.py --replace "lib_m = ['m']" "lib_m = ['System']"
30 '';
31
32 # The tests use -Werror but with python3.6 clang detects some unreachable code.
33 NIX_CFLAGS_COMPILE = stdenv.lib.optionals stdenv.cc.isClang [ "-Wno-unused-command-line-argument" "-Wno-unreachable-code" ];
34
35 doCheck = !stdenv.hostPlatform.isMusl; # TODO: Investigate
36 checkPhase = ''
37 py.test
38 '';
39
40 meta = with stdenv.lib; {
41 maintainers = with maintainers; [ domenkozar lnl7 ];
42 homepage = https://cffi.readthedocs.org/;
43 license = with licenses; [ mit ];
44 description = "Foreign Function Interface for Python calling C code";
45 };
46}