1{
2 lib,
3 buildPythonPackage,
4 fetchFromGitHub,
5 pythonOlder,
6 can,
7 cobs,
8 libpcap,
9 nunavut,
10 numpy,
11 pyserial,
12 pytestCheckHook,
13 pytest-asyncio,
14 setuptools,
15}:
16
17buildPythonPackage rec {
18 pname = "pycyphal";
19 version = "1.18.0";
20 format = "setuptools";
21
22 disabled = pythonOlder "3.8";
23
24 src = fetchFromGitHub {
25 owner = "OpenCyphal";
26 repo = pname;
27 rev = "refs/tags/${version}";
28 hash = "sha256-XkH0wss8ueh/Wwz0lhvQShOp3a4X9lNdosT/sMe7p4Q=";
29 fetchSubmodules = true;
30 };
31
32 propagatedBuildInputs = [
33 numpy
34 nunavut
35 ];
36
37 passthru.optional-dependencies = {
38 transport-can-pythoncan = [ can ] ++ can.optional-dependencies.serial;
39 transport-serial = [
40 cobs
41 pyserial
42 ];
43 transport-udp = [ libpcap ];
44 };
45
46 nativeCheckInputs = [
47 pytestCheckHook
48 pytest-asyncio
49 ] ++ builtins.foldl' (x: y: x ++ y) [ ] (builtins.attrValues passthru.optional-dependencies);
50
51 preCheck = ''
52 export HOME=$TMPDIR
53 export PYTHONASYNCIODEBUG=1
54 python -c ${lib.escapeShellArg ''
55 import pycyphal
56 pycyphal.dsdl.compile_all(
57 [
58 "demo/public_regulated_data_types/uavcan",
59 "demo/custom_data_types/sirius_cyber_corp",
60 ],
61 output_directory=".dsdl_compiled",
62 )
63 ''}
64 export PYTHONPATH="$(pwd)/.dsdl_compiled:$PYTHONPATH"
65 '';
66
67 # These require extra permissions and/or actual hardware connected
68 disabledTestPaths = [
69 "pycyphal/application/__init__.py"
70 "pycyphal/application/_transport_factory.py"
71 "pycyphal/transport/udp/_ip/_link_layer.py"
72 "pycyphal/transport/udp/_ip/_v4.py"
73 "tests/application"
74 "tests/demo"
75 "tests/dsdl"
76 "tests/presentation"
77 "tests/transport"
78 ];
79
80 pythonImportsCheck = [ "pycyphal" ];
81
82 meta = with lib; {
83 description = "A full-featured implementation of the Cyphal protocol stack in Python";
84 longDescription = ''
85 Cyphal is an open technology for real-time intravehicular distributed computing and communication based on modern networking standards (Ethernet, CAN FD, etc.).
86 '';
87 homepage = "https://opencyphal.org/";
88 changelog = "https://github.com/OpenCyphal/pycyphal/blob/${version}/CHANGELOG.rst";
89 license = licenses.mit;
90 maintainers = teams.ororatech.members;
91 };
92}