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