From 69d78abdb885134bc339a89faa038dde99412f34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nils=20Andr=C3=A9?= Date: Wed, 27 Dec 2023 19:43:44 -0800 Subject: [PATCH] pre-commit: fix pygrep hooks Fixes https://github.com/NixOS/nixpkgs/issues/173707 --- pkgs/tools/misc/pre-commit/default.nix | 1 + pkgs/tools/misc/pre-commit/pygrep-pythonpath.patch | 13 +++++++++++++ 2 files changed, 14 insertions(+) create mode 100644 pkgs/tools/misc/pre-commit/pygrep-pythonpath.patch diff --git a/pkgs/tools/misc/pre-commit/default.nix b/pkgs/tools/misc/pre-commit/default.nix index ded7b3290d3c..56afc22f19ea 100644 --- a/pkgs/tools/misc/pre-commit/default.nix +++ b/pkgs/tools/misc/pre-commit/default.nix @@ -32,6 +32,7 @@ buildPythonApplication rec { patches = [ ./languages-use-the-hardcoded-path-to-python-binaries.patch ./hook-tmpl.patch + ./pygrep-pythonpath.patch ]; propagatedBuildInputs = [ diff --git a/pkgs/tools/misc/pre-commit/pygrep-pythonpath.patch b/pkgs/tools/misc/pre-commit/pygrep-pythonpath.patch new file mode 100644 index 000000000000..722b436169be --- /dev/null +++ b/pkgs/tools/misc/pre-commit/pygrep-pythonpath.patch @@ -0,0 +1,13 @@ +diff --git a/pre_commit/languages/pygrep.py b/pre_commit/languages/pygrep.py +index ec55560..44e08a1 100644 +--- a/pre_commit/languages/pygrep.py ++++ b/pre_commit/languages/pygrep.py +@@ -98,7 +98,7 @@ def run_hook( + color: bool, + ) -> tuple[int, bytes]: + cmd = (sys.executable, '-m', __name__, *args, entry) +- return xargs(cmd, file_args, color=color) ++ return xargs(cmd, file_args, color=color, env={ "PYTHONPATH": ':'.join(sys.path) }) + + + def main(argv: Sequence[str] | None = None) -> int: