1{ 2 lib, 3 stdenv, 4 buildPythonPackage, 5 6 # build-system 7 pybind11, 8 setuptools, 9 10 # dependencies 11 ctranslate2-cpp, 12 numpy, 13 pyyaml, 14 15 # tests 16 pytestCheckHook, 17 torch, 18 transformers, 19 writableTmpDirAsHomeHook, 20 wurlitzer, 21}: 22 23buildPythonPackage rec { 24 inherit (ctranslate2-cpp) pname version src; 25 pyproject = true; 26 27 # https://github.com/OpenNMT/CTranslate2/tree/master/python 28 sourceRoot = "${src.name}/python"; 29 30 build-system = [ 31 pybind11 32 setuptools 33 ]; 34 35 buildInputs = [ ctranslate2-cpp ]; 36 37 dependencies = [ 38 numpy 39 pyyaml 40 ]; 41 42 pythonImportsCheck = [ 43 # https://opennmt.net/CTranslate2/python/overview.html 44 "ctranslate2" 45 "ctranslate2.converters" 46 "ctranslate2.models" 47 "ctranslate2.specs" 48 ]; 49 50 nativeCheckInputs = [ 51 pytestCheckHook 52 torch 53 transformers 54 writableTmpDirAsHomeHook 55 wurlitzer 56 ]; 57 58 preCheck = '' 59 # run tests against build result, not sources 60 rm -rf ctranslate2 61 ''; 62 63 disabledTests = lib.optionals stdenv.hostPlatform.isDarwin [ 64 # Fatal Python error: Aborted 65 "test_invalid_model_path" 66 ]; 67 68 disabledTestPaths = [ 69 # TODO: ModuleNotFoundError: No module named 'opennmt' 70 "tests/test_opennmt_tf.py" 71 # OSError: We couldn't connect to 'https://huggingface.co' to load this file 72 "tests/test_transformers.py" 73 ]; 74 75 meta = { 76 description = "Fast inference engine for Transformer models"; 77 homepage = "https://github.com/OpenNMT/CTranslate2"; 78 changelog = "https://github.com/OpenNMT/CTranslate2/blob/${src.rev}/CHANGELOG.md"; 79 license = lib.licenses.mit; 80 maintainers = with lib.maintainers; [ hexa ]; 81 }; 82}