1{ lib
2, python3Packages
3, fetchFromGitHub
4 # tests
5, cargo
6, dotnet-sdk
7, git
8, go
9, libiconv
10, nodejs
11}:
12
13with python3Packages;
14buildPythonPackage rec {
15 pname = "pre-commit";
16 version = "2.19.0";
17 format = "setuptools";
18
19 disabled = pythonOlder "3.6";
20
21 src = fetchFromGitHub {
22 owner = "pre-commit";
23 repo = "pre-commit";
24 rev = "v${version}";
25 sha256 = "sha256-5YV0FJhHiq/NJFKYvwddIWUQVxKJpnIJLLNmyY0NX4A=";
26 };
27
28 patches = [
29 ./languages-use-the-hardcoded-path-to-python-binaries.patch
30 ./hook-tmpl.patch
31 ];
32
33 propagatedBuildInputs = [
34 cfgv
35 identify
36 nodeenv
37 pyyaml
38 toml
39 virtualenv
40 ] ++ lib.optional (pythonOlder "3.8") [
41 importlib-metadata
42 ] ++ lib.optional (pythonOlder "3.7") [
43 importlib-resources
44 ];
45
46 checkInputs = [
47 cargo
48 dotnet-sdk
49 git
50 go
51 nodejs
52 pytest-env
53 pytest-xdist
54 pytestCheckHook
55 re-assert
56 ];
57
58 buildInputs = [
59 # Required for rust test on x86_64-darwin
60 libiconv
61 ];
62
63 doCheck = true;
64
65 postPatch = ''
66 substituteInPlace pre_commit/resources/hook-tmpl \
67 --subst-var-by pre-commit $out
68 substituteInPlace pre_commit/languages/python.py \
69 --subst-var-by virtualenv ${virtualenv}
70 substituteInPlace pre_commit/languages/node.py \
71 --subst-var-by nodeenv ${nodeenv}
72
73 patchShebangs pre_commit/resources/hook-tmpl
74 '';
75
76 pytestFlagsArray = [
77 "--forked"
78 ];
79
80 preCheck = ''
81 export GIT_AUTHOR_NAME=test GIT_COMMITTER_NAME=test \
82 GIT_AUTHOR_EMAIL=test@example.com GIT_COMMITTER_EMAIL=test@example.com \
83 VIRTUALENV_NO_DOWNLOAD=1 PRE_COMMIT_NO_CONCURRENCY=1 LANG=en_US.UTF-8
84
85 git init -b master
86
87 export HOME=$(mktemp -d)
88
89 python -m venv --system-site-packages venv
90 source "$PWD/venv/bin/activate"
91 #$out/bin/pre-commit install
92 python setup.py develop
93 '';
94
95 postCheck = ''
96 deactivate
97 '';
98
99 disabledTests = [
100 # ERROR: The install method you used for conda--probably either `pip install conda`
101 # or `easy_install conda`--is not compatible with using conda as an application.
102 "test_conda_"
103 "test_local_conda_"
104
105 # /build/pytest-of-nixbld/pytest-0/test_install_ruby_with_version0/rbenv-2.7.2/libexec/rbenv-init:
106 # /usr/bin/env: bad interpreter: No such file or directory
107 "ruby"
108
109 # network
110 "test_additional_dependencies_roll_forward"
111 "test_additional_golang_dependencies_installed"
112 "test_additional_node_dependencies_installed"
113 "test_additional_rust_cli_dependencies_installed"
114 "test_additional_rust_lib_dependencies_installed"
115 "test_dart_hook"
116 "test_dotnet_hook"
117 "test_golang_hook"
118 "test_golang_hook_still_works_when_gobin_is_set"
119 "test_installs_without_links_outside_env"
120 "test_local_dart_additional_dependencies"
121 "test_local_golang_additional_dependencies"
122 "test_local_lua_additional_dependencies"
123 "test_local_perl_additional_dependencies"
124 "test_local_rust_additional_dependencies"
125 "test_lua_hook"
126 "test_perl_hook"
127 "test_r_hook"
128 "test_r_inline_hook"
129 "test_r_local_with_additional_dependencies_hook"
130 "test_r_with_additional_dependencies_hook"
131 "test_run_a_node_hook_default_version"
132 "test_run_versioned_node_hook"
133
134 # python2, no explanation needed
135 "python2"
136 "test_switch_language_versions_doesnt_clobber"
137
138 # docker
139 "test_run_a_docker_hook"
140
141 # i don't know why these fail
142 "test_install_existing_hooks_no_overwrite"
143 "test_installed_from_venv"
144 "test_uninstall_restores_legacy_hooks"
145 ];
146
147 pythonImportsCheck = [
148 "pre_commit"
149 ];
150
151 meta = with lib; {
152 description = "A framework for managing and maintaining multi-language pre-commit hooks";
153 homepage = "https://pre-commit.com/";
154 license = licenses.mit;
155 maintainers = with maintainers; [ borisbabic ];
156 };
157}