summaryrefslogtreecommitdiffstats
path: root/pkgs/by-name/pr/pre-commit/package.nix
blob: 93de0eb0dfeaa4c76e8484dcbaec28f9fcd2b45a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
{
  lib,
  stdenv,
  python3Packages,
  fetchFromGitHub,

  # tests
  cabal-install,
  cargo,
  gitMinimal,
  go,
  perl,
  versionCheckHook,
  writableTmpDirAsHomeHook,
  coursier,
  dotnet-sdk,
  nodejs,

  # passthru
  callPackage,
  pkgsi686Linux,
  pre-commit,
}:

let
  i686Linux = stdenv.buildPlatform.system == "i686-linux";
in
python3Packages.buildPythonApplication (finalAttrs: {
  pname = "pre-commit";
  version = "4.6.2";
  pyproject = true;

  src = fetchFromGitHub {
    owner = "pre-commit";
    repo = "pre-commit";
    tag = "v${finalAttrs.version}";
    hash = "sha256-aCEN9dVz/3lB2gy7U+6dVj3jSM7cmVsstOp+LHvYRsU=";
  };

  patches = [
    ./languages-use-the-hardcoded-path-to-python-binaries.patch
    ./hook-tmpl.patch
    ./pygrep-pythonpath.patch
  ];

  build-system = with python3Packages; [
    setuptools
  ];

  dependencies = with python3Packages; [
    cfgv
    identify
    nodeenv
    pyyaml
    virtualenv
  ];

  nativeCheckInputs = [
    cabal-install
    cargo
    gitMinimal
    go
    nodejs
    perl
    writableTmpDirAsHomeHook
  ]
  ++ (with python3Packages; [
    pytest-env
    pytest-xdist
    re-assert
  ])
  ++ lib.optionals (!i686Linux) [
    # coursier can be moved back to the main nativeCheckInputs list once we’re able to bootstrap a
    # JRE on i686-linux: <https://github.com/NixOS/nixpkgs/issues/314873>. When coursier gets
    # moved back to the main nativeCheckInputs list, don’t forget to re-enable the
    # coursier-related test that is currently disabled on i686-linux.
    coursier
    # i686-linux: dotnet-sdk not available
    dotnet-sdk
  ];

  nativeInstallCheckInputs = [ versionCheckHook ];

  postPatch = ''
    substituteInPlace pre_commit/resources/hook-tmpl \
      --subst-var-by pre-commit $out
    substituteInPlace pre_commit/languages/python.py \
      --subst-var-by virtualenv ${python3Packages.virtualenv}
    substituteInPlace pre_commit/languages/node.py \
      --subst-var-by nodeenv ${python3Packages.nodeenv}

    patchShebangs pre_commit/resources/hook-tmpl
  '';

  preCheck = ''
    export GIT_AUTHOR_NAME=test GIT_COMMITTER_NAME=test \
           GIT_AUTHOR_EMAIL=test@example.com GIT_COMMITTER_EMAIL=test@example.com \
           PRE_COMMIT_NO_CONCURRENCY=1

    # Some CLI tests expect to run in a Git repository.
    git init
  ''
  + lib.optionalString (!i686Linux) ''
    # Resolve `.NET location: Not found` errors for dotnet tests
    export DOTNET_ROOT="${dotnet-sdk}/share/dotnet"
  '';

  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_language"
    "test_conda_additional_deps"

    # /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
    "test_ruby_"

    # network
    "test_additional_dependencies_roll_forward"
    "test_automatic_toolchain_switching"
    "test_coursier_hook"
    "test_coursier_hook_additional_dependencies"
    "test_dart"
    "test_dart_additional_deps"
    "test_dart_additional_deps_versioned"
    "test_during_commit_all"
    "test_golang_default_version"
    "test_golang_hook"
    "test_golang_hook_still_works_when_gobin_is_set"
    "test_golang_infer_go_version_default"
    "test_golang_system"
    "test_golang_versioned"
    "test_language_version_with_rustup"
    "test_installs_rust_missing_rustup"
    "test_installs_without_links_outside_env"
    "test_julia_hook"
    "test_julia_repo_local"
    "test_local_golang_additional_deps"
    "test_lua"
    "test_lua_additional_dependencies"
    "test_node_additional_deps"
    "test_node_hook_versions"
    "test_npm_install_succeeds_with_build"
    "test_perl_additional_dependencies"
    "test_r_hook"
    "test_r_inline"
    "test_run_lib_additional_dependencies"
    "test_rust_cli_additional_dependencies"
    "test_swift_language"
    "test_run_example_executable"
    "test_run_dep"
    "test_control_c_control_c_on_install"
    "test_healthy_default_creator"
    "test_healthy_venv_creator"
    "test_invalidated_virtualenv"
    "test_language_versioned_python_hook"
    "test_local_python_repo"
    "test_local_repo_with_other_artifacts"
    "test_python_hook_weird_setup_cfg"
    "test_really_long_file_paths"
    "test_reinstall"
    "test_repository_state_compatibility[v1]"
    "test_repository_state_compatibility[v2]"
    "test_simple_python_hook_default_version"
    "test_simple_python_hook"
    "test_unhealthy_old_virtualenv"
    "test_unhealthy_python_goes_missing"
    "test_unhealthy_system_version_changes"
    "test_unhealthy_then_replaced"
    "test_unhealthy_unexpected_pyvenv"
    "test_unhealthy_with_version_change"

    # R required
    "test_health_check_"

    # Expects `git commit` to fail when `pre-commit` is not in the `$PATH`,
    # but we use an absolute path so it's not an issue.
    "test_environment_not_sourced"

    # Docker required
    "test_docker_fallback_user"
    "test_docker_hook"
    "test_docker_image_"
  ]
  ++ lib.optionals stdenv.hostPlatform.isLinux [
    "test_install_existing_hooks_no_overwrite"
    "test_uninstall_restores_legacy_hooks"
  ]
  ++ lib.optionals i686Linux [
    # i686-linux: dotnet-sdk not available
    "test_dotnet_"
    # From coursier_test.py:
    "test_error_if_no_deps_or_channel"
  ];

  pythonImportsCheck = [
    "pre_commit"
  ];

  # add gitMinimal as fallback, if git is not installed
  preFixup = ''
    makeWrapperArgs+=(--suffix PATH : ${lib.makeBinPath [ gitMinimal ]})
  '';

  passthru.tests =
    callPackage ./tests.nix {
      inherit gitMinimal pre-commit;
    }
    // lib.optionalAttrs (stdenv.hostPlatform.system == "x86_64-linux") {
      i686 = pkgsi686Linux.pre-commit;
    };

  meta = {
    description = "Framework for managing and maintaining multi-language pre-commit hooks";
    homepage = "https://pre-commit.com/";
    changelog = "https://github.com/pre-commit/pre-commit/blob/${finalAttrs.src.tag}/CHANGELOG.md";
    license = lib.licenses.mit;
    maintainers = with lib.maintainers; [
      booxter
      borisbabic
      savtrip
    ];
    mainProgram = "pre-commit";
  };
})