Skip to content

Commit 11053e4

Browse files
committed
[cli] Switch to for version detection
1 parent 14ed005 commit 11053e4

3 files changed

Lines changed: 26 additions & 21 deletions

File tree

scenedetect/platform.py

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
functions to handle logging and invoking external commands.
1616
"""
1717

18-
import importlib
18+
import importlib.metadata
1919
import logging
2020
import os
2121
import os.path
@@ -325,29 +325,34 @@ def get_system_version_info() -> str:
325325
)
326326
]
327327

328-
# Third-Party Packages
328+
# Third-Party Packages: queried via PyPI distribution names. `cv2` is exposed by either
329+
# `opencv-python` or `opencv-python-headless` - both are listed so whichever is installed
330+
# gets reported. `scenedetect` is read from the package attribute since it must report a
331+
# version even when run uninstalled (e.g. from a source checkout). The import is deferred
332+
# to avoid a circular import at module load time.
333+
from scenedetect import __version__ as scenedetect_version
334+
329335
out_lines += ["", "Packages", line_separator]
330-
third_party_packages = (
336+
out_lines.append(output_template.format("scenedetect", scenedetect_version))
337+
third_party_distributions = (
331338
"av",
332339
"click",
333-
"cv2",
340+
"opencv-python",
341+
"opencv-python-headless",
334342
"imageio",
335-
"imageio_ffmpeg",
343+
"imageio-ffmpeg",
336344
"moviepy",
337345
"numpy",
338346
"platformdirs",
339-
"scenedetect",
340347
"tqdm",
341348
)
342-
for module_name in third_party_packages:
349+
for dist_name in third_party_distributions:
343350
try:
344-
module = importlib.import_module(module_name)
345-
if hasattr(module, "__version__"):
346-
out_lines.append(output_template.format(module_name, module.__version__))
347-
else:
348-
out_lines.append(output_template.format(module_name, not_found_str))
349-
except ModuleNotFoundError:
350-
out_lines.append(output_template.format(module_name, not_found_str))
351+
out_lines.append(
352+
output_template.format(dist_name, importlib.metadata.version(dist_name))
353+
)
354+
except importlib.metadata.PackageNotFoundError:
355+
out_lines.append(output_template.format(dist_name, not_found_str))
351356

352357
# External Tools
353358
out_lines += ["", "Tools", line_separator]

scripts/generate_assets.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ def _render_slate(inkscape: str, work_dir: Path, side: int, *, inverted: bool) -
200200
With inverted=False, the slate renders with its native FG body / BG stripes
201201
(right for placing on the white banner). With inverted=True, the SVG color
202202
codes are swapped before rendering so the body becomes BG and the stripes
203-
FG needed for the dialog's dark FG strip, where a non-inverted slate
203+
FG - needed for the dialog's dark FG strip, where a non-inverted slate
204204
would blend into the background.
205205
"""
206206
if inverted:
@@ -256,18 +256,18 @@ def render_installer_jpegs(inkscape: str, work_dir: Path) -> None:
256256
"""Render the per-scale baseline JPEGs that ship inside the MSI.
257257
258258
Outputs `Generated Images/installer_{banner,logo}{,.scale-125,.scale-150,.scale-200}.jpg`
259-
from the master SVG. These are gitignored pre_release.py --release rebuilds
259+
from the master SVG. These are gitignored - pre_release.py --release rebuilds
260260
them before each MSI build, so they always match the current logo without
261261
being re-committed every time.
262262
"""
263263
GENERATED_IMAGES_DIR.mkdir(parents=True, exist_ok=True)
264-
# Render the slate at the exact target size each iteration sharper than
264+
# Render the slate at the exact target size each iteration - sharper than
265265
# rendering once big and downsampling, and avoids Pillow's resize stub mismatch.
266266
for scale, suffix in SCALES:
267267
bw, bh = round(BANNER_BASE[0] * scale), round(BANNER_BASE[1] * scale)
268268
dw, dh = round(DIALOG_BASE[0] * scale), round(DIALOG_BASE[1] * scale)
269269

270-
# Banner icon sized off height (the limiting dim banner is wide & short).
270+
# Banner icon sized off height (the limiting dim - banner is wide & short).
271271
# Strip is wider than the icon, so the icon centers within it.
272272
banner_icon_side = round(bh * BANNER_ICON_FRAC)
273273
slate_fg = _render_slate(inkscape, work_dir, banner_icon_side, inverted=False)
@@ -285,7 +285,7 @@ def render_installer_jpegs(inkscape: str, work_dir: Path) -> None:
285285

286286

287287
def render_installer_static(inkscape: str, work_dir: Path) -> None:
288-
"""Render the stable, committed installer assets only re-run when the logo changes.
288+
"""Render the stable, committed installer assets - only re-run when the logo changes.
289289
290290
Outputs:
291291
- psd_square_small.ico (copy of pyscenedetect.ico)

tests/test_video_stream.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@
4242

4343

4444
def get_moviepy_major_version() -> int:
45-
import moviepy
45+
import importlib.metadata
4646

47-
return int(moviepy.__version__.split(".")[0])
47+
return int(importlib.metadata.version("moviepy").split(".")[0])
4848

4949

5050
def calculate_frame_delta(frame_a, frame_b, roi=None) -> float:

0 commit comments

Comments
 (0)