Fix: Use importlib.resources or importlib_resources instead of pkg_resources#11454
Conversation
|
Hello! 👋 Thanks for opening your first pull request here! ❤️ We will try to get back to you soon. 🚴🏽♂️ |
|
Regarding the use of checksums in |
larsoner
left a comment
There was a problem hiding this comment.
I feel like it's probably not worth having this mechanism just for our checksums.
Agreed but we do make use of files in mne/utils/misc.py already, so why not keep/use it
Changes LGTM, @drammock feel free to merge if you agree this is a reasonable fix. I was never totally sure about the packaging / pkg_resources etc. stuff...
importlib.resources or importlib_resources instead of pkg_resourcesimportlib.resources or importlib_resources instead of pkg_resources
drammock
left a comment
There was a problem hiding this comment.
adding a couple of code comments for future maintainers. Let's see if the CIs are happy...
No such luck I suppose. |
|
It looks like the failures are an unrelated bug where nipy.org is down, so our docs complain. So I think we're actually okay! |
|
only failures are the |
|
🎉 Congrats on merging your first pull request! 🥳 Looking forward to seeing more from you in the future! 💪 |
Reference issue
Fixes #11448.
What does this implement/fix?
mnecurrently relies onpkg_resources, which is a part ofsetuptools, without declaring it as a dependency. This can cause issues in environments wheresetuptoolsis not present by default (see #11448 for an example).This PR updates
mneto useimportlib.resourcesfor Python >= 3.9 or its backportimportlib_resourcesfor Python < 3.9 as recommended here.importlibis part of the standard library.Additional information
The only
importlibfunction this PR uses isimportlib.resources.files(), which was added in Python 3.9. I added a dependency toimportlib_resourcesinrequirements_base.txtfor Python versions < 3.9. Please advise if this is ok. If not I will update the PR accordingly, but it would mean thatmnewould still rely onpkg_resourcesfor Python < 3.9 (meaning thatsetuptoolsshould be declared as a dependency then).pkg_resourceswas used in two functions,mne/datasets/eegbci/eegbci.py:load_data()andmne/utils/misc.py:_resource_path(). There are currently no unit tests that testload_data(), but manually calling the updated version works for Python 3.7 and 3.11 on my end. All unit tests calling the updated_resource_path()are passing when I run them locally in Python 3.7 and 3.11.