Custom error messages for missing dependencies
ZanSara opened this issue · 2 comments
Problem
Large projects often group optional dependencies into extras, which allow users to install groups of optional dependencies together. When one dependency from such group is missing, it would be nice to point users towards the extra that they should install, instead of giving a generic error message.
Solution
For now, simple customized error messages would be sufficient. They could be provided through the generalimport
call, something like:
generalimport(
("missingdep1a", "Please install my-library[group1]"),
("missingdep1b", "Please install my-library[group1] or make sure you install missingdep1b with a version lower than 0.12.3"),
("missingdep2", "Please install my-library[groupB] or my-library[groupC]"),
"another_missing_dep", # This has only the default error message
...
)
We could also use a namedtuple here, but for now I decided to keep it simple.
PR coming soon 🙂
Sorry it's taking me so long to get to these! I got a bit carried away with this one, experimenting with reading the pyproject.toml
file to dynamically generate these messages!
I used your farm-haystack repo as an example there, this has some potential but I'm unsure about structuring the entry point for such a system since pyproject.toml
is only available when cloning a repo I believe
So I'm putting that branch on hold for now and focusing on your proposal instead!
The idea of having custom messages is excellent! However, I'm afraid supplying tuples isn't too intuitive. I think having key-word arg message
is a bit more clear, what do you think?
I also had an idea that we could store the message in the ImportCatcher instance, and then relay that instance to the FakeModule instance. This seems to work pretty nicely. Please see the PR above before I merge it