Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at python-updates 91 lines 2.4 kB view raw
1{ 2 lib, 3 stdenv, 4 buildPythonPackage, 5 fetchPypi, 6 7 # build-system 8 hatchling, 9 10 # dependencies 11 click, 12 numpy, 13 onnxruntime, 14 python-dotenv, 15 tabulate, 16 tqdm, 17 18 # tests 19 pytestCheckHook, 20 dacite, 21 versionCheckHook, 22}: 23 24let 25 isNotAarch64Linux = !(stdenv.hostPlatform.isLinux && stdenv.hostPlatform.isAarch64); 26in 27buildPythonPackage (finalAttrs: { 28 pname = "magika"; 29 version = "1.0.1"; 30 pyproject = true; 31 32 # Use pypi tarball instead of GitHub source 33 # Pypi tarball contains a pure python implementation of magika 34 # while GitHub source requires compiling magika-cli 35 src = fetchPypi { 36 inherit (finalAttrs) pname version; 37 hash = "sha256-MT+Mv83Jp+VcJChicyMKJzK4mCXlipPeK1dlMTk7g5g="; 38 }; 39 40 postPatch = '' 41 substituteInPlace tests/test_python_magika_client.py \ 42 --replace-fail 'python_root_dir / "src" / "magika" / "cli" / "magika_client.py"' \ 43 "Path('$out/bin/magika-python-client')" 44 ''; 45 46 build-system = [ hatchling ]; 47 48 dependencies = [ 49 click 50 numpy 51 onnxruntime 52 python-dotenv 53 tabulate 54 tqdm 55 ]; 56 57 nativeCheckInputs = [ 58 pytestCheckHook 59 dacite 60 versionCheckHook 61 ]; 62 63 disabledTests = [ 64 # These tests require test data which doesn't exist in pypi tarball 65 "test_features_extraction_vs_reference" 66 "test_reference_generation" 67 "test_inference_vs_reference" 68 "test_reference_generation" 69 "test_magika_module_with_one_test_file" 70 "test_magika_module_with_explicit_model_dir" 71 "test_magika_module_with_basic" 72 "test_magika_module_with_all_models" 73 "test_magika_module_with_previously_missdetected_samples" 74 ]; 75 76 # aarch64-linux fails cpuinfo test, because /sys/devices/system/cpu/ does not exist in the sandbox: 77 # terminate called after throwing an instance of 'onnxruntime::OnnxRuntimeException' 78 # 79 # -> Skip all tests that require importing magika 80 pythonImportsCheck = lib.optionals isNotAarch64Linux [ "magika" ]; 81 doCheck = isNotAarch64Linux; 82 83 meta = { 84 description = "Detect file content types with deep learning"; 85 homepage = "https://github.com/google/magika"; 86 changelog = "https://github.com/google/magika/blob/python-v${finalAttrs.version}/python/CHANGELOG.md"; 87 license = lib.licenses.asl20; 88 maintainers = with lib.maintainers; [ mihaimaruseac ]; 89 mainProgram = "magika-python-client"; 90 }; 91})