diff --git a/pkgs/development/python-modules/pycapnp/default.nix b/pkgs/development/python-modules/pycapnp/default.nix index 51f36bd86eec..f06b010a5467 100644 --- a/pkgs/development/python-modules/pycapnp/default.nix +++ b/pkgs/development/python-modules/pycapnp/default.nix @@ -1,42 +1,76 @@ { lib, buildPythonPackage, - capnproto, - cython_0, + replaceVars, fetchFromGitHub, - isPy27, - isPyPy, + fetchpatch2, + setuptools, + wheel, + capnproto, + cython, pkgconfig, + pytest-asyncio, + pytestCheckHook, }: buildPythonPackage rec { pname = "pycapnp"; version = "2.0.0"; - format = "setuptools"; - disabled = isPyPy || isPy27; + format = "pyproject"; src = fetchFromGitHub { owner = "capnproto"; repo = "pycapnp"; tag = "v${version}"; - sha256 = "sha256-SVeBRJMMR1Z8+S+QoiUKGRFGUPS/MlmWLi1qRcGcPoE="; + hash = "sha256-SVeBRJMMR1Z8+S+QoiUKGRFGUPS/MlmWLi1qRcGcPoE="; }; - nativeBuildInputs = [ - cython_0 + patches = [ + # pycapnp hardcodes /usr/include and /usr/local/include as the paths to search + # for capnproto's built-in schemas in; replace them with the path to our copy of + # capnproto. + # + # Theoretically, this mechanism could also be used to load capnproto schemas + # exposed by other packages (e.g. capnproto-java), which we could support using + # a setup hook; but in practice nobody seems to use this mechanism for anything + # other than the builtin schemas (based on quick GitHub code search), so I don't + # think it's worthwhile. + (replaceVars ./include-paths.patch { inherit capnproto; }) + (fetchpatch2 { + name = "cython-3.patch"; + url = "https://github.com/capnproto/pycapnp/pull/334.diff?full_index=1"; + hash = "sha256-we7v4RaL7c1tePWl+oYfzMHAfnvnpdMkQgVu9YLwC6Y="; + }) + ]; + + build-system = [ + setuptools + wheel + cython pkgconfig ]; buildInputs = [ capnproto ]; - # Tests depend on schema_capnp which fails to generate - doCheck = false; + nativeCheckInputs = [ + pytest-asyncio + pytestCheckHook + ]; + __darwinAllowLocalNetworking = true; + # https://github.com/NixOS/nixpkgs/issues/255262 + preCheck = '' + enabledTestPaths=$PWD/test + pushd "$out" + ''; + postCheck = '' + popd + ''; - pythonImportsCheck = [ "capnp" ]; - - meta = with lib; { + meta = { + description = "Cython wrapping of the C++ Cap'n Proto library"; homepage = "https://capnproto.github.io/pycapnp/"; - maintainers = [ ]; - license = licenses.bsd2; + changelog = "https://github.com/capnproto/pycapnp/blob/${src.rev}/CHANGELOG.md"; + license = lib.licenses.bsd2; + maintainers = with lib.maintainers; [ Liamolucko ]; }; } diff --git a/pkgs/development/python-modules/pycapnp/include-paths.patch b/pkgs/development/python-modules/pycapnp/include-paths.patch new file mode 100644 index 000000000000..04bd7a79e5c2 --- /dev/null +++ b/pkgs/development/python-modules/pycapnp/include-paths.patch @@ -0,0 +1,14 @@ +--- a/capnp/lib/capnp.pyx ++++ b/capnp/lib/capnp.pyx +@@ -4410,10 +4410,7 @@ def load(file_name, display_name=None, imports=[]): + # Automatically include the system and built-in capnp paths + # Highest priority at position 0 + _capnp_paths = [ +- # Common macOS brew location +- '/usr/local/include', +- # Common posix location +- '/usr/include', ++ '@capnproto@/include', + ] + + class _Loader: