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 ]
63 ++ lib.flatten (builtins.attrValues optional-dependencies);
64
65 pythonImportsCheck = [ "betterproto" ];
66
67 # The tests require the generation of code before execution. This requires
68 # the protoc-gen-python_betterproto script from the package to be on PATH.
69 preCheck = ''
70 (($(ulimit -n) < 1024)) && ulimit -n 1024
71 export PATH=$PATH:$out/bin
72 patchShebangs src/betterproto/plugin/main.py
73 ${python.interpreter} -m tests.generate
74 '';
75
76 disabledTestPaths = [
77 # https://github.com/danielgtaylor/python-betterproto/issues/530
78 "tests/inputs/oneof/test_oneof.py"
79 ];
80
81 disabledTests = [
82 "test_pydantic_no_value"
83 # Test is flaky
84 "test_binary_compatibility"
85 ];
86
87 meta = {
88 description = "Code generator & library for Protobuf 3 and async gRPC";
89 mainProgram = "protoc-gen-python_betterproto";
90 longDescription = ''
91 This project aims to provide an improved experience when using Protobuf /
92 gRPC in a modern Python environment by making use of modern language
93 features and generating readable, understandable, idiomatic Python code.
94 '';
95 homepage = "https://github.com/danielgtaylor/python-betterproto";
96 changelog = "https://github.com/danielgtaylor/python-betterproto/blob/v.${version}/CHANGELOG.md";
97 license = lib.licenses.mit;
98 maintainers = with lib.maintainers; [ nikstur ];
99 };
100}