-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Viewcode: Fix issue with import paths that differ from the directory structure #13195
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
Merged
Merged
Changes from 13 commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
8bcf410
Improve module path finder
ProGamerGov b332cf7
Add tests
ProGamerGov f6cf7df
add test
ProGamerGov b926d82
Fix try except issue
ProGamerGov 67c732d
Fix linting errors
ProGamerGov bf614af
Fix lint
ProGamerGov bcaec12
remove old NOQA
ProGamerGov 487d4ae
Remove NOQA
ProGamerGov 4f2e401
change test name
ProGamerGov 2b998c3
fix test lint
ProGamerGov 0ae96b1
fix lint quotation marks
ProGamerGov 6e3cfcb
Update authors & changes files
ProGamerGov dafd181
Merge branch 'master' into master-attempt-2
ProGamerGov dc4ec10
Fix lint errors
ProGamerGov 761d253
Merge branch 'master' into master-attempt-2
ProGamerGov 8c98620
Update viewcode.py
ProGamerGov fd52bc1
Update viewcode.py
ProGamerGov abbadbb
Fix remaining lint issues
ProGamerGov e91eb2e
fix mistake
ProGamerGov 768145c
Merge branch 'master' into master-attempt-2
ProGamerGov bcbccd1
fix remaining lint errors
ProGamerGov 49ff6f0
Merge branch 'master-attempt-2' of https://github.com/ProGamerGov/sph…
ProGamerGov 965cc26
fix classes
ProGamerGov 6fa7a43
replace __import__ with find_spec
ProGamerGov adca233
Merge branch 'master' into master-attempt-2
ProGamerGov 87f01b1
Fix lint errors
ProGamerGov 214ab7b
Merge branch 'master' into master-attempt-2
AA-Turner a3ff8cb
format
AA-Turner e06b219
early return
AA-Turner a7d3d1c
deduplicate
AA-Turner 7e5dc56
Use non-deprecated exec_module
AA-Turner 6849c71
Use module.__name__ instead of parsing the module repr
AA-Turner eada6e7
module is import_module(module.__name__)
AA-Turner 60f7529
style
AA-Turner 6e435dd
absolute imports
AA-Turner 9dfde4b
unify with the 'import_module' approach
AA-Turner 6ba6460
Credit
AA-Turner 69766d1
remove unused import
AA-Turner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import os | ||
| import sys | ||
|
|
||
| source_dir = os.path.abspath('.') | ||
| if source_dir not in sys.path: | ||
| sys.path.insert(0, source_dir) | ||
| extensions = ['sphinx.ext.autodoc', 'sphinx.ext.viewcode'] | ||
| exclude_patterns = ['_build'] | ||
|
|
||
|
|
||
| if 'test_linkcode' in tags: | ||
| extensions.remove('sphinx.ext.viewcode') | ||
| extensions.append('sphinx.ext.linkcode') | ||
|
|
||
| def linkcode_resolve(domain, info): | ||
| if domain == 'py': | ||
| fn = info['module'].replace('.', '/') | ||
| return "http://foobar/source/%s.py" % fn | ||
| elif domain == "js": | ||
| return "http://foobar/js/" + info['fullname'] | ||
| elif domain in ("c", "cpp"): | ||
| return "http://foobar/%s/%s" % (domain, "".join(info['names'])) | ||
| else: | ||
| raise AssertionError() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| viewcode | ||
| ======== | ||
|
|
||
| .. currentmodule:: main_package.subpackage.submodule | ||
|
|
||
| .. autofunction:: func1 | ||
|
|
||
| .. autoclass:: Class1 | ||
|
|
||
| .. autoclass:: Class3 |
1 change: 1 addition & 0 deletions
1
tests/roots/test-ext-viewcode-find-package/main_package/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| import main_package.subpackage as subpackage |
3 changes: 3 additions & 0 deletions
3
tests/roots/test-ext-viewcode-find-package/main_package/subpackage/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| from main_package.subpackage._subpackage2 import submodule | ||
|
|
||
| __all__ = ["submodule"] |
1 change: 1 addition & 0 deletions
1
tests/roots/test-ext-viewcode-find-package/main_package/subpackage/_subpackage2/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
|
|
31 changes: 31 additions & 0 deletions
31
tests/roots/test-ext-viewcode-find-package/main_package/subpackage/_subpackage2/submodule.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| """ | ||
| submodule | ||
| """ | ||
| # raise RuntimeError('This module should not get imported') | ||
|
|
||
|
|
||
| def decorator(f): | ||
| return f | ||
|
|
||
|
|
||
| @decorator | ||
| def func1(a, b): | ||
| """ | ||
| this is func1 | ||
| """ | ||
| return a, b | ||
|
|
||
|
|
||
| @decorator | ||
| class Class1(object): | ||
| """ | ||
| this is Class1 | ||
| """ | ||
|
|
||
|
|
||
| class Class3(object): | ||
| """ | ||
| this is Class3 | ||
| """ | ||
| class_attr = 42 | ||
| """this is the class attribute class_attr""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.