summaryrefslogtreecommitdiff
path: root/pkgs/development/python-modules/rds2py/default.nix
blob: b1a62863beab4ba7025427476a7de3c5f40254a0 (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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
{
  lib,
  buildPythonPackage,
  stdenv,
  fetchFromGitHub,
  cmake,
  zlib,
  pybind11,
  pytestCheckHook,
  pytest-cov-stub,
  pkg-config,
  setuptools,
  setuptools-scm,
  biocutils,
  biocframe,
  pandas,
  scipy,
}:

buildPythonPackage rec {
  pname = "rds2py";
  version = "0.7.3";
  pyproject = true;

  src = fetchFromGitHub {
    owner = "BiocPy";
    repo = "rds2py";
    tag = version;
    hash = "sha256-GbRpkt+K2HXuAT7KtI4h1SnZ4RtSo5hrea2L92VZj/o=";
  };

  rds2cpp-src = fetchFromGitHub {
    owner = "LTLA";
    repo = "rds2cpp";
    rev = "v1.1.0";
    hash = "sha256-q7C/oORmhgXlqnZnslhyrxBc3RRF2gdgGuQU4TimxtI=";
  };

  byteme-src = fetchFromGitHub {
    owner = "LTLA";
    repo = "byteme";
    rev = "v1.2.2";
    hash = "sha256-rM/pSMGlaMWE69lYORaa8SQYGQyzhdyQnXImmAesxFA=";
  };

  # Upstream uses CMake's FetchContent to download rds2cpp and byteme into
  # build/_deps at configure time. We pre-fetch both repos and copy them
  # into build/_deps manually. This way the build tree matches what upstream expects.
  prePatch = ''
    mkdir -p build/_deps
    cp -r ${rds2cpp-src} build/_deps/rds2cpp-src
    cp -r ${byteme-src} build/_deps/byteme-src
    chmod -R u+w build/_deps
  '';

  # Patch upstream CMakeLists.txt files to use our vendored sources instead of
  # calling FetchContent. We point add_subdirectory() to the copies staged in
  # build/_deps above. We also patch rds2cpp's own extern/CMakeLists.txt to
  # disable its nested FetchContent call for byteme, since we already provide it.
  postPatch = ''
    substituteInPlace lib/CMakeLists.txt \
      --replace-fail \
        "FetchContent_MakeAvailable(byteme)" \
        "add_subdirectory(\''${CMAKE_BINARY_DIR}/../_deps/byteme-src \''${CMAKE_CURRENT_BINARY_DIR}/byteme)" \
      --replace-fail \
        "FetchContent_MakeAvailable(rds2cpp)" \
        "add_subdirectory(\''${CMAKE_BINARY_DIR}/../_deps/rds2cpp-src \''${CMAKE_CURRENT_BINARY_DIR}/rds2cpp)"

    substituteInPlace build/_deps/rds2cpp-src/extern/CMakeLists.txt \
      --replace-fail "FetchContent_MakeAvailable(byteme)" "# FetchContent_MakeAvailable(byteme) -- Patched by Nix"
  '';

  # We use the MORE_CMAKE_OPTIONS environment variable, which is a hook provided
  # by the upstream setup.py, to pass our zlib flags to the CMake configure step.
  preConfigure = ''
    export MORE_CMAKE_OPTIONS="-DZLIB_INCLUDE_DIR=${lib.getDev zlib}/include -DZLIB_LIBRARY=${lib.getLib zlib}/lib/libz.so"
  '';

  nativeBuildInputs = [
    cmake
    pkg-config
    pybind11
    zlib
  ];

  build-system = [
    setuptools
    setuptools-scm
  ];

  dependencies = [
    biocutils
  ];

  nativeCheckInputs = [
    pytest-cov-stub
    pytestCheckHook
    biocframe
    pandas
    scipy
  ];

  disabledTestPaths = [
    # Requires packages not in Nixpkgs
    "tests/test_delayedmatrices.py"
    "tests/test_granges.py"
    "tests/test_mae.py"
    "tests/test_sce.py"
    "tests/test_se.py"
  ];

  # setuptools drives the build, so disable cmake configure hook
  dontUseCmakeConfigure = true;

  pythonImportsCheck = [ "rds2py" ];

  meta = {
    description = "Read RDS files, in Python";
    homepage = "https://github.com/BiocPy/rds2py";
    license = lib.licenses.mit;
    maintainers = with lib.maintainers; [ b-rodrigues ];
  };
}