diff --git a/pkgs/development/python-modules/modbus-connection/default.nix b/pkgs/development/python-modules/modbus-connection/default.nix new file mode 100644 index 000000000000..ee941c0f623b --- /dev/null +++ b/pkgs/development/python-modules/modbus-connection/default.nix @@ -0,0 +1,63 @@ +{ + buildPythonPackage, + fetchFromGitHub, + hatchling, + lib, + pymodbus, + pyprojectVersionPatchHook, + pytest-asyncio, + pytestCheckHook, + tmodbus, +}: + +buildPythonPackage (finalAttrs: { + pname = "modbus-connection"; + version = "3.3.0"; + pyproject = true; + __structuredAttrs = true; + + src = fetchFromGitHub { + owner = "home-assistant-libs"; + repo = "modbus-connection"; + tag = finalAttrs.version; + hash = "sha256-IEdOLd+BjX2b6bQS7hw33CyuDFVJ5dO0BaHLLhGp3LE="; + }; + + nativeBuildInputs = [ + pyprojectVersionPatchHook + ]; + + build-system = [ + hatchling + ]; + + optional-dependencies = { + pymodbus = [ + pymodbus + ] + ++ pymodbus.optional-dependencies.serial; + tmodbus = [ + tmodbus + ] + ++ tmodbus.optional-dependencies.async-serial + ++ tmodbus.optional-dependencies.smart; + }; + + nativeCheckInputs = [ + pytest-asyncio + pytestCheckHook + ] + ++ lib.concatAttrValues finalAttrs.passthru.optional-dependencies; + + pythonImportsCheck = [ + "modbus_connection" + ]; + + meta = { + description = "Small, backend-neutral Modbus connection abstraction"; + homepage = "https://github.com/home-assistant-libs/modbus-connection"; + changelog = "https://github.com/home-assistant-libs/modbus-connection/releases/tag/${finalAttrs.src.tag}"; + license = lib.licenses.asl20; + maintainers = with lib.maintainers; [ hexa ]; + }; +}) diff --git a/pkgs/development/python-modules/tmodbus/default.nix b/pkgs/development/python-modules/tmodbus/default.nix new file mode 100644 index 000000000000..c2add12f2075 --- /dev/null +++ b/pkgs/development/python-modules/tmodbus/default.nix @@ -0,0 +1,117 @@ +{ + buildPythonPackage, + fetchFromGitHub, + hatchling, + hatch-vcs, + lib, + pytest-asyncio, + pytestCheckHook, + rustPlatform, + serialx, + socat, + tenacity, +}: + +let + version = "0.4.1"; + + src = fetchFromGitHub { + owner = "wlcrs"; + repo = "tmodbus"; + tag = "v${version}"; + hash = "sha256-pVP2QaCYkeeKhlEha7qIyNhbN1DfVyRxTSZBloEMXxc="; + }; + + rmodbus-server = rustPlatform.buildRustPackage (finalAttrs: { + pname = "rmodbus-server"; + version = "0.1.0"; + + inherit src; + + sourceRoot = "${src.name}/integration_tests/rmodbus"; + + cargoHash = "sha256-t7lJ7zC5+z1E/EDWTPR6cbGhcy/RmtXQXon+FiXRZlI="; + + meta = { + description = "Rust Modbus server"; + license = lib.licenses.bsd3; + mainProgram = "server"; + }; + }); + + tokio-modbus-server = rustPlatform.buildRustPackage (finalAttrs: { + pname = "tokio-modbus-server"; + version = "0.1.0"; + + inherit src; + + sourceRoot = "${src.name}/integration_tests/tokio"; + + cargoHash = "sha256-grYnQxf0CH7hkFq1zTMxw6brtHfCheh/O2EtPPPpVqA="; + + meta = { + description = "Rust Tokio Modbus server"; + license = lib.licenses.bsd3; + mainProgram = "tokio-server"; + }; + }); +in + +buildPythonPackage (finalAttrs: { + pname = "tmodbus"; + inherit version src; + pyproject = true; + + __structuredAttrs = true; + + postPatch = '' + substituteInPlace \ + integration_tests/tokio/test_tokio_client.py \ + integration_tests/rmodbus/test_rmodbus_client.py \ + --replace-fail "/usr/bin/socat" "${lib.getExe socat}" + + mkdir -p integration_tests/{rmodbus,tokio}/target/release + ln -s ${lib.getExe' rmodbus-server "ascii-server"} integration_tests/rmodbus/target/release/ + ln -s ${lib.getExe rmodbus-server} integration_tests/rmodbus/target/release/ + ln -s ${lib.getExe tokio-modbus-server} integration_tests/tokio/target/release/ + ''; + + build-system = [ + hatch-vcs + hatchling + ]; + + optional-dependencies = { + async-serial = [ + serialx + ]; + smart = [ + tenacity + ]; + }; + + nativeCheckInputs = [ + pytest-asyncio + pytestCheckHook + ] + ++ lib.concatAttrValues finalAttrs.passthru.optional-dependencies; + + pythonImportsCheck = [ + "tmodbus" + ]; + + passthru = { + inherit rmodbus-server tokio-modbus-server; + }; + + meta = { + description = "Modern Python Modbus library"; + homepage = "https://github.com/wlcrs/tmodbus"; + changelog = "https://github.com/wlcrs/tmodbus/releases/tag/${finalAttrs.src.tag}"; + license = lib.licenses.bsd3; + maintainers = with lib.maintainers; [ hexa ]; + badPlatforms = [ + "aarch64-darwin" # tests fail, no indication they should work + ]; + }; +}) diff --git a/pkgs/top-level/python-packages.nix b/pkgs/top-level/python-packages.nix index 86476eafd4fd..5108c480dd04 100644 --- a/pkgs/top-level/python-packages.nix +++ b/pkgs/top-level/python-packages.nix @@ -10687,6 +10687,8 @@ self: super: with self; { modal = callPackage ../development/python-modules/modal { }; + modbus-connection = callPackage ../development/python-modules/modbus-connection { }; + modbus-tk = callPackage ../development/python-modules/modbus-tk { }; moddb = callPackage ../development/python-modules/moddb { }; @@ -20319,6 +20321,8 @@ self: super: with self; { tmdbsimple = callPackage ../development/python-modules/tmdbsimple { }; + tmodbus = callPackage ../development/python-modules/tmodbus { }; + tnefparse = callPackage ../development/python-modules/tnefparse { }; todoist = callPackage ../development/python-modules/todoist { };