1{
2 lib,
3 commitizen,
4 fetchFromGitHub,
5 buildPythonPackage,
6 git,
7 pythonOlder,
8 stdenv,
9 installShellFiles,
10 poetry-core,
11 nix-update-script,
12 testers,
13 argcomplete,
14 charset-normalizer,
15 colorama,
16 decli,
17 importlib-metadata,
18 jinja2,
19 packaging,
20 pyyaml,
21 questionary,
22 termcolor,
23 tomlkit,
24 py,
25 pytest-freezer,
26 pytest-mock,
27 pytest-regressions,
28 pytest7CheckHook,
29 deprecated,
30}:
31
32buildPythonPackage rec {
33 pname = "commitizen";
34 version = "4.0.0";
35 pyproject = true;
36
37 disabled = pythonOlder "3.8";
38
39 src = fetchFromGitHub {
40 owner = "commitizen-tools";
41 repo = "commitizen";
42 rev = "refs/tags/v${version}";
43 hash = "sha256-M6JoBVst2aJwxr/SyMpXXOnMKIl9gX0ltg3H0SpU7uQ=";
44 };
45
46 pythonRelaxDeps = [
47 "argcomplete"
48 "decli"
49 ];
50
51 build-system = [ poetry-core ];
52
53 nativeBuildInputs = [ installShellFiles ];
54
55 dependencies = [
56 argcomplete
57 charset-normalizer
58 colorama
59 decli
60 importlib-metadata
61 jinja2
62 packaging
63 pyyaml
64 questionary
65 termcolor
66 tomlkit
67 ];
68
69 nativeCheckInputs = [
70 argcomplete
71 deprecated
72 git
73 py
74 pytest-freezer
75 pytest-mock
76 pytest-regressions
77 pytest7CheckHook
78 ];
79
80 pythonImportsCheck = [ "commitizen" ];
81
82 # The tests require a functional git installation
83 # which requires a valid HOME directory.
84 preCheck = ''
85 export HOME="$(mktemp -d)"
86
87 git config --global user.name "Nix Builder"
88 git config --global user.email "nix-builder@nixos.org"
89 git init .
90 '';
91
92 # NB: These tests require complex GnuPG setup
93 disabledTests = [
94 "test_bump_minor_increment_signed"
95 "test_bump_minor_increment_signed_config_file"
96 "test_bump_on_git_with_hooks_no_verify_enabled"
97 "test_bump_on_git_with_hooks_no_verify_disabled"
98 "test_bump_pre_commit_changelog"
99 "test_bump_pre_commit_changelog_fails_always"
100 "test_get_commits_with_signature"
101 # fatal: not a git repository (or any of the parent directories): .git
102 "test_commitizen_debug_excepthook"
103 ];
104
105 postInstall =
106 let
107 register-python-argcomplete = lib.getExe' argcomplete "register-python-argcomplete";
108 in
109 lib.optionalString (stdenv.buildPlatform.canExecute stdenv.hostPlatform) ''
110 installShellCompletion --cmd cz \
111 --bash <(${register-python-argcomplete} --shell bash $out/bin/cz) \
112 --zsh <(${register-python-argcomplete} --shell zsh $out/bin/cz) \
113 --fish <(${register-python-argcomplete} --shell fish $out/bin/cz)
114 '';
115
116 passthru = {
117 updateScript = nix-update-script { };
118 tests.version = testers.testVersion {
119 package = commitizen;
120 command = "cz version";
121 };
122 };
123
124 meta = with lib; {
125 description = "Tool to create committing rules for projects, auto bump versions, and generate changelogs";
126 homepage = "https://github.com/commitizen-tools/commitizen";
127 changelog = "https://github.com/commitizen-tools/commitizen/blob/v${version}/CHANGELOG.md";
128 license = licenses.mit;
129 mainProgram = "cz";
130 maintainers = with maintainers; [
131 lovesegfault
132 anthonyroussel
133 ];
134 };
135}