- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
fix: proper error messages if autosummary fails to import module #9555
Conversation
+1 thank you very much @Pro |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your stringification is a bit wonky, but generally good idea!
Co-authored-by: Philipp A. <flying-sheep@web.de>
Co-authored-by: Philipp A. <flying-sheep@web.de>
@@ -614,7 +614,7 @@ def get_import_prefixes_from_env(env: BuildEnvironment) -> List[str]: | |||
return prefixes | |||
|
|||
|
|||
def import_by_name(name: str, prefixes: List[str] = [None]) -> Tuple[str, Any, Any, str]: | |||
def import_by_name(name: str, prefixes: List[str] = [None], last_errors = None) -> Tuple[str, Any, Any, str]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel this change is strange because last_errors
should be a part of the return value. I understand using argument gives us compatibility. But...
BTW, it should be annotated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also thought the same, but that would probably break backwards compatibility? Or should I change last_errors to be a retun value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have two ideas:
- Add another version of
import_by_name
that also returns list of errors. It will be named as different name. - Add a boolean argument like
raise_error
toimport_by_name
. And it raises a custom exception that contains list of errors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, raise_error would not work that well since we need to collect all errors during the various import methods there are.
Having another version of the import_by_name is IMHO also not such an ideal solution, since then we would need to duplicate code, not only for the import_by_name
but also for the sub-methods such as _import_by_name
which is called inside of import_by_name
@@ -614,7 +614,7 @@ def get_import_prefixes_from_env(env: BuildEnvironment) -> List[str]: | |||
return prefixes | |||
|
|||
|
|||
def import_by_name(name: str, prefixes: List[str] = [None]) -> Tuple[str, Any, Any, str]: | |||
def import_by_name(name: str, prefixes: List[str] = [None], last_errors = None) -> Tuple[str, Any, Any, str]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have two ideas:
- Add another version of
import_by_name
that also returns list of errors. It will be named as different name. - Add a boolean argument like
raise_error
toimport_by_name
. And it raises a custom exception that contains list of errors.
Co-authored-by: Takeshi KOMIYA <i.tkomiya@gmail.com>
@tk0miya is there still something missing to merge this MR? |
… to load target object
I just post #10031 to implement my idea. |
Cool! Also nice solution! |
…autosummary Close #9555: autosummary: Improve error messages on failure to load target object
Subject: Show proper error messages if autosummary fails to import module
Fixes #7989
Feature or Bugfix
Purpose
As described in #7989, autosummary currently does not provide helpful error messages.
E.g., let's say I have a module called fancy_bob, which in its init.py uses
import filelock
(or any other external module).Then in my docs I write:
If the filelock module is not installed, autosummary will just fail with:
This error message is completely misleading, since it actually finds the module
fancy_bob
but then fails to import its dependencies.This MR changes the error output in a way that you at least get some hints what went wrong, e.g., now you get:
Or if there is a syntax error in the module's init.py, it will show:
Reproduction
@astrojuanlu provided a nice example project to reproduce the issue in https://github.com/astrojuanlu/sphinx-autosummary-tracebacks
Not setting the pythonpath properly results in:
Setting the pythonpath gives the correct error:
I.e.,
"No module named 'attr'
Detail
Relates