|
1 | 1 | # /*##########################################################################
|
2 | 2 | #
|
3 |
| -# Copyright (c) 2016-2023 European Synchrotron Radiation Facility |
| 3 | +# Copyright (c) 2016-2025 European Synchrotron Radiation Facility |
4 | 4 | #
|
5 | 5 | # Permission is hereby granted, free of charge, to any person obtaining a copy
|
6 | 6 | # of this software and associated documentation files (the "Software"), to deal
|
|
65 | 65 | import logging
|
66 | 66 | import os
|
67 | 67 | import sys
|
68 |
| -from typing import NamedTuple, Optional |
| 68 | +from typing import NamedTuple |
69 | 69 |
|
70 | 70 | import importlib.resources as importlib_resources
|
71 | 71 |
|
@@ -237,9 +237,16 @@ def _get_resource_filename(package: str, resource: str) -> str:
|
237 | 237 | :return: Abolute resource path in the file system
|
238 | 238 | """
|
239 | 239 | # Caching prevents extracting the resource twice
|
240 |
| - file_context = importlib_resources.as_file( |
241 |
| - importlib_resources.files(package) / resource |
242 |
| - ) |
| 240 | + traversable = importlib_resources.files(package).joinpath(resource) |
| 241 | + if not traversable.is_file() and not traversable.is_dir(): |
| 242 | + package_dir_context = importlib_resources.as_file( |
| 243 | + importlib_resources.files(package) |
| 244 | + ) |
| 245 | + path = _file_manager.enter_context(package_dir_context) |
| 246 | + return str(path.absolute() / resource) |
| 247 | + |
| 248 | + file_context = importlib_resources.as_file(traversable) |
| 249 | + |
243 | 250 | path = _file_manager.enter_context(file_context)
|
244 | 251 | return str(path.absolute())
|
245 | 252 |
|
|
0 commit comments