2727import subprocess as sp
2828from os import path as op
2929import argparse
30- import pkg_resources
30+
31+ # Prefer importlib.resources to avoid deprecated pkg_resources
32+ try :
33+ from importlib .resources import files , as_file # Python 3.9+
34+
35+ _USE_IMPORTLIB_RESOURCES = True
36+ except Exception : # pragma: no cover - fallback on very old Python
37+ _USE_IMPORTLIB_RESOURCES = False
38+ import pkg_resources # type: ignore
3139
3240__version__ = "0.2.2"
3341
@@ -38,12 +46,19 @@ def example_stem_path():
3846 Returns
3947 -------
4048 filename : str
41- Path to the stem file
49+ Filesystem path to the stem file (temp path if package is zipped)
4250 """
43- return pkg_resources .resource_filename (
44- __name__ ,
45- 'data/The Easton Ellises - Falcon 69.stem.mp4'
46- )
51+ rel_path = "data/The Easton Ellises - Falcon 69.stem.mp4"
52+ if _USE_IMPORTLIB_RESOURCES :
53+ ref = files ("stempeg" ).joinpath (rel_path )
54+ try :
55+ # as_file handles zipped/zip-safe installs by creating a tmp file
56+ with as_file (ref ) as concrete_path :
57+ return str (concrete_path )
58+ except Exception :
59+ return str (ref )
60+ else : # fallback
61+ return pkg_resources .resource_filename (__name__ , rel_path )
4762
4863
4964def default_metadata ():
@@ -52,12 +67,18 @@ def default_metadata():
5267 Returns
5368 -------
5469 filename : str
55- Path to the json file
70+ Filesystem path to the json file (temp path if package is zipped)
5671 """
57- return pkg_resources .resource_filename (
58- __name__ ,
59- 'data/default_metadata.json'
60- )
72+ rel_path = "data/default_metadata.json"
73+ if _USE_IMPORTLIB_RESOURCES :
74+ ref = files ("stempeg" ).joinpath (rel_path )
75+ try :
76+ with as_file (ref ) as concrete_path :
77+ return str (concrete_path )
78+ except Exception :
79+ return str (ref )
80+ else : # fallback
81+ return pkg_resources .resource_filename (__name__ , rel_path )
6182
6283
6384def ffmpeg_version ():
0 commit comments