captum icon indicating copy to clipboard operation
captum copied to clipboard

`captum.attr.visualization` is missing the Sphinx viewcode source link

Open ProGamerGov opened this issue 3 years ago • 2 comments

🐛 Bug

The captum.attr.visualization module is missing the link to its source code. I traced the issue with Sphinx's viewcode extension, and discovered that it gives the following warning.

No module named 'captum.attr.visualization'

In viewcode extension, the _get_full_modname function inside doctree_read returns None, and then skips generating the source docs. Inside the _get_full_modname function, a function called get_full_modname is run and it attempts to use importlib's import_module function to get the paths to the files

https://github.com/sphinx-doc/sphinx/blob/master/sphinx/ext/viewcode.py#L116 https://github.com/sphinx-doc/sphinx/blob/master/sphinx/util/init.py#L242.

from importlib import import_module
module = import_module("captum.attr.visualization") # Fails

You can see that its missing it's link to the source code here: https://captum.ai/api/utilities.html#visualization

And the file being used is here: https://github.com/pytorch/captum/blob/master/captum/attr/_utils/visualization.py

I discovered this issue while trying to figure out why it's happening in the Optim module code.


Possible solutions for this issue are:

  • Using an exact path in the API docs, like what was done for the Linear Models: https://captum.ai/api/utilities.html#linear-models
  • Changing the file path so that the visualization.py file's location matches the way it's called: captum/attr/visualization.py
  • Importing the needed functions in visualization.py directly, though this would remove the visualization part of the import path.

ProGamerGov avatar Jul 02 '22 02:07 ProGamerGov

This Sphinx PR will fix this issue, if it gets merged: https://github.com/sphinx-doc/sphinx/pull/10766

ProGamerGov avatar Sep 02 '22 16:09 ProGamerGov