Skip to content

Commit

Permalink
pre-commit: fix import bug for built-in hooks
Browse files Browse the repository at this point in the history
And add regression test.

Closes #270805.

Co-Authored-By: Matt Rixman <[email protected]>
  • Loading branch information
l0b0 and MatrixManAtYrService committed Nov 22, 2024
1 parent ae7c1f0 commit 291e11d
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 8 deletions.
10 changes: 2 additions & 8 deletions pkgs/by-name/pr/pre-commit/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,6 @@ buildPythonApplication rec {
deactivate
'';

# Propagating dependencies leaks them through $PYTHONPATH which causes issues
# when used in nix-shell.
postFixup = ''
rm $out/nix-support/propagated-build-inputs
'';

disabledTests = [
# ERROR: The install method you used for conda--probably either `pip install conda`
# or `easy_install conda`--is not compatible with using conda as an application.
Expand Down Expand Up @@ -182,8 +176,8 @@ buildPythonApplication rec {
"pre_commit"
];

passthru.tests.version = testers.testVersion {
package = pre-commit;
passthru.tests = callPackage ./tests.nix {
inherit git pre-commit;
};

meta = with lib; {
Expand Down
45 changes: 45 additions & 0 deletions pkgs/by-name/pr/pre-commit/tests.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
git,
pre-commit,
runCommand,
testers,
}:
{
check-meta-hooks =
runCommand "check-meta-hooks"
{
nativeBuildInputs = [
git
pre-commit
];
}
''
cd "$(mktemp --directory)"
export HOME="$PWD"
cat << 'EOF' > .pre-commit-config.yaml
repos:
- repo: local
hooks:
- id: echo
name: echo
entry: echo
files: \.yaml$
language: system
- repo: meta
hooks:
- id: check-hooks-apply
- id: check-useless-excludes
- id: identity
EOF
git config --global user.email "[email protected]"
git config --global user.name "Your Name"
git init --initial-branch=main
git add .
pre-commit run --all-files
touch $out
'';

version = testers.testVersion {
package = pre-commit;
};
}

0 comments on commit 291e11d

Please sign in to comment.