about summary refs log tree commit diff
path: root/pkgs/development/tools/backblaze-b2/default.nix
blob: fadd6a2d4f76dad9421a517e7f058c4588ac8dfb (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
{ lib
, python3Packages
, fetchFromGitHub
, installShellFiles
, testers
, backblaze-b2
# executable is renamed to backblaze-b2 by default, to avoid collision with boost's 'b2'
, execName ? "backblaze-b2"
}:

python3Packages.buildPythonApplication rec {
  pname = "backblaze-b2";
  version = "3.18.0";
  pyproject = true;

  src = fetchFromGitHub {
    owner = "Backblaze";
    repo = "B2_Command_Line_Tool";
    rev = "refs/tags/v${version}";
    hash = "sha256-1UXByc3jjp8GN7+aI2GBohJ0DFxgp604QOsXp5GaL4Q=";
  };

  nativeBuildInputs = [
    installShellFiles
  ];

  build-system = with python3Packages; [
    pdm-backend
  ];

  dependencies = with python3Packages; [
    argcomplete
    arrow
    b2sdk
    phx-class-registry
    docutils
    rst2ansi
    tabulate
    tqdm
    platformdirs
    packaging
    setuptools
  ];

  nativeCheckInputs = with python3Packages; [
    backoff
    more-itertools
    pexpect
    pytestCheckHook
    pytest-xdist
  ];

  preCheck = ''
    export HOME=$(mktemp -d)
  '';

  disabledTestPaths = [
    # Test requires network
    "test/integration/test_b2_command_line.py"
    "test/integration/test_tqdm_closer.py"
    # it's hard to make it work on nix
    "test/integration/test_autocomplete.py"
    "test/unit/test_console_tool.py"
    # this one causes successive tests to fail
    "test/unit/_cli/test_autocomplete_cache.py"
  ];

  disabledTests = [
    # Autocomplete is not successful in a sandbox
    "test_autocomplete_installer"
    "test_help"
    "test_install_autocomplete"
  ];

  postInstall = lib.optionalString (execName != "b2") ''
    mv "$out/bin/b2" "$out/bin/${execName}"
  ''
  + ''
    installShellCompletion --cmd ${execName} \
      --bash <(${python3Packages.argcomplete}/bin/register-python-argcomplete ${execName}) \
      --zsh <(${python3Packages.argcomplete}/bin/register-python-argcomplete ${execName})
  '';

  passthru.tests.version = (testers.testVersion {
    package = backblaze-b2;
    command = "${execName} version --short";
  }).overrideAttrs (old: {
    # workaround the error: Permission denied: '/homeless-shelter'
    # backblaze-b2 fails to create a 'b2' directory under the XDG config path
    preHook = ''
      export HOME=$(mktemp -d)
    '';
  });

  meta = with lib; {
    description = "Command-line tool for accessing the Backblaze B2 storage service";
    homepage = "https://github.com/Backblaze/B2_Command_Line_Tool";
    changelog = "https://github.com/Backblaze/B2_Command_Line_Tool/blob/v${version}/CHANGELOG.md";
    license = licenses.mit;
    maintainers = with maintainers; [ hrdinka tomhoule ];
    mainProgram = "backblaze-b2";
  };
}