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