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