Merge pull request #307098 from r-ryantm/auto-update/cilium-cli
[NixPkgs.git] / pkgs / development / python-modules / gfal2-util / default.nix
blob2aabf3b43e88da9db170e199142e0e0323c1d683
1 { lib
2 , buildPythonPackage
3 , callPackage
4 , fetchFromGitHub
5 , runCommandLocal
6   # Build inputs
7 , gfal2-python
8   # For tests
9 , xrootd # pkgs.xrootd
11 (buildPythonPackage rec {
12   pname = "gfal2-util";
13   version = "1.8.1";
14   src = fetchFromGitHub {
15     owner = "cern-fts";
16     repo = "gfal2-util";
17     rev = "v${version}";
18     hash = "sha256-3JbJgKD17aYkrB/aaww7IQU8fLFrTCh868KWlLPxmlk=";
19   };
21   # Replace the ad-hoc python executable finding
22   # and change the shebangs from `#!/bin/sh` to `#!/usr/bin/env python`
23   # for fixup phase to work correctly.
24   postPatch = ''
25     for script in src/gfal-*; do
26       patch "$script" ${./gfal-util-script.patch}
27     done
28   '';
30   propagatedBuildInputs = [
31     gfal2-python
32   ];
34   pythonImportsCheck = [
35     "gfal2_util"
36   ];
38   meta = with lib; {
39     description = "CLI for gfal2";
40     homepage = "https://github.com/cern-fts/gfal2-utils";
41     license = licenses.asl20;
42     maintainers = with maintainers; [ ShamrockLee ];
43   };
44 }).overrideAttrs (finalAttrs: previousAttrs: lib.recursiveUpdate previousAttrs {
45   passthru = {
46     inherit (gfal2-python) gfal2;
48     fetchGfal2 = lib.makeOverridable (callPackage ./fetchgfal2.nix { gfal2-util = finalAttrs.finalPackage; });
50     # With these functionality tests, it should be safe to merge version bumps once all the tests are passed.
51     tests =
52       let
53         # Use the the bin output hash of gfal2-util as version to ensure that
54         # the test gets rebuild everytime gfal2-util gets rebuild
55         versionFODTests = finalAttrs.version + "-" + lib.substring (lib.stringLength builtins.storeDir + 1) 32 "${self}";
56         self = finalAttrs.finalPackage;
57       in
58       lib.optionalAttrs gfal2-python.gfal2.enablePluginStatus.xrootd (
59         let
60           # Test against a real-world dataset from CERN Open Data
61           # borrowed from `xrootd.tests`.
62           urlTestFile = xrootd.tests.test-xrdcp.url;
63           hashTestFile = xrootd.tests.test-xrdcp.outputHash;
64           urlTestDir = dirOf urlTestFile;
65         in
66         {
67           test-copy-file-xrootd = finalAttrs.passthru.fetchGfal2 {
68             url = urlTestFile;
69             hash = hashTestFile;
70             extraGfalCopyFlags = [ "--verbose" ];
71             pname = "gfal2-util-test-copy-file-xrootd";
72             version = versionFODTests;
73             allowSubstitutes = false;
74           };
76           test-copy-dir-xrootd = finalAttrs.passthru.fetchGfal2 {
77             url = urlTestDir;
78             hash = "sha256-vOahIhvx1oE9sfkqANMGUvGeLHS737wyfYWo4rkvrxw=";
79             recursive = true;
80             extraGfalCopyFlags = [ "--verbose" ];
81             pname = "gfal2-util-test-copy-dir-xrootd";
82             version = versionFODTests;
83             allowSubstitutes = false;
84           };
86           test-ls-dir-xrootd = (runCommandLocal "test-gfal2-util-ls-dir-xrootd" { } ''
87             set -eu -o pipefail
88             gfal-ls "$url" | grep "$baseNameExpected" | tee "$out"
89           '').overrideAttrs (finalAttrs: previousAttrs: {
90             pname = previousAttrs.name;
91             version = versionFODTests;
92             name = "${finalAttrs.pname}-${finalAttrs.version}";
93             nativeBuildInputs = [ self ];
94             url = urlTestDir;
95             baseNameExpected = baseNameOf urlTestFile;
96             outputHashMode = "flat";
97             outputHashAlgo = "sha256";
98             outputHash = builtins.hashString finalAttrs.outputHashAlgo (finalAttrs.baseNameExpected + "\n");
99           });
100         }
101       );
102   };