@@ -421,3 +421,42 @@ def get_doc_object(obj, what=None, doc=None, config={}, builder=None):
421421 if doc is None :
422422 doc = pydoc .getdoc (obj )
423423 return SphinxObjDoc (obj , doc , config = config )
424+
425+
426+ if __name__ == '__main__' :
427+ import argparse
428+ import importlib
429+ import ast
430+
431+ descr = 'Test numpydoc docstring generation for a given object'
432+ ap = argparse .ArgumentParser (description = descr )
433+ ap .add_argument ('import_path' , help = 'e.g. numpy.ndarray' )
434+
435+ def _parse_config (s ):
436+ key , _ , value = s .partition ('=' )
437+ value = ast .literal_eval (value )
438+ return key , value
439+
440+ ap .add_argument ('-c' , '--config' , type = _parse_config ,
441+ action = 'append' ,
442+ help = 'key=val where val will be parsed by literal_eval, '
443+ 'e.g. -c use_plots=True. Multiple -c can be used.' )
444+ args = ap .parse_args ()
445+
446+ parts = args .import_path .split ('.' )
447+
448+ for split_point in range (len (parts ), 0 , - 1 )[::- 1 ]:
449+ try :
450+ path = '.' .join (parts [:split_point ])
451+ obj = importlib .import_module (path )
452+ except ImportError :
453+ continue
454+ break
455+ else :
456+ raise ImportError ('Could not resolve {!r} to an importable object'
457+ '' .format (args .import_path ))
458+
459+ for part in parts [split_point :]:
460+ obj = getattr (obj , part )
461+
462+ print (get_doc_object (obj , config = dict (args .config )))
0 commit comments