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