1{
2 lib,
3 buildPythonPackage,
4 fetchFromGitHub,
5 substituteAll,
6 cmdstan,
7 setuptools,
8 pandas,
9 numpy,
10 tqdm,
11 stanio,
12 xarray,
13 pytestCheckHook,
14 stdenv,
15}:
16
17buildPythonPackage rec {
18 pname = "cmdstanpy";
19 version = "1.2.4";
20 pyproject = true;
21
22 src = fetchFromGitHub {
23 owner = "stan-dev";
24 repo = "cmdstanpy";
25 rev = "refs/tags/v${version}";
26 hash = "sha256-SKDqLvWbzaBcL13E87kcphBJNIZfdkPp2g4SIDEKA0U=";
27 };
28
29 patches = [
30 (substituteAll {
31 src = ./use-nix-cmdstan-path.patch;
32 cmdstan = "${cmdstan}/opt/cmdstan";
33 })
34 ];
35
36 postPatch = ''
37 # conftest.py would have used git to clean up, which is unnecessary here
38 rm test/conftest.py
39 '';
40
41 nativeBuildInputs = [
42 setuptools
43 ];
44
45 propagatedBuildInputs = [
46 pandas
47 numpy
48 tqdm
49 stanio
50 ];
51
52 passthru.optional-dependencies = {
53 all = [ xarray ];
54 };
55
56 pythonRelaxDeps = [ "stanio" ];
57
58 preCheck = ''
59 export HOME=$(mktemp -d)
60 '';
61
62 nativeCheckInputs = [ pytestCheckHook ] ++ passthru.optional-dependencies.all;
63
64 disabledTestPaths = [
65 # No need to test these when using Nix
66 "test/test_install_cmdstan.py"
67 "test/test_cxx_installation.py"
68 ];
69
70 disabledTests =
71 [
72 "test_serialization" # Pickle class mismatch errors
73 # These tests use the flag -DSTAN_THREADS which doesn't work in cmdstan (missing file)
74 "test_multi_proc_threads"
75 "test_compile_force"
76 # These tests require a writeable cmdstan source directory
77 "test_pathfinder_threads"
78 "test_save_profile"
79 ]
80 ++ lib.optionals stdenv.isDarwin [
81 "test_init_types" # CmdStan error: error during processing Operation not permitted
82 ];
83
84 pythonImportsCheck = [ "cmdstanpy" ];
85
86 meta = {
87 homepage = "https://github.com/stan-dev/cmdstanpy";
88 description = "Lightweight interface to Stan for Python users";
89 changelog = "https://github.com/stan-dev/cmdstanpy/releases/tag/v${version}";
90 license = lib.licenses.bsd3;
91 maintainers = with lib.maintainers; [ tomasajt ];
92 };
93}