aports/testing/py3-imageio-ffmpeg/0002-replace-pkg-resources.patch
mio dfad2b3931 testing/py3-imageio-ffmpeg: rebuild against python 3.14
Fix `ModuleNotFoundError: No module named 'pkg_resources'` error when
building with setuptools 82.

Ref: https://gitlab.alpinelinux.org/alpine/aports/-/issues/18025
2026-03-31 03:10:10 +00:00

120 lines
3.5 KiB
Diff

Patch-Source: https://github.com/imageio/imageio-ffmpeg/commit/b941256e7d281adb72f069054d3d04f1903e412c
---
From b941256e7d281adb72f069054d3d04f1903e412c Mon Sep 17 00:00:00 2001
From: Almar Klein <almar@almarklein.org>
Date: Fri, 8 Mar 2024 10:36:25 +0100
Subject: [PATCH] Replace pkg_resources with importlib.resources (#109)
* Replace pkg_resources with importlib.resources
* fix in setup.py
* fix ci for new resource mechanics
* ah
* try
* arg
* update manifest
* ?
* debug
* ah
* clean ci
* fix win
---
.github/workflows/ci.yml | 6 ++++--
MANIFEST.in | 1 +
imageio_ffmpeg/_utils.py | 18 ++++++++++++++----
imageio_ffmpeg/binaries/__init__.py | 1 +
setup.py | 5 ++---
tasks.py | 2 +-
6 files changed, 23 insertions(+), 10 deletions(-)
create mode 100644 imageio_ffmpeg/binaries/__init__.py
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")