Merge pull request #268619 from tweag/lib-descriptions
[NixPkgs.git] / pkgs / development / python-modules / piano-transcription-inference / default.nix
blobbe46384649be31f8fce658e92959ffdda17bb184
1 { stdenv
2 , lib
3 , buildPythonPackage
4 , fetchPypi
5 , fetchpatch
6 , fetchurl
7 , librosa
8 , matplotlib
9 , mido
10 , torch
11 , torchlibrosa
14 buildPythonPackage rec {
15   pname = "piano-transcription-inference";
16   version = "0.0.5";
17   format = "setuptools";
19   src = fetchPypi {
20     inherit pname version;
21     hash = "sha256-nbhuSkXuWrekFxwdNHaspuag+3K1cKwq90IpATBpWPY=";
22   };
24   checkpoint = fetchurl {
25     name = "piano-transcription-inference.pth";
26     # The download url can be found in
27     # https://github.com/qiuqiangkong/piano_transcription_inference/blob/master/piano_transcription_inference/inference.py
28     url = "https://zenodo.org/record/4034264/files/CRNN_note_F1%3D0.9677_pedal_F1%3D0.9186.pth?download=1";
29     hash = "sha256-w/qXMHJb9Kdi8cFLyAzVmG6s2gGwJvWkolJc1geHYUE=";
30   };
32   propagatedBuildInputs = [
33     librosa
34     matplotlib
35     mido
36     torch
37     torchlibrosa
38   ];
40   patches = [
41     # Fix run against librosa 0.10.0
42     # https://github.com/qiuqiangkong/piano_transcription_inference/pull/14
43     (fetchpatch {
44       url = "https://github.com/qiuqiangkong/piano_transcription_inference/commit/b2d448916be771cd228f709c23c474942008e3e8.patch";
45       hash = "sha256-8O4VtFij//k3fhcbMRz4J8Iz4AdOPLkuk3UTxuCSy8U=";
46     })
47     (fetchpatch {
48       url = "https://github.com/qiuqiangkong/piano_transcription_inference/commit/61443632dc5ea69a072612b6fa3f7da62c96b72c.patch";
49       hash = "sha256-I9+Civ95BnPUX0WQhTU/pGQruF5ctIgkIdxCK+xO3PE=";
50     })
51   ];
53   postPatch = ''
54     substituteInPlace piano_transcription_inference/inference.py --replace \
55       "checkpoint_path='{}/piano_transcription_inference_data/note_F1=0.9677_pedal_F1=0.9186.pth'.format(str(Path.home()))" \
56       "checkpoint_path='$out/share/checkpoint.pth'"
57   '';
59   postInstall = ''
60     mkdir "$out/share"
61     ln -s "${checkpoint}" "$out/share/checkpoint.pth"
62   '';
64   # Project has no tests.
65   # In order to make pythonImportsCheck work, NUMBA_CACHE_DIR env var need to
66   # be set to a writable dir (https://github.com/numba/numba/issues/4032#issuecomment-488102702).
67   # pythonImportsCheck has no pre* hook, use checkPhase to wordaround that.
68   checkPhase = ''
69     export NUMBA_CACHE_DIR="$(mktemp -d)"
70   '';
71   pythonImportsCheck = [ "piano_transcription_inference" ];
73   meta = with lib; {
74     description = "A piano transcription inference package";
75     homepage = "https://github.com/qiuqiangkong/piano_transcription_inference";
76     license = licenses.mit;
77     maintainers = with maintainers; [ azuwis ];
78   };