MCPcopy Create free account
hub / github.com/Breakthrough/PySceneDetect / _query_package_version

Function _query_package_version

scenedetect/platform.py:319–337  ·  view source on GitHub ↗

Return version of an installed package, querying PyPI metadata first then falling back to the module's `__version__` attribute when metadata is missing. PyInstaller bundles ship modules but not the `.dist-info` directories that `importlib.metadata` reads, so the fallback is required for

(dist_name: str, fallback_module: str | None)

Source from the content-addressed store, hash-verified

317
318
319def _query_package_version(dist_name: str, fallback_module: str | None) -> str | None:
320 """Return version of an installed package, querying PyPI metadata first then
321 falling back to the module's `__version__` attribute when metadata is missing.
322
323 PyInstaller bundles ship modules but not the `.dist-info` directories that
324 `importlib.metadata` reads, so the fallback is required for frozen builds.
325 Returns None when the package isn't installed.
326 """
327 try:
328 return importlib.metadata.version(dist_name)
329 except importlib.metadata.PackageNotFoundError:
330 pass
331 if fallback_module is None:
332 return None
333 try:
334 module = importlib.import_module(fallback_module)
335 except ModuleNotFoundError:
336 return None
337 return getattr(module, "__version__", None)
338
339
340def get_system_version_info() -> str:

Callers 1

get_system_version_infoFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected