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