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