pre-commit: fix meta hooks (#306444)

This commit is contained in:
Guillaume Girol 2024-11-23 17:55:22 +01:00 committed by GitHub
commit 2911adffc7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 79 additions and 37 deletions

View File

@ -1,18 +1,19 @@
{ lib
, fetchFromGitHub
, python3Packages
, libiconv
, cargo
, coursier
, dotnet-sdk
, git
, glibcLocales
, go
, nodejs
, perl
, cabal-install
, testers
, pre-commit
{
lib,
fetchFromGitHub,
python3Packages,
libiconv,
cargo,
coursier,
dotnet-sdk,
git,
glibcLocales,
go,
nodejs,
perl,
cabal-install,
testers,
pre-commit,
}:
with python3Packages;
@ -81,10 +82,12 @@ buildPythonApplication rec {
"--forked"
];
preCheck = lib.optionalString (!(stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isAarch64)) ''
preCheck =
lib.optionalString (!(stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isAarch64)) ''
# Disable outline atomics for rust tests on aarch64-linux.
export RUSTFLAGS="-Ctarget-feature=-outline-atomics"
'' + ''
''
+ ''
export GIT_AUTHOR_NAME=test GIT_COMMITTER_NAME=test \
GIT_AUTHOR_EMAIL=test@example.com GIT_COMMITTER_EMAIL=test@example.com \
VIRTUALENV_NO_DOWNLOAD=1 PRE_COMMIT_NO_CONCURRENCY=1 LANG=en_US.UTF-8
@ -104,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.
@ -179,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; {

View File

@ -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 "you@example.com"
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;
};
}