1{
2 lib,
3 stdenv,
4 buildPythonPackage,
5 fetchFromGitHub,
6 git,
7 pytestCheckHook,
8 pythonOlder,
9 ruamel-yaml,
10 tomli,
11}:
12
13buildPythonPackage rec {
14 pname = "pre-commit-hooks";
15 version = "4.6.0";
16 format = "setuptools";
17
18 disabled = pythonOlder "3.8";
19
20 src = fetchFromGitHub {
21 owner = "pre-commit";
22 repo = pname;
23 rev = "refs/tags/v${version}";
24 hash = "sha256-p/pPpuuNjVxHSPyi4RL2DJlj9weSq8QinugQ4zmv9Ck=";
25 };
26
27 propagatedBuildInputs = [ ruamel-yaml ] ++ lib.optionals (pythonOlder "3.11") [ tomli ];
28
29 nativeCheckInputs = [
30 git
31 pytestCheckHook
32 ];
33
34 # Note: this is not likely to ever work on Darwin
35 # https://github.com/pre-commit/pre-commit-hooks/pull/655
36 doCheck = !stdenv.isDarwin;
37
38 # the tests require a functional git installation which requires a valid HOME
39 # directory.
40 preCheck = ''
41 export HOME="$(mktemp -d)"
42
43 git config --global user.name "Nix Builder"
44 git config --global user.email "nix-builder@nixos.org"
45 git init .
46 '';
47
48 pythonImportsCheck = [ "pre_commit_hooks" ];
49
50 meta = with lib; {
51 description = "Some out-of-the-box hooks for pre-commit";
52 homepage = "https://github.com/pre-commit/pre-commit-hooks";
53 changelog = "https://github.com/pre-commit/pre-commit-hooks/blob/v${version}/CHANGELOG.md";
54 license = licenses.mit;
55 maintainers = with maintainers; [ kalbasit ];
56 };
57}