projects/aports·blob master · refs

119 lines · 3.5 KiB

1Patch-Source: https://github.com/imageio/imageio-ffmpeg/commit/b941256e7d281adb72f069054d3d04f1903e412c
2---
3From b941256e7d281adb72f069054d3d04f1903e412c Mon Sep 17 00:00:00 2001
4From: Almar Klein <[email protected]>
5Date: Fri, 8 Mar 2024 10:36:25 +0100
6Subject: [PATCH] Replace pkg_resources with importlib.resources (#109)
7
8* Replace pkg_resources with importlib.resources
9
10* fix in setup.py
11
12* fix ci for new resource mechanics
13
14* ah
15
16* try
17
18* arg
19
20* update manifest
21
22* ?
23
24* debug
25
26* ah
27
28* clean ci
29
30* fix win
31---
32 .github/workflows/ci.yml | 6 ++++--
33 MANIFEST.in | 1 +
34 imageio_ffmpeg/_utils.py | 18 ++++++++++++++----
35 imageio_ffmpeg/binaries/__init__.py | 1 +
36 setup.py | 5 ++---
37 tasks.py | 2 +-
38 6 files changed, 23 insertions(+), 10 deletions(-)
39 create mode 100644 imageio_ffmpeg/binaries/__init__.py
40
41diff --git a/imageio_ffmpeg/_utils.py b/imageio_ffmpeg/_utils.py
42index 15bd958..be6f916 100644
43--- a/imageio_ffmpeg/_utils.py
44+++ b/imageio_ffmpeg/_utils.py
45@@ -3,8 +3,7 @@
46 import subprocess
47 import sys
48 from functools import lru_cache
49-
50-from pkg_resources import resource_filename
51+import importlib.resources
52
53 from ._definitions import FNAME_PER_PLATFORM, get_platform
54
55@@ -42,8 +41,7 @@ def _get_ffmpeg_exe():
56 plat = get_platform()
57
58 # 2. Try from here
59- bin_dir = resource_filename("imageio_ffmpeg", "binaries")
60- exe = os.path.join(bin_dir, FNAME_PER_PLATFORM.get(plat, ""))
61+ exe = os.path.join(_get_bin_dir(), FNAME_PER_PLATFORM.get(plat, ""))
62 if exe and os.path.isfile(exe) and _is_valid_exe(exe):
63 return exe
64
65@@ -64,6 +62,18 @@ def _get_ffmpeg_exe():
66 return None
67
68
69+def _get_bin_dir():
70+ if sys.version_info < (3, 9):
71+ context = importlib.resources.path("imageio_ffmpeg.binaries", "__init__.py")
72+ else:
73+ ref = importlib.resources.files("imageio_ffmpeg.binaries") / "__init__.py"
74+ context = importlib.resources.as_file(ref)
75+ with context as path:
76+ pass
77+ # Return the dir. We assume that the data files are on a normal dir on the fs.
78+ return str(path.parent)
79+
80+
81 def _popen_kwargs(prevent_sigint=False):
82 startupinfo = None
83 preexec_fn = None
84diff --git a/imageio_ffmpeg/binaries/__init__.py b/imageio_ffmpeg/binaries/__init__.py
85new file mode 100644
86index 0000000..5919de3
87--- /dev/null
88+++ b/imageio_ffmpeg/binaries/__init__.py
89@@ -0,0 +1 @@
90+# Just here to make importlib.resources work
91diff --git a/setup.py b/setup.py
92index 2868794..ead3e22 100644
93--- a/setup.py
94+++ b/setup.py
95@@ -59,9 +59,8 @@
96 python_requires=">=3.5",
97 setup_requires=[],
98 install_requires=["setuptools"],
99- packages=["imageio_ffmpeg"],
100- package_dir={"imageio_ffmpeg": "imageio_ffmpeg"},
101- package_data={"imageio_ffmpeg": ["binaries/*.*"]},
102+ packages=["imageio_ffmpeg", "imageio_ffmpeg.binaries"],
103+ package_data={"imageio_ffmpeg.binaries": ["*.*"]},
104 include_package_data=True,
105 zip_safe=False,
106 classifiers=[
107diff --git a/tasks.py b/tasks.py
108index 3d70670..70d4726 100644
109--- a/tasks.py
110+++ b/tasks.py
111@@ -273,7 +273,7 @@ def black_wrapper(writeback):
112 def clear_binaries_dir(target_dir):
113 assert os.path.isdir(target_dir)
114 for fname in os.listdir(target_dir):
115- if fname != "README.md":
116+ if fname not in ["README.md", "__init__.py"]:
117 print("Removing", fname, "...", end="")
118 os.remove(os.path.join(target_dir, fname))
119 print("done")