From 98ffc65cb1576cbbe61fae1139752c3a42ba74be Mon Sep 17 00:00:00 2001 From: kiskaadee Date: Sun, 15 Nov 2026 12:11:53 -0500 Subject: [PATCH] build(nix): deduplicate runtime/test deps and add pre-commit check hook - flake.nix: extract shared runtimeDeps and testDeps lists for packages.default (with pytestCheckHook) and devShells.default, and configure git core.hooksPath in shellHook - .githooks/pre-commit: run ruff check, pyright, pytest, and nix flake check before each commit --- .githooks/pre-commit | 12 ++++++++++++ flake.nix | 26 ++++++++++++++++---------- 2 files changed, 28 insertions(+), 10 deletions(-) create mode 100755 .githooks/pre-commit diff --git a/.githooks/pre-commit b/.githooks/pre-commit new file mode 100755 index 0000000..0d5b515 --- /dev/null +++ b/.githooks/pre-commit @@ -0,0 +1,12 @@ +#!/usr/bin/env bash +set -euo pipefail + +if command -v ruff >/dev/null 2>&1 && command -v pyright >/dev/null 2>&1 && command -v pytest >/dev/null 2>&1; then + ruff check . + pyright + pytest +else + nix develop --command bash -c "ruff check . && pyright && pytest" +fi + +nix flake check diff --git a/flake.nix b/flake.nix index a4a2566..23f12c2 100644 --- a/flake.nix +++ b/flake.nix @@ -9,29 +9,32 @@ let system = "x86_64-linux"; pkgs = import nixpkgs { inherit system; }; - pythonEnv = pkgs.python3.withPackages (ps: [ + ps = pkgs.python3Packages; + + runtimeDeps = [ ps.websockets ps.mcp ps.asyncssh ps.uvicorn + ]; + + testDeps = [ ps.httpx ps.pytest ps.pytest-asyncio - ]); + ]; + + pythonEnv = pkgs.python3.withPackages (_: runtimeDeps ++ testDeps); in { - packages.${system}.default = pkgs.python3Packages.buildPythonApplication { + packages.${system}.default = ps.buildPythonApplication { pname = "lg-smtv-mcp"; version = "0.1.0"; src = ./.; pyproject = true; - build-system = [ pkgs.python3Packages.setuptools ]; - dependencies = with pkgs.python3Packages; [ - websockets - mcp - asyncssh - uvicorn - ]; + build-system = [ ps.setuptools ]; + dependencies = runtimeDeps; + nativeCheckInputs = [ ps.pytestCheckHook ] ++ testDeps; }; devShells.${system}.default = pkgs.mkShell { @@ -42,6 +45,9 @@ ]; shellHook = '' export PYTHONPATH="$PWD/src:${PYTHONPATH:-}" + if [ -d .git ] && [ -d .githooks ]; then + git config core.hooksPath .githooks + fi ''; }; };