2024-06-05 15:53:02 +00:00
|
|
|
{
|
|
|
|
buildPackages,
|
|
|
|
buildPythonPackage,
|
|
|
|
fetchpatch,
|
|
|
|
isPyPy,
|
|
|
|
lib,
|
|
|
|
numpy,
|
|
|
|
protobuf,
|
|
|
|
pytestCheckHook,
|
|
|
|
pythonAtLeast,
|
|
|
|
substituteAll,
|
|
|
|
tzdata,
|
2021-01-09 10:05:03 +00:00
|
|
|
}:
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2023-11-16 04:20:00 +00:00
|
|
|
assert lib.versionOlder protobuf.version "21" -> throw "Protobuf 21 or newer required";
|
|
|
|
|
2022-11-21 17:40:18 +00:00
|
|
|
let
|
2023-11-16 04:20:00 +00:00
|
|
|
protobufVersionMajor = lib.versions.major protobuf.version;
|
|
|
|
protobufVersionMinor = lib.versions.minor protobuf.version;
|
2022-11-21 17:40:18 +00:00
|
|
|
in
|
2020-04-24 23:36:52 +00:00
|
|
|
buildPythonPackage {
|
2022-11-21 17:40:18 +00:00
|
|
|
inherit (protobuf) pname src;
|
|
|
|
|
2023-11-16 04:20:00 +00:00
|
|
|
# protobuf 21 corresponds with its python library 4.21
|
|
|
|
version = "4.${protobufVersionMajor}.${protobufVersionMinor}";
|
2024-01-02 11:29:13 +00:00
|
|
|
format = "setuptools";
|
2022-11-21 17:40:18 +00:00
|
|
|
|
2023-08-04 22:07:22 +00:00
|
|
|
sourceRoot = "${protobuf.src.name}/python";
|
2022-11-21 17:40:18 +00:00
|
|
|
|
2024-06-05 15:53:02 +00:00
|
|
|
patches =
|
|
|
|
lib.optionals (lib.versionAtLeast protobuf.version "22") [
|
|
|
|
# Replace the vendored abseil-cpp with nixpkgs'
|
|
|
|
(substituteAll {
|
|
|
|
src = ./use-nixpkgs-abseil-cpp.patch;
|
|
|
|
abseil_cpp_include_path = "${lib.getDev protobuf.abseil-cpp}/include";
|
|
|
|
})
|
|
|
|
]
|
|
|
|
++ lib.optionals (pythonAtLeast "3.11" && lib.versionOlder protobuf.version "22") [
|
|
|
|
(fetchpatch {
|
|
|
|
name = "support-python311.patch";
|
|
|
|
url = "https://github.com/protocolbuffers/protobuf/commit/2206b63c4649cf2e8a06b66c9191c8ef862ca519.diff";
|
|
|
|
stripLen = 1; # because sourceRoot above
|
|
|
|
hash = "sha256-3GaoEyZIhS3QONq8LEvJCH5TdO9PKnOgcQF0GlEiwFo=";
|
|
|
|
})
|
|
|
|
];
|
2023-01-20 10:41:00 +00:00
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
prePatch = ''
|
2022-11-21 17:40:18 +00:00
|
|
|
if [[ "$(<../version.json)" != *'"python": "'"$version"'"'* ]]; then
|
|
|
|
echo "Python library version mismatch. Derivation version: $version, actual: $(<../version.json)"
|
|
|
|
exit 1
|
|
|
|
fi
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
|
2023-08-22 20:05:09 +00:00
|
|
|
# Remove the line in setup.py that forces compiling with C++14. Upstream's
|
|
|
|
# CMake build has been updated to support compiling with other versions of
|
|
|
|
# C++, but the Python build has not. Without this, we observe compile-time
|
|
|
|
# errors using GCC.
|
|
|
|
#
|
|
|
|
# Fedora appears to do the same, per this comment:
|
|
|
|
#
|
|
|
|
# https://github.com/protocolbuffers/protobuf/issues/12104#issuecomment-1542543967
|
|
|
|
#
|
|
|
|
postPatch = ''
|
|
|
|
sed -i "/extra_compile_args.append('-std=c++14')/d" setup.py
|
2024-04-21 15:54:59 +00:00
|
|
|
|
|
|
|
# The former function has been renamed into the latter in Python 3.12.
|
|
|
|
# Does not apply to all protobuf versions, hence --replace-warn.
|
|
|
|
substituteInPlace google/protobuf/internal/json_format_test.py \
|
|
|
|
--replace-warn assertRaisesRegexp assertRaisesRegex
|
2023-08-22 20:05:09 +00:00
|
|
|
'';
|
|
|
|
|
2023-08-04 22:07:22 +00:00
|
|
|
nativeBuildInputs = lib.optional isPyPy tzdata;
|
|
|
|
|
2022-11-02 22:02:43 +00:00
|
|
|
buildInputs = [ protobuf ];
|
|
|
|
|
|
|
|
propagatedNativeBuildInputs = [
|
|
|
|
# For protoc of the same version.
|
2023-11-16 04:20:00 +00:00
|
|
|
buildPackages."protobuf_${protobufVersionMajor}"
|
2022-11-02 22:02:43 +00:00
|
|
|
];
|
|
|
|
|
2022-12-17 10:02:37 +00:00
|
|
|
setupPyGlobalFlags = [ "--cpp_implementation" ];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2023-08-04 22:07:22 +00:00
|
|
|
nativeCheckInputs = [
|
|
|
|
pytestCheckHook
|
2024-06-05 15:53:02 +00:00
|
|
|
] ++ lib.optionals (lib.versionAtLeast protobuf.version "22") [ numpy ];
|
2023-08-04 22:07:22 +00:00
|
|
|
|
|
|
|
disabledTests = lib.optionals isPyPy [
|
|
|
|
# error message differs
|
|
|
|
"testInvalidTimestamp"
|
|
|
|
# requires tracemalloc which pypy does not implement
|
|
|
|
# https://foss.heptapod.net/pypy/pypy/-/issues/3048
|
|
|
|
"testUnknownFieldsNoMemoryLeak"
|
|
|
|
# assertion is not raised for some reason
|
|
|
|
"testStrictUtf8Check"
|
|
|
|
];
|
|
|
|
|
2024-06-05 15:53:02 +00:00
|
|
|
disabledTestPaths =
|
|
|
|
lib.optionals (lib.versionAtLeast protobuf.version "23") [
|
|
|
|
# The following commit (I think) added some internal test logic for Google
|
|
|
|
# that broke generator_test.py. There is a new proto file that setup.py is
|
|
|
|
# not generating into a .py file. However, adding this breaks a bunch of
|
|
|
|
# conflict detection in descriptor_test.py that I don't understand. So let's
|
|
|
|
# just disable generator_test.py for now.
|
|
|
|
#
|
|
|
|
# https://github.com/protocolbuffers/protobuf/commit/5abab0f47e81ac085f0b2d17ec3b3a3b252a11f1
|
|
|
|
#
|
|
|
|
"google/protobuf/internal/generator_test.py"
|
|
|
|
]
|
|
|
|
++ lib.optionals (lib.versionAtLeast protobuf.version "25") [
|
|
|
|
"minimal_test.py" # ModuleNotFoundError: No module named 'google3'
|
|
|
|
];
|
2023-08-22 20:05:09 +00:00
|
|
|
|
2021-12-19 01:06:50 +00:00
|
|
|
pythonImportsCheck = [
|
|
|
|
"google.protobuf"
|
|
|
|
"google.protobuf.internal._api_implementation" # Verify that --cpp_implementation worked
|
|
|
|
];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
2022-11-02 22:02:43 +00:00
|
|
|
passthru = {
|
|
|
|
inherit protobuf;
|
|
|
|
};
|
|
|
|
|
2021-02-05 17:12:51 +00:00
|
|
|
meta = with lib; {
|
2020-04-24 23:36:52 +00:00
|
|
|
description = "Protocol Buffers are Google's data interchange format";
|
|
|
|
homepage = "https://developers.google.com/protocol-buffers/";
|
|
|
|
license = licenses.bsd3;
|
2021-12-19 01:06:50 +00:00
|
|
|
maintainers = with maintainers; [ knedlsepp ];
|
2024-02-29 20:09:43 +00:00
|
|
|
# Tests are currently failing because backend is unavailable and causes tests to fail
|
|
|
|
# Progress tracked in https://github.com/NixOS/nixpkgs/pull/264902
|
2024-06-05 15:53:02 +00:00
|
|
|
broken = lib.versionAtLeast protobuf.version "26";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
}
|