1{ 2 lib, 3 stdenv, 4 buildPythonPackage, 5 fetchFromGitHub, 6 7 # build-system 8 cargo, 9 pkg-config, 10 rustPlatform, 11 rustc, 12 13 # buildInputs 14 oniguruma, 15 openssl, 16 17 # tests 18 pytestCheckHook, 19 torch, 20 transformers, 21 pythonOlder, 22}: 23 24buildPythonPackage rec { 25 pname = "llguidance"; 26 version = "0.7.19"; 27 pyproject = true; 28 29 src = fetchFromGitHub { 30 owner = "guidance-ai"; 31 repo = "llguidance"; 32 tag = "v${version}"; 33 hash = "sha256-tfTiut8jiGGf2uQLGcC4ieNf4ePFauJZL6vNbWie078="; 34 }; 35 36 cargoDeps = rustPlatform.fetchCargoVendor { 37 inherit src; 38 hash = "sha256-I1sjkZgtsBpPVkGL596TjLi9txRmgP5oTIWaM1K5I1E="; 39 }; 40 41 build-system = [ 42 cargo 43 pkg-config 44 rustPlatform.cargoSetupHook 45 rustPlatform.maturinBuildHook 46 rustc 47 ]; 48 49 buildInputs = [ 50 oniguruma 51 openssl 52 ]; 53 54 env = { 55 RUSTONIG_SYSTEM_LIBONIG = true; 56 }; 57 58 pythonImportsCheck = [ 59 "llguidance" 60 "llguidance._lib" 61 ]; 62 63 nativeCheckInputs = [ 64 pytestCheckHook 65 torch 66 transformers 67 ]; 68 69 # Prevent python from loading the package from $src instead of the $out 70 preCheck = '' 71 rm -r python/llguidance 72 ''; 73 74 disabledTests = 75 [ 76 # Require internet access (https://huggingface.co) 77 "test_grammar" 78 "test_incomplete_tokenizer" 79 "test_par_errors" 80 "test_par_grammar" 81 "test_tokenize_partial_basic" 82 "test_tokenize_partial_docs" 83 ] 84 ++ lib.optionals stdenv.hostPlatform.isDarwin [ 85 # torch._inductor.exc.CppCompileError: C++ compile error 86 # OpenMP support not found. 87 "test_mask_data_torch" 88 ]; 89 90 disabledTestPaths = [ 91 # Require internet access (https://huggingface.co) 92 "scripts/tokenizer_test.py" 93 ]; 94 95 # As dynamo is not supported on Python 3.13+, no successful tests remain. 96 doCheck = pythonOlder "3.13"; 97 98 meta = { 99 description = "Super-fast Structured Outputs"; 100 homepage = "https://github.com/guidance-ai/llguidance"; 101 changelog = "https://github.com/guidance-ai/llguidance/blob/v${version}/CHANGELOG.md"; 102 license = lib.licenses.mit; 103 maintainers = with lib.maintainers; [ GaetanLepage ]; 104 }; 105}