1{ lib
2, fetchFromGitHub
3, python3Packages
4, libiconv
5, cargo
6, coursier
7, dotnet-sdk
8, git
9, glibcLocales
10, go
11, nodejs
12, perl
13, testers
14, pre-commit
15}:
16
17with python3Packages;
18buildPythonApplication rec {
19 pname = "pre-commit";
20 version = "3.3.3";
21 format = "setuptools";
22
23 disabled = pythonOlder "3.8";
24
25 src = fetchFromGitHub {
26 owner = "pre-commit";
27 repo = "pre-commit";
28 rev = "v${version}";
29 hash = "sha256-6FKf4jLHUt2c7LSxFcq53IsfHOWeUSI+P9To0eh48+o=";
30 };
31
32 patches = [
33 ./languages-use-the-hardcoded-path-to-python-binaries.patch
34 ./hook-tmpl.patch
35 ];
36
37 propagatedBuildInputs = [
38 cfgv
39 identify
40 nodeenv
41 pyyaml
42 toml
43 virtualenv
44 ];
45
46 nativeCheckInputs = [
47 cargo
48 coursier
49 dotnet-sdk
50 git
51 glibcLocales
52 go
53 libiconv # For rust tests on Darwin
54 nodejs
55 perl
56 pytest-env
57 pytest-forked
58 pytest-xdist
59 pytestCheckHook
60 re-assert
61 ];
62
63 # i686-linux: dotnet-sdk not available
64 doCheck = stdenv.buildPlatform.system != "i686-linux";
65
66 postPatch = ''
67 substituteInPlace pre_commit/resources/hook-tmpl \
68 --subst-var-by pre-commit $out
69 substituteInPlace pre_commit/languages/python.py \
70 --subst-var-by virtualenv ${virtualenv}
71 substituteInPlace pre_commit/languages/node.py \
72 --subst-var-by nodeenv ${nodeenv}
73
74 patchShebangs pre_commit/resources/hook-tmpl
75 '';
76
77 pytestFlagsArray = [
78 "--forked"
79 ];
80
81 preCheck = lib.optionalString (!(stdenv.isLinux && stdenv.isAarch64)) ''
82 # Disable outline atomics for rust tests on aarch64-linux.
83 export RUSTFLAGS="-Ctarget-feature=-outline-atomics"
84 '' + ''
85 export GIT_AUTHOR_NAME=test GIT_COMMITTER_NAME=test \
86 GIT_AUTHOR_EMAIL=test@example.com GIT_COMMITTER_EMAIL=test@example.com \
87 VIRTUALENV_NO_DOWNLOAD=1 PRE_COMMIT_NO_CONCURRENCY=1 LANG=en_US.UTF-8
88
89 # Resolve `.NET location: Not found` errors for dotnet tests
90 export DOTNET_ROOT="${dotnet-sdk}"
91
92 export HOME=$(mktemp -d)
93
94 git init -b master
95
96 python -m venv --system-site-packages venv
97 source "$PWD/venv/bin/activate"
98 '';
99
100 postCheck = ''
101 deactivate
102 '';
103
104 # Propagating dependencies leaks them through $PYTHONPATH which causes issues
105 # when used in nix-shell.
106 postFixup = ''
107 rm $out/nix-support/propagated-build-inputs
108 '';
109
110 disabledTests = [
111 # ERROR: The install method you used for conda--probably either `pip install conda`
112 # or `easy_install conda`--is not compatible with using conda as an application.
113 "test_conda_"
114 "test_local_conda_"
115
116 # /build/pytest-of-nixbld/pytest-0/test_install_ruby_with_version0/rbenv-2.7.2/libexec/rbenv-init:
117 # /usr/bin/env: bad interpreter: No such file or directory
118 "test_ruby_"
119
120 # network
121 "test_additional_dependencies_roll_forward"
122 "test_additional_golang_dependencies_installed"
123 "test_additional_node_dependencies_installed"
124 "test_additional_rust_cli_dependencies_installed"
125 "test_additional_rust_lib_dependencies_installed"
126 "test_coursier_hook"
127 "test_coursier_hook_additional_dependencies"
128 "test_dart"
129 "test_dart_additional_deps"
130 "test_dart_additional_deps_versioned"
131 "test_docker_hook"
132 "test_docker_image_hook_via_args"
133 "test_docker_image_hook_via_entrypoint"
134 "test_golang_default_version"
135 "test_golang_hook"
136 "test_golang_hook_still_works_when_gobin_is_set"
137 "test_golang_infer_go_version_default"
138 "test_golang_system"
139 "test_golang_versioned"
140 "test_language_version_with_rustup"
141 "test_installs_rust_missing_rustup"
142 "test_installs_without_links_outside_env"
143 "test_local_golang_additional_deps"
144 "test_lua"
145 "test_lua_additional_dependencies"
146 "test_node_additional_deps"
147 "test_node_hook_versions"
148 "test_perl_additional_dependencies"
149 "test_r_hook"
150 "test_r_inline"
151 "test_r_inline_hook"
152 "test_r_local_with_additional_dependencies_hook"
153 "test_r_with_additional_dependencies_hook"
154 "test_run_a_node_hook_default_version"
155 "test_run_lib_additional_dependencies"
156 "test_run_versioned_node_hook"
157 "test_rust_cli_additional_dependencies"
158 "test_swift_language"
159
160 # i don't know why these fail
161 "test_install_existing_hooks_no_overwrite"
162 "test_installed_from_venv"
163 "test_uninstall_restores_legacy_hooks"
164 "test_dotnet_"
165
166 # Expects `git commit` to fail when `pre-commit` is not in the `$PATH`,
167 # but we use an absolute path so it's not an issue.
168 "test_environment_not_sourced"
169 ];
170
171 pythonImportsCheck = [
172 "pre_commit"
173 ];
174
175 passthru.tests.version = testers.testVersion {
176 package = pre-commit;
177 };
178
179 meta = with lib; {
180 description = "A framework for managing and maintaining multi-language pre-commit hooks";
181 homepage = "https://pre-commit.com/";
182 license = licenses.mit;
183 maintainers = with maintainers; [ borisbabic ];
184 };
185}