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,
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 rev = "refs/tags/v.${version}";
33 hash = "sha256-ZuVq4WERXsRFUPNNTNp/eisWX1MyI7UtwqEI8X93wYI=";
34 };
35
36 build-system = [ poetry-core ];
37
38 dependencies = [
39 grpclib
40 python-dateutil
41 typing-extensions
42 ];
43
44 passthru.optional-dependencies.compiler = [
45 black
46 jinja2
47 isort
48 ];
49
50 nativeCheckInputs = [
51 grpcio-tools
52 pydantic
53 pytest-asyncio
54 pytest-mock
55 pytest7CheckHook
56 tomlkit
57 ] ++ lib.flatten (builtins.attrValues passthru.optional-dependencies);
58
59 pythonImportsCheck = [ "betterproto" ];
60
61 # The tests require the generation of code before execution. This requires
62 # the protoc-gen-python_betterproto script from the package to be on PATH.
63 preCheck = ''
64 (($(ulimit -n) < 1024)) && ulimit -n 1024
65 export PATH=$PATH:$out/bin
66 patchShebangs src/betterproto/plugin/main.py
67 ${python.interpreter} -m tests.generate
68 '';
69
70 disabledTestPaths = [
71 # https://github.com/danielgtaylor/python-betterproto/issues/530
72 "tests/inputs/oneof/test_oneof.py"
73 ];
74
75 disabledTests = [
76 "test_pydantic_no_value"
77 # Test is flaky
78 "test_binary_compatibility"
79 ];
80
81 meta = with lib; {
82 description = "Code generator & library for Protobuf 3 and async gRPC";
83 mainProgram = "protoc-gen-python_betterproto";
84 longDescription = ''
85 This project aims to provide an improved experience when using Protobuf /
86 gRPC in a modern Python environment by making use of modern language
87 features and generating readable, understandable, idiomatic Python code.
88 '';
89 homepage = "https://github.com/danielgtaylor/python-betterproto";
90 changelog = "https://github.com/danielgtaylor/python-betterproto/blob/v.${version}/CHANGELOG.md";
91 license = licenses.mit;
92 maintainers = with maintainers; [ nikstur ];
93 };
94}