Skip to content

importlib: prefer importlib.resources over importlib_resources #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

askervin
Copy link

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.

@askervin askervin requested a review from dedekind as a code owner July 25, 2025 05:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant