diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index df66cc9..3355e3f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -73,9 +73,11 @@ jobs: python -m pip install --upgrade pip pip install psutil pip install invoke pytest pytest-cov - invoke get-ffmpeg-binary; + invoke get-ffmpeg-binary + pip install . + rm -r ./imageio_ffmpeg - name: Test with pytest run: | python -c "import sys; print(sys.version, '\n', sys.prefix)"; python -c 'import imageio_ffmpeg; print(imageio_ffmpeg.get_ffmpeg_version())' - invoke test + pytest tests -v --cov=imageio_ffmpeg --cov-report=term diff --git a/MANIFEST.in b/MANIFEST.in index c1a7121..c7e0764 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1,2 +1,3 @@ include LICENSE include README.md +include imageio_ffmpeg/binaries/*.* diff --git a/imageio_ffmpeg/_utils.py b/imageio_ffmpeg/_utils.py index 15bd958..be6f916 100644 --- a/imageio_ffmpeg/_utils.py +++ b/imageio_ffmpeg/_utils.py @@ -3,8 +3,7 @@ import subprocess import sys from functools import lru_cache - -from pkg_resources import resource_filename +import importlib.resources from ._definitions import FNAME_PER_PLATFORM, get_platform @@ -42,8 +41,7 @@ def _get_ffmpeg_exe(): plat = get_platform() # 2. Try from here - bin_dir = resource_filename("imageio_ffmpeg", "binaries") - exe = os.path.join(bin_dir, FNAME_PER_PLATFORM.get(plat, "")) + exe = os.path.join(_get_bin_dir(), FNAME_PER_PLATFORM.get(plat, "")) if exe and os.path.isfile(exe) and _is_valid_exe(exe): return exe @@ -64,6 +62,18 @@ def _get_ffmpeg_exe(): return None +def _get_bin_dir(): + if sys.version_info < (3, 9): + context = importlib.resources.path("imageio_ffmpeg.binaries", "__init__.py") + else: + ref = importlib.resources.files("imageio_ffmpeg.binaries") / "__init__.py" + context = importlib.resources.as_file(ref) + with context as path: + pass + # Return the dir. We assume that the data files are on a normal dir on the fs. + return str(path.parent) + + def _popen_kwargs(prevent_sigint=False): startupinfo = None preexec_fn = None diff --git a/imageio_ffmpeg/binaries/__init__.py b/imageio_ffmpeg/binaries/__init__.py new file mode 100644 index 0000000..5919de3 --- /dev/null +++ b/imageio_ffmpeg/binaries/__init__.py @@ -0,0 +1 @@ +# Just here to make importlib.resources work diff --git a/setup.py b/setup.py index 2868794..ead3e22 100644 --- a/setup.py +++ b/setup.py @@ -59,9 +59,8 @@ python_requires=">=3.5", setup_requires=[], install_requires=["setuptools"], - packages=["imageio_ffmpeg"], - package_dir={"imageio_ffmpeg": "imageio_ffmpeg"}, - package_data={"imageio_ffmpeg": ["binaries/*.*"]}, + packages=["imageio_ffmpeg", "imageio_ffmpeg.binaries"], + package_data={"imageio_ffmpeg.binaries": ["*.*"]}, include_package_data=True, zip_safe=False, classifiers=[ diff --git a/tasks.py b/tasks.py index 3d70670..70d4726 100644 --- a/tasks.py +++ b/tasks.py @@ -273,7 +273,7 @@ def black_wrapper(writeback): def clear_binaries_dir(target_dir): assert os.path.isdir(target_dir) for fname in os.listdir(target_dir): - if fname != "README.md": + if fname not in ["README.md", "__init__.py"]: print("Removing", fname, "...", end="") os.remove(os.path.join(target_dir, fname)) print("done")