diff --git a/bear/data_file.py b/bear/data_file.py index 7f8077f..231d023 100644 --- a/bear/data_file.py +++ b/bear/data_file.py @@ -1,4 +1,4 @@ -import pkg_resources +import importlib_resources import os @@ -15,12 +15,12 @@ def get_path(file_url): # try to find the file in a couple of different places for package, prefix in ("bear", "data/"), ("visr_bear_data", ""): try: - full_path = pkg_resources.resource_filename(package, prefix + path) + full_path = importlib_resources.files(package) / prefix / path except ModuleNotFoundError: continue - if os.path.isfile(full_path): - return full_path + if full_path.is_file(): + return str(full_path) else: raise Exception(f"resource '{path}' not found") elif file_url.startswith("file:"): diff --git a/flake.lock b/flake.lock index 42dd02e..ee9d76f 100644 --- a/flake.lock +++ b/flake.lock @@ -3,11 +3,11 @@ "ear_src": { "flake": false, "locked": { - "lastModified": 1696330591, - "narHash": "sha256-dpJtZ974HrSklPIh78UByjhEGsbVyltklceIcCZ81a4=", + "lastModified": 1712678150, + "narHash": "sha256-dwLalhg6rwdXKtY4iph3/bZuU+aW5sXbKVv8pqLOS5g=", "ref": "master", - "rev": "29efa875c772e86b09c9154381cbe2d1db60f999", - "revCount": 239, + "rev": "a04e287f247809653a031b7c99306066ec3d94c1", + "revCount": 364, "type": "git", "url": "https://github.com/ebu/ebu_adm_renderer.git" }, @@ -22,11 +22,11 @@ "systems": "systems" }, "locked": { - "lastModified": 1694529238, - "narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=", + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", "owner": "numtide", "repo": "flake-utils", - "rev": "ff7b65b44d01cf9ba6a71320833626af21126384", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", "type": "github" }, "original": { @@ -38,11 +38,11 @@ "libear_src": { "flake": false, "locked": { - "lastModified": 1683050932, - "narHash": "sha256-4Ce1B9Ajuw9K8zy2PVl46DTqae5biPVftDGNCaFedbU=", + "lastModified": 1712698185, + "narHash": "sha256-yLOWHkhUI57vPDf9G/GvFHwD0bQEsl9dE3ll/0d0r0Y=", "ref": "master", - "rev": "10e071784d7f033fee8e456032458f10dd1da174", - "revCount": 83, + "rev": "2db69f8fcea0bc5db8a78e14a9c2ae6ed4283c15", + "revCount": 109, "type": "git", "url": "https://github.com/ebu/libear.git" }, @@ -54,11 +54,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1701539137, - "narHash": "sha256-nVO/5QYpf1GwjvtpXhyxx5M3U/WN0MwBro4Lsk+9mL0=", + "lastModified": 1713344939, + "narHash": "sha256-jpHkAt0sG2/J7ueKnG7VvLLkBYUMQbXQ2L8OBpVG53s=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "933d7dc155096e7575d207be6fb7792bc9f34f6d", + "rev": "e402c3eb6d88384ca6c52ef1c53e61bdc9b84ddd", "type": "github" }, "original": { @@ -94,12 +94,13 @@ "visr_src": { "flake": false, "locked": { - "lastModified": 1706626832, - "narHash": "sha256-AXvgWBvQZwi88zglKRK9quFfG52oqJaBldcREeqV3xI=", - "owner": "ebu", - "repo": "bear", - "rev": "7ba1653b67c305d7245c2798f81b8e27889342c6", - "type": "github" + "lastModified": 1713548227, + "narHash": "sha256-xPwZDL9LVokj6/eZs22xVU3GLc/MLcAUZvHTJ3ixp2Y=", + "ref": "visr", + "rev": "6907b24a250c9dadf1028fb5e8764eaa078a184f", + "revCount": 19, + "type": "git", + "url": "https://github.com/ebu/bear.git" }, "original": { "ref": "visr", diff --git a/nix/bear.nix b/nix/bear.nix index 3d8b1ee..e449f41 100644 --- a/nix/bear.nix +++ b/nix/bear.nix @@ -2,7 +2,8 @@ python.pkgs.buildPythonPackage rec { name = "bear"; inherit src; - propagatedBuildInputs = with python.pkgs; [ numpy ear setuptools visr_python visr_bear ]; + propagatedBuildInputs = with python.pkgs; [ numpy ear importlib-resources visr_python visr_bear ]; + nativeBuildInputs = with python.pkgs; [ setuptools ]; nativeCheckInputs = [ python.pkgs.pytest numpy_quaternion ]; checkPhase = lib.optionalString (visr_bear != null) '' pytest visr_bear/test diff --git a/nix/ear.nix b/nix/ear.nix index c95c51b..f281db0 100644 --- a/nix/ear.nix +++ b/nix/ear.nix @@ -1,7 +1,10 @@ -{ stdenv, python, fetchFromGitHub, src }: +{ stdenv, python, src }: python.pkgs.buildPythonPackage rec { name = "ear"; inherit src; - propagatedBuildInputs = with python.pkgs; [ numpy scipy six attrs multipledispatch lxml pyyaml setuptools ]; + propagatedBuildInputs = with python.pkgs; [ numpy scipy six attrs multipledispatch lxml pyyaml importlib-resources ]; + nativeBuildInputs = with python.pkgs; [ setuptools ]; + pyproject = true; + doCheck = false; } diff --git a/nix/visr.nix b/nix/visr.nix index 4f6a4e4..680f6f4 100644 --- a/nix/visr.nix +++ b/nix/visr.nix @@ -2,7 +2,7 @@ stdenv.mkDerivation rec { name = "VISR"; inherit src; - nativeBuildInputs = [ cmake ninja boost ] ++ lib.optional enable_python python.buildEnv; + nativeBuildInputs = [ cmake ninja boost ] ++ lib.optional enable_python python; cmakeFlags = [ "-DBUILD_AUDIOINTERFACES_PORTAUDIO=FALSE" "-DBUILD_USE_SNDFILE_LIBRARY=FALSE" @@ -13,4 +13,17 @@ stdenv.mkDerivation rec { substituteInPlace CMakeLists.txt \ --replace "\''${VISR_TOPLEVEL_INSTALL_DIRECTORY}/python" "$out/${python.sitePackages}" ''; + + preCheck = '' + export LD_LIBRARY_PATH=$(pwd)/lib + export DYLD_LIBRARY_PATH=$(pwd)/lib + ''; + + nativeCheckInputs = lib.optionals enable_python [ + python.pkgs.numpy + python.pkgs.scipy + python.pkgs.pytest + ]; + + doCheck = true; } diff --git a/nix/visr_bear.nix b/nix/visr_bear.nix index c9014af..955e4f1 100644 --- a/nix/visr_bear.nix +++ b/nix/visr_bear.nix @@ -9,7 +9,7 @@ stdenv.mkDerivation rec { eigen libear rapidjson - ] ++ (if enable_python then [ python.buildEnv visr_python ] else [ visr ]); + ] ++ (if enable_python then [ python visr_python ] else [ visr ]); cmakeFlags = [ "-DBEAR_UNIT_TESTS=true" "-DBEAR_DATA_PATH_DEFAULT=${data_files.default.file}" diff --git a/setup.py b/setup.py index 797988d..4a51cb1 100644 --- a/setup.py +++ b/setup.py @@ -6,6 +6,7 @@ version="0.0.1", install_requires=[ "ear~=2.1", + "importlib_resources", "numpy", ], packages=find_packages(),