Beets BPM plugin

Looking for some help getting an external beets plugin working.

In home manager I have an override

    bpmanalyser = {
        enable = true;
        propagatedBuildInputs = [pkgs.beets-bpmanalyser];
      };

which points to a custom local package

{
  python3Packages,
  fetchurl,
  lib,
  pkgs,
}:

python3Packages.buildPythonPackage rec {
  pname = "beets-bpmanalyser";
  version = "1.5.9";
  src = pkgs.fetchPypi {
    inherit version;
    pname = "beets_bpmanalyser"; #name in pip uses _ not -
    sha256 = "sha256-iWXSELGRHI4ak1MTWCSdRiyPz618fyBSzKw/FeJigZ4="; 
  };
 
  propagatedBuildInputs = with pkgs.python3Packages; [ numpy aubio pydub];

  nativeBuildInputs = [ pkgs.ffmpeg pkgs.beets ];
  
  doCheck = false; #bodgy way to get rid of pip error
    
  meta = with pkgs.lib; {
    description = "A BPM analyzer plugin for Beets music library manager";
    homepage = "https://github.com/adamjakab/BeetsPluginBpmAnalyser";
    license = licenses.mit;
  };
}

And after rebuilding home-manager I can see the plugin in beets

beets version 1.6.0
Python version 3.11.9
plugins: albumtypes, bpmanalyser,…

But when I try to run the plugin I get the following.

bpmanalyser: Error(1): Unknown error! Unparsable response.

Any ideas welcome.

This is more of a python question than a nix question at this point; you’d have to look at the upstream python code and figure out why that “unknown error” is occurring.

Wierdly it looks like the resulting python package/plugin can’t see the pydub python module and throws a ModuleNotFoundError: No module named 'pydub' error.

As far as I can see, because this program uses threads and is calling part of itself via popen call, i’m losing the pythonpath in the subprocess.

Had to modify the python subprocess call to pass the sys.path to the subprocess to make it work.
If anyone has a way to do this without modifying the upstream code that would be awesome.

    # Pass the current environment variables to the subprocess
    env = os.environ.copy()
    env["PYTHONPATH"] = ":".join(sys.path)
    
    proc = Popen([sys.executable, self.analyser_script_path, item_path],
                 stdout=PIPE, stderr=PIPE, env=env)