-
Notifications
You must be signed in to change notification settings - Fork 1
Description
Let's start with a concrete example.
It often happens that I want to use from importlib.resources import files, but that only exists in 3.9+.
In my code, I end up doing:
try:
from importlib.resources import files # ... and any other things you want to get
except (ImportError, ModuleNotFoundError):
from importlib_resources import files # pip install importlib_resourcesBut I feel shame when copy/pasting this code everywhere. Additionally, it still doesn't solve my problem "completely".
The question is: Do I include importlib_resources, a third-party backport of importlib.resources, in my setup.cfg install_requires? If I don't, my code will fail on python < 3.9. If I do include it, I'm overkilling my dependencies.
Ideally, I'd like a solution where I can just do
from importlib_resources import filesin my code, and trust that the setup.cfg took care of doing two things:
- telling the install to only do a
pip install importlib-resourcesif python version < 3.9 - telling it that
importlib_resourcesis an alias forimportlib.resourcesif in 3.9+, and ofimportlib_resources(the pip install backport) if not.
Trying to solve the first problem only, I did this.
install_requires =
dol
importlib_resources; python_version < '3.9'
But it doesn't condition the install at all (it's installed on both 3.8 and 3.10!).
Not sure how to even start with the second "aliasing" desire.