Fix getting 'orig_path' for 'viewcode_follow_imported' #367
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
When I use
autoapito build aAPI docs and I want to useviewcodeto addsource code linkin docs, I meet this problem.The built doc is https://mmediting.readthedocs.io/en/dev-1.x/ . I find that when an object's (class, function, or method) directory level is lower more than 2 levels than the directory level of the current API doc, the source link of this object will lost. For example:
The path of


class AOTBlockNeckismmedit.models.editors.aotgan.aot_neck.AOTBlockNeckand the path of the current doc ismmedit.models.editors. The source link will be lost.But when the path of the current doc is
mmedit.models.editors.aotgan, the source link will be built.And another example of the

methodobject: the path of 'method add_datasample' ismmedit.visualization.concat_visualizer.ConcatImageVisualizer.add_datasample, the path ofclass ConcatImageVisualizerismmedit.visualization.concat_visualizer.ConcatImageVisualizer, and the path of the current doc ismmedit.visualization. 2 levels gap of path gets the source link, but 3 levels gap doesn't.Modification
I think the reason is that some objects don't get their correct path of source code file. Related codes are in autoapi/extension.py/viewcode_follow_imported. After modification, We will iteratively find the
original_pathoforiginal_path, until the finaloriginal_pathis a real source code file.This is test results:

