-
-
Notifications
You must be signed in to change notification settings - Fork 170
Command-line tool to help debug NumpyDocString #146
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 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c99f393
Command-line tool to help debug NumpyDocString
jnothman a30eb93
handle config is None
jnothman 8245460
Merge branch 'master' into test-rest
jnothman 9469f59
Move to numpydoc.__main__. Add test
jnothman 65cd286
Remove from docscrape_sphinx
jnothman 6d5d449
Add documentation
jnothman 91a78df
Use StringIO.StringIO in Py2
jnothman faafc79
Improve importing in main
jnothman 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,3 +22,4 @@ Documentation | |
install | ||
format | ||
example | ||
validation |
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,12 @@ | ||
============================== | ||
Validating NumpyDoc docstrings | ||
============================== | ||
|
||
One tool for validating docstrings is to see how an object's dosctring | ||
translates to Restructured Text. Using numpydoc as a command-line tool | ||
facilitates this. For example to see the Restructured Text generated | ||
for ``numpy.ndarray``, use: | ||
|
||
.. code-block:: bash | ||
|
||
$ python -m numpydoc numpy.ndarray |
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,44 @@ | ||
import argparse | ||
import importlib | ||
import ast | ||
|
||
from .docscrape_sphinx import get_doc_object | ||
|
||
|
||
def main(argv=None): | ||
"""Test numpydoc docstring generation for a given object""" | ||
|
||
ap = argparse.ArgumentParser(description=__doc__) | ||
ap.add_argument('import_path', help='e.g. numpy.ndarray') | ||
|
||
def _parse_config(s): | ||
key, _, value = s.partition('=') | ||
value = ast.literal_eval(value) | ||
return key, value | ||
|
||
ap.add_argument('-c', '--config', type=_parse_config, | ||
action='append', | ||
help='key=val where val will be parsed by literal_eval, ' | ||
'e.g. -c use_plots=True. Multiple -c can be used.') | ||
args = ap.parse_args(argv) | ||
|
||
parts = args.import_path.split('.') | ||
|
||
for split_point in range(len(parts), 0, -1)[::-1]: | ||
try: | ||
path = '.'.join(parts[:split_point]) | ||
obj = importlib.import_module(path) | ||
except ImportError: | ||
continue | ||
break | ||
else: | ||
raise ImportError('Could not resolve {!r} to an importable object' | ||
''.format(args.import_path)) | ||
|
||
for part in parts[split_point:]: | ||
obj = getattr(obj, part) | ||
|
||
print(get_doc_object(obj, config=dict(args.config or []))) | ||
|
||
if __name__ == '__main__': | ||
main() |
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,15 @@ | ||
from numpydoc.__main__ import main | ||
|
||
import sys | ||
try: | ||
from StringIO import StringIO | ||
except ImportError: | ||
from io import StringIO | ||
|
||
|
||
def test_main(): | ||
f = StringIO() | ||
sys.stdout, old_stdout = f, sys.stdout | ||
main(['numpydoc.__main__.main']) | ||
assert f.getvalue().strip() == main.__doc__ | ||
sys.stdout = old_stdout |
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.
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.
Of course. This does the reversal twice. Silly me.