1{
2 buildPythonPackage,
3 fetchFromGitHub,
4 lib,
5 pythonOlder,
6 poetry-core,
7 grpclib,
8 python-dateutil,
9 black,
10 jinja2,
11 isort,
12 python,
13 pydantic,
14 pytest7CheckHook,
15 pytest-asyncio_0_21,
16 pytest-mock,
17 typing-extensions,
18 tomlkit,
19 grpcio-tools,
20}:
21
22buildPythonPackage rec {
23 pname = "betterproto";
24 version = "2.0.0b6";
25 pyproject = true;
26
27 disabled = pythonOlder "3.9";
28
29 src = fetchFromGitHub {
30 owner = "danielgtaylor";
31 repo = "python-betterproto";
32 tag = "v.${version}";
33 hash = "sha256-ZuVq4WERXsRFUPNNTNp/eisWX1MyI7UtwqEI8X93wYI=";
34 };
35
36 postPatch = ''
37 substituteInPlace pyproject.toml \
38 --replace-fail "poetry-core>=1.0.0,<2" "poetry-core"
39 '';
40
41 build-system = [ poetry-core ];
42
43 dependencies = [
44 grpclib
45 python-dateutil
46 typing-extensions
47 ];
48
49 optional-dependencies.compiler = [
50 black
51 jinja2
52 isort
53 ];
54
55 nativeCheckInputs = [
56 grpcio-tools
57 pydantic
58 pytest-asyncio_0_21
59 pytest-mock
60 pytest7CheckHook
61 tomlkit
62 ] ++ lib.flatten (builtins.attrValues optional-dependencies);
63
64 pythonImportsCheck = [ "betterproto" ];
65
66 # The tests require the generation of code before execution. This requires
67 # the protoc-gen-python_betterproto script from the package to be on PATH.
68 preCheck = ''
69 (($(ulimit -n) < 1024)) && ulimit -n 1024
70 export PATH=$PATH:$out/bin
71 patchShebangs src/betterproto/plugin/main.py
72 ${python.interpreter} -m tests.generate
73 '';
74
75 disabledTestPaths = [
76 # https://github.com/danielgtaylor/python-betterproto/issues/530
77 "tests/inputs/oneof/test_oneof.py"
78 ];
79
80 disabledTests = [
81 "test_pydantic_no_value"
82 # Test is flaky
83 "test_binary_compatibility"
84 ];
85
86 meta = {
87 description = "Code generator & library for Protobuf 3 and async gRPC";
88 mainProgram = "protoc-gen-python_betterproto";
89 longDescription = ''
90 This project aims to provide an improved experience when using Protobuf /
91 gRPC in a modern Python environment by making use of modern language
92 features and generating readable, understandable, idiomatic Python code.
93 '';
94 homepage = "https://github.com/danielgtaylor/python-betterproto";
95 changelog = "https://github.com/danielgtaylor/python-betterproto/blob/v.${version}/CHANGELOG.md";
96 license = lib.licenses.mit;
97 maintainers = with lib.maintainers; [ nikstur ];
98 };
99}