summaryrefslogtreecommitdiff
path: root/pkgs/development/python-modules/pyotb/default.nix
blob: 0728317d43389c15fdbeabe121dd0c6eddd14bcc (plain)
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
{
  lib,
  fetchurl,
  fetchFromGitHub,
  buildPythonPackage,
  python,

  # build-system
  setuptools,

  # dependencies
  otb,

  # tests
  pytestCheckHook,
  pytest-cov-stub,
  requests,
  writableTmpDirAsHomeHook,
}:
let
  # fetch the test data separately or else none of the test will work
  # https://github.com/orfeotoolbox/pyotb/blob/develop/tests/tests_data.py
  spotImage = fetchurl {
    url = "https://gitlab.orfeo-toolbox.org/orfeotoolbox/otb/-/raw/develop/Data/Input/SP67_FR_subset_1.tif";
    sha256 = "sha256-MuWY/g7KI+F23lFY/+AX5MLWJlIgHCr5BvFjDHzpWgY=";
  };

  pleiadesImage = fetchurl {
    url = "https://gitlab.orfeo-toolbox.org/orfeotoolbox/otb/-/raw/develop/Data/Baseline/OTB/Images/prTvOrthoRectification_pleiades-1_noDEM.tif";
    sha256 = "sha256-1EsGAJdHgBIb/gfbh4Y7yEEmYHb54bSx4fEMKssZ/oA=";
  };

  otbWithPy = otb.override {
    enablePython = true;
    python3 = python;
  };
in
buildPythonPackage rec {
  pname = "pyotb";
  version = "2.1.0";
  pyproject = true;

  src = fetchFromGitHub {
    owner = "orfeotoolbox";
    repo = "pyotb";
    tag = version;
    hash = "sha256-KomIMVx4jfsTSbGtoml9ON/82sHanOkp/mp1TiUaa2E=";
  };

  postPatch = ''
    substituteInPlace pyotb/helpers.py \
      --replace-fail 'OTB_ROOT = os.environ.get("OTB_ROOT")' 'OTB_ROOT = "${otbWithPy}"' \
      --replace-fail 'os.environ["GDAL_DATA"] = gdal_data' "" \
      --replace-fail 'os.environ["PROJ_LIB"] = proj_lib' "" \
      --replace-fail 'os.environ["GDAL_DRIVER_PATH"] = "disable"' ""

    ln -s ${spotImage} $HOME/SP67_FR_subset_1.tif
    ln -s ${pleiadesImage} $HOME/prTvOrthoRectification_pleiades-1_noDEM.tif

    substituteInPlace tests/tests_data.py \
      --replace-fail \
        'SPOT_IMG_URL = "https://gitlab.orfeo-toolbox.org/orfeotoolbox/otb/-/raw/develop/Data/Input/SP67_FR_subset_1.tif"' \
        "SPOT_IMG_URL = '$HOME/SP67_FR_subset_1.tif'" \
      --replace-fail \
        'PLEIADES_IMG_URL = "https://gitlab.orfeo-toolbox.org/orfeotoolbox/otb/-/raw/develop/Data/Baseline/OTB/Images/prTvOrthoRectification_pleiades-1_noDEM.tif"' \
        "PLEIADES_IMG_URL = '$HOME/prTvOrthoRectification_pleiades-1_noDEM.tif'"
  '';

  build-system = [
    setuptools
  ];

  dependencies = [ otbWithPy ];

  pythonImportsCheck = [ "pyotb" ];

  nativeCheckInputs = [
    pytestCheckHook
    pytest-cov-stub
    requests
    writableTmpDirAsHomeHook
  ];

  disabledTests = [
    # test requires network access as inputs needs to be url
    "test_app_input_vsi"
    "test_img_metadata"
    "test_summarize_pipeline_simple"
    "test_summarize_pipeline_diamond"
    "test_summarize_strip_output"
  ];

  meta = {
    description = "Python extension of Orfeo Toolbox";
    homepage = "https://github.com/orfeotoolbox/pyotb";
    changelog = "https://github.com/orfeotoolbox/pyotb/releases/tag/${version}";
    license = lib.licenses.asl20;
    teams = [ lib.teams.geospatial ];
    maintainers = with lib.maintainers; [ daspk04 ];
  };
}