1{
2 lib,
3 buildPythonPackage,
4 stdenv,
5 fetchFromGitHub,
6 cmake,
7 zlib,
8 pybind11,
9 pytestCheckHook,
10 pytest-cov-stub,
11 pkg-config,
12 setuptools,
13 setuptools-scm,
14 biocutils,
15 biocframe,
16 pandas,
17 scipy,
18}:
19
20buildPythonPackage rec {
21 pname = "rds2py";
22 version = "0.7.3";
23 pyproject = true;
24
25 src = fetchFromGitHub {
26 owner = "BiocPy";
27 repo = "rds2py";
28 tag = version;
29 hash = "sha256-GbRpkt+K2HXuAT7KtI4h1SnZ4RtSo5hrea2L92VZj/o=";
30 };
31
32 rds2cpp-src = fetchFromGitHub {
33 owner = "LTLA";
34 repo = "rds2cpp";
35 rev = "v1.1.0";
36 hash = "sha256-q7C/oORmhgXlqnZnslhyrxBc3RRF2gdgGuQU4TimxtI=";
37 };
38
39 byteme-src = fetchFromGitHub {
40 owner = "LTLA";
41 repo = "byteme";
42 rev = "v1.2.2";
43 hash = "sha256-rM/pSMGlaMWE69lYORaa8SQYGQyzhdyQnXImmAesxFA=";
44 };
45
46 # Upstream uses CMake's FetchContent to download rds2cpp and byteme into
47 # build/_deps at configure time. We pre-fetch both repos and copy them
48 # into build/_deps manually. This way the build tree matches what upstream expects.
49 prePatch = ''
50 mkdir -p build/_deps
51 cp -r ${rds2cpp-src} build/_deps/rds2cpp-src
52 cp -r ${byteme-src} build/_deps/byteme-src
53 chmod -R u+w build/_deps
54 '';
55
56 # Patch upstream CMakeLists.txt files to use our vendored sources instead of
57 # calling FetchContent. We point add_subdirectory() to the copies staged in
58 # build/_deps above. We also patch rds2cpp's own extern/CMakeLists.txt to
59 # disable its nested FetchContent call for byteme, since we already provide it.
60 postPatch = ''
61 substituteInPlace lib/CMakeLists.txt \
62 --replace-fail \
63 "FetchContent_MakeAvailable(byteme)" \
64 "add_subdirectory(\''${CMAKE_BINARY_DIR}/../_deps/byteme-src \''${CMAKE_CURRENT_BINARY_DIR}/byteme)" \
65 --replace-fail \
66 "FetchContent_MakeAvailable(rds2cpp)" \
67 "add_subdirectory(\''${CMAKE_BINARY_DIR}/../_deps/rds2cpp-src \''${CMAKE_CURRENT_BINARY_DIR}/rds2cpp)"
68
69 substituteInPlace build/_deps/rds2cpp-src/extern/CMakeLists.txt \
70 --replace-fail "FetchContent_MakeAvailable(byteme)" "# FetchContent_MakeAvailable(byteme) -- Patched by Nix"
71 '';
72
73 # We use the MORE_CMAKE_OPTIONS environment variable, which is a hook provided
74 # by the upstream setup.py, to pass our zlib flags to the CMake configure step.
75 preConfigure = ''
76 export MORE_CMAKE_OPTIONS="-DZLIB_INCLUDE_DIR=${lib.getDev zlib}/include -DZLIB_LIBRARY=${lib.getLib zlib}/lib/libz.so"
77 '';
78
79 nativeBuildInputs = [
80 cmake
81 pkg-config
82 pybind11
83 zlib
84 ];
85
86 build-system = [
87 setuptools
88 setuptools-scm
89 ];
90
91 dependencies = [
92 biocutils
93 ];
94
95 nativeCheckInputs = [
96 pytest-cov-stub
97 pytestCheckHook
98 biocframe
99 pandas
100 scipy
101 ];
102
103 disabledTestPaths = [
104 # Requires packages not in Nixpkgs
105 "tests/test_delayedmatrices.py"
106 "tests/test_granges.py"
107 "tests/test_mae.py"
108 "tests/test_sce.py"
109 "tests/test_se.py"
110 ];
111
112 # setuptools drives the build, so disable cmake configure hook
113 dontUseCmakeConfigure = true;
114
115 pythonImportsCheck = [ "rds2py" ];
116
117 meta = {
118 description = "Read RDS files, in Python";
119 homepage = "https://github.com/BiocPy/rds2py";
120 license = lib.licenses.mit;
121 maintainers = with lib.maintainers; [ b-rodrigues ];
122 };
123}