importlib: prefer importlib.resources over importlib_resources #13
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Using pepc simply by cloning the repo and running pepc fails on importing importlib_resources. Looking at the code, this could be avoided without installing the importlib_resources dependency in recent Python 3 versions, simply by using importlib.resources.
According to the docs, importlib.resources.files got added to the API in Python 3.9, and the only change so far, that is in Python 3.12, does not affect this code.
Therefore I'd propose getting rid of this minor inconvenience by trying to use importlib.resources.file, and only fallback to importlib_resources.files in case importlib.resources.file is not found in the API (Python older than 3.9).
I'm still leaving the TODO comment untouched as a reminder to get rid of the importlib_resources dependency when dropping support of outdated Python 3.
I tested this change with Python 3.13.5 and Python 3.9.23. They both worked fine, and they both successfully used importlib.resources.files.