@@ -220,26 +220,19 @@ def format(self, avoid_double_period=True, **kwargs):
220
220
221
221
222
222
def get_resource_path (package : str , resource : str ) -> str :
223
- """
224
- Get the path to a resource file, supporting both pkg_resources and importlib.resources.
223
+ """Get the path to a resource file, supporting both pkg_resources and importlib.resources.
225
224
Falls back to importlib.resources if pkg_resources is not available.
226
225
227
226
Problem this solves:
228
- - In python 3.12, pkg_resources is being deprecated in favor of importlib.resources, and
229
- it no longer comes with pkg_resources. This creates an import error unless user does `pip install setuptools` but it is
230
- bad practice to add setuptools as a runtime dependency.
231
-
232
- - If I just switch to importlib, this is limiting since importlib is only for 3.9+.
233
-
234
- - So the solution is to use pkg_resources if available, and if not, use importlib.resources.
235
-
227
+ - In python 3.12, pkg_resources is being deprecated in favor of importlib.resources, and
228
+ it no longer comes with pkg_resources. This creates an import error unless user does
229
+ `pip install setuptools` but it is bad practice to add setuptools as a runtime dependency.
230
+ - If I just switch to importlib, this is limiting since importlib is only for 3.9+.
231
+ - So the solution is to use pkg_resources if available, and if not, use importlib.resources.
236
232
237
233
Args:
238
- package: The package name (just __name__ usually)
239
- resource: The resource path relative to the package
240
-
241
- Returns:
242
- str: The full path to the resource
234
+ package (str): The package name (just __name__ usually)
235
+ resource (str): The resource path relative to the package
243
236
"""
244
237
try :
245
238
import pkg_resources
@@ -248,4 +241,4 @@ def get_resource_path(package: str, resource: str) -> str:
248
241
from importlib import resources
249
242
root_package = package .split ('.' )[0 ]
250
243
with resources .path (root_package , resource ) as path :
251
- return str (path )
244
+ return str (path )
0 commit comments