pre-commit: enable tests

used arch and openSUSE packages for reference
This commit is contained in:
Artturin 2022-04-04 22:28:00 +03:00 committed by Jonathan Ringer
parent 6edf36f81c
commit d90f4d5030

View file

@ -1,4 +1,13 @@
{ lib, python3Packages }:
{ lib
, python3Packages
, fetchFromGitHub
# tests
, cargo
, dotnet-sdk
, git
, go
, nodejs
}:
with python3Packages;
buildPythonPackage rec {
@ -8,10 +17,11 @@ buildPythonPackage rec {
disabled = pythonOlder "3.6";
src = fetchPypi {
inherit version;
pname = "pre_commit";
sha256 = "sha256-XURe4fqHONUGiBxdhPg8Yrtb5rKDjjIgdDNkfo5evhA=";
src = fetchFromGitHub {
owner = "pre-commit";
repo = "pre-commit";
rev = "v${version}";
sha256 = "sha256-d/ukUTjNgpqr6IeDJHDaOXQm0EdsX+vq0sVX7HG3gSE=";
};
patches = [
@ -32,18 +42,103 @@ buildPythonPackage rec {
importlib-resources
];
# slow and impure
doCheck = false;
checkInputs = [
cargo
dotnet-sdk
git
go
nodejs
pytest-env
pytest-xdist
pytestCheckHook
re-assert
];
preFixup = ''
substituteInPlace $out/${python.sitePackages}/pre_commit/resources/hook-tmpl \
doCheck = true;
postPatch = ''
substituteInPlace pre_commit/resources/hook-tmpl \
--subst-var-by pre-commit $out
substituteInPlace $out/${python.sitePackages}/pre_commit/languages/python.py \
substituteInPlace pre_commit/languages/python.py \
--subst-var-by virtualenv ${virtualenv}
substituteInPlace $out/${python.sitePackages}/pre_commit/languages/node.py \
substituteInPlace pre_commit/languages/node.py \
--subst-var-by nodeenv ${nodeenv}
patchShebangs pre_commit/resources/hook-tmpl
'';
pytestFlagsArray = [
"--numprocesses $NIX_BUILD_CORES"
"--forked"
];
preCheck = ''
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
git init -b master
export HOME=$(mktemp -d)
python -m venv --system-site-packages venv
source "$PWD/venv/bin/activate"
#$out/bin/pre-commit install
python setup.py develop
'';
postCheck = ''
deactivate
'';
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.
"test_conda_"
"test_local_conda_"
# /build/pytest-of-nixbld/pytest-0/test_install_ruby_with_version0/rbenv-2.7.2/libexec/rbenv-init:
# /usr/bin/env: bad interpreter: No such file or directory
"ruby"
# network
"test_additional_dependencies_roll_forward"
"test_additional_golang_dependencies_installed"
"test_additional_node_dependencies_installed"
"test_additional_rust_cli_dependencies_installed"
"test_additional_rust_lib_dependencies_installed"
"test_dart_hook"
"test_dotnet_hook"
"test_golang_hook"
"test_golang_hook_still_works_when_gobin_is_set"
"test_installs_without_links_outside_env"
"test_local_dart_additional_dependencies"
"test_local_golang_additional_dependencies"
"test_local_lua_additional_dependencies"
"test_local_perl_additional_dependencies"
"test_local_rust_additional_dependencies"
"test_lua_hook"
"test_perl_hook"
"test_r_hook"
"test_r_inline_hook"
"test_r_local_with_additional_dependencies_hook"
"test_r_with_additional_dependencies_hook"
"test_run_a_node_hook_default_version"
"test_run_versioned_node_hook"
# python2, no explanation needed
"python2"
"test_switch_language_versions_doesnt_clobber"
# docker
"test_run_a_docker_hook"
# i don't know why these fail
"test_install_existing_hooks_no_overwrite"
"test_installed_from_venv"
"test_uninstall_restores_legacy_hooks"
];
pythonImportsCheck = [
"pre_commit"
];