<s> """<STR_LIT>""" <EOL> from __future__ import print_function <EOL> import inspect <EOL> from nose . plugins . skip import SkipTest <EOL> import re <EOL> import sys <EOL> from theano . compat import six <EOL> class Reader ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , data ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( data , list ) : <EOL> self . _str = data <EOL> else : <EOL> self . _str = data . split ( '<STR_LIT:\n>' ) <EOL> self . reset ( ) <EOL> def __getitem__ ( self , n ) : <EOL> return self . _str [ n ] <EOL> def reset ( self ) : <EOL> self . _l = <NUM_LIT:0> <EOL> def read ( self ) : <EOL> if not self . eof ( ) : <EOL> out = self [ self . _l ] <EOL> self . _l += <NUM_LIT:1> <EOL> return out <EOL> else : <EOL> return '<STR_LIT>' <EOL> def seek_next_non_empty_line ( self ) : <EOL> for l in self [ self . _l : ] : <EOL> if l . strip ( ) : <EOL> break <EOL> else : <EOL> self . _l += <NUM_LIT:1> <EOL> def eof ( self ) : <EOL> return self . _l >= len ( self . _str ) <EOL> def read_to_condition ( self , condition_func ) : <EOL> start = self . _l <EOL> for line in self [ start : ] : <EOL> if condition_func ( line ) : <EOL> return self [ start : self . _l ] <EOL> self . _l += <NUM_LIT:1> <EOL> if self . eof ( ) : <EOL> return self [ start : self . _l + <NUM_LIT:1> ] <EOL> return [ ] <EOL> def read_to_next_empty_line ( self ) : <EOL> self . seek_next_non_empty_line ( ) <EOL> def is_empty ( line ) : <EOL> return not line . strip ( ) <EOL> return self . read_to_condition ( is_empty ) <EOL> def read_to_next_unindented_line ( self ) : <EOL> def is_unindented ( line ) : <EOL> return ( line . strip ( ) and ( len ( line . lstrip ( ) ) == len ( line ) ) ) <EOL> return self . read_to_condition ( is_unindented ) <EOL> def peek ( self , n = <NUM_LIT:0> ) : <EOL> if self . _l + n < len ( self . _str ) : <EOL> return self [ self . _l + n ] <EOL> else : <EOL> return '<STR_LIT>' <EOL> def is_empty ( self ) : <EOL> return not '<STR_LIT>' . join ( self . _str ) . strip ( ) <EOL> def __iter__ ( self ) : <EOL> for line in self . _str : <EOL> yield line <EOL> class NumpyDocString ( object ) : <EOL> def __init__ ( self , docstring , name = None ) : <EOL> if name : <EOL> self . name = name <EOL> docstring = docstring . split ( '<STR_LIT:\n>' ) <EOL> try : <EOL> indent = min ( len ( s ) - len ( s . lstrip ( ) ) for s in docstring <EOL> if s . strip ( ) ) <EOL> except ValueError : <EOL> indent = <NUM_LIT:0> <EOL> for n , line in enumerate ( docstring ) : <EOL> docstring [ n ] = docstring [ n ] [ indent : ] <EOL> self . _doc = Reader ( docstring ) <EOL> self . _parsed_data = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:index>' : { } , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ ] , <EOL> } <EOL> self . section_order = [ ] <EOL> self . _parse ( ) <EOL> def __getitem__ ( self , key ) : <EOL> return self . _parsed_data [ key ] <EOL> def __setitem__ ( self , key , val ) : <EOL> if key not in self . _parsed_data : <EOL> raise ValueError ( "<STR_LIT>" % key ) <EOL> else : <EOL> self . _parsed_data [ key ] = val <EOL> def _is_at_section ( self ) : <EOL> self . _doc . seek_next_non_empty_line ( ) <EOL> if self . _doc . eof ( ) : <EOL> return False <EOL> l1 = self . _doc . peek ( ) . strip ( ) <EOL> if l1 . startswith ( '<STR_LIT>' ) : <EOL> return True <EOL> l2 = self . _doc . peek ( <NUM_LIT:1> ) . strip ( ) <EOL> return ( len ( l1 ) == len ( l2 ) and l2 == '<STR_LIT:->' * len ( l1 ) ) <EOL> def _strip ( self , doc ) : <EOL> i = <NUM_LIT:0> <EOL> j = <NUM_LIT:0> <EOL> for i , line in enumerate ( doc ) : <EOL> if line . strip ( ) : break <EOL> for j , line in enumerate ( doc [ : : - <NUM_LIT:1> ] ) : <EOL> if line . strip ( ) : break <EOL> return doc [ i : len ( doc ) - j ] <EOL> def _read_to_next_section ( self ) : <EOL> section = self . _doc . read_to_next_empty_line ( ) <EOL> while not self . _is_at_section ( ) and not self . _doc . eof ( ) : <EOL> if not self . _doc . peek ( - <NUM_LIT:1> ) . strip ( ) : <EOL> section += [ '<STR_LIT>' ] <EOL> section += self . _doc . read_to_next_empty_line ( ) <EOL> return section <EOL> def _read_sections ( self ) : <EOL> while not self . _doc . eof ( ) : <EOL> data = self . _read_to_next_section ( ) <EOL> name = data [ <NUM_LIT:0> ] . strip ( ) <EOL> if name . startswith ( '<STR_LIT:..>' ) : <EOL> yield name , data [ <NUM_LIT:1> : ] <EOL> elif len ( data ) < <NUM_LIT:2> : <EOL> yield StopIteration <EOL> else : <EOL> yield name , self . _strip ( data [ <NUM_LIT:2> : ] ) <EOL> def _parse_param_list ( self , content ) : <EOL> r = Reader ( content ) <EOL> params = [ ] <EOL> while not r . eof ( ) : <EOL> header = r . read ( ) . strip ( ) <EOL> if '<STR_LIT>' in header : <EOL> arg_name , arg_type = header . split ( '<STR_LIT>' ) [ : <NUM_LIT:2> ] <EOL> else : <EOL> arg_name , arg_type = header , '<STR_LIT>' <EOL> desc = r . read_to_next_unindented_line ( ) <EOL> for n , line in enumerate ( desc ) : <EOL> desc [ n ] = line . strip ( ) <EOL> desc = desc <EOL> params . append ( ( arg_name , arg_type , desc ) ) <EOL> return params <EOL> def _parse_see_also ( self , content ) : <EOL> """<STR_LIT>""" <EOL> functions = [ ] <EOL> current_func = None <EOL> rest = [ ] <EOL> for line in content : <EOL> if not line . strip ( ) : continue <EOL> if '<STR_LIT::>' in line : <EOL> if current_func : <EOL> functions . append ( ( current_func , rest ) ) <EOL> r = line . split ( '<STR_LIT::>' , <NUM_LIT:1> ) <EOL> current_func = r [ <NUM_LIT:0> ] . strip ( ) <EOL> r [ <NUM_LIT:1> ] = r [ <NUM_LIT:1> ] . strip ( ) <EOL> if r [ <NUM_LIT:1> ] : <EOL> rest = [ r [ <NUM_LIT:1> ] ] <EOL> else : <EOL> rest = [ ] <EOL> elif not line . startswith ( '<STR_LIT:U+0020>' ) : <EOL> if current_func : <EOL> functions . append ( ( current_func , rest ) ) <EOL> current_func = None <EOL> rest = [ ] <EOL> if '<STR_LIT:U+002C>' in line : <EOL> for func in line . split ( '<STR_LIT:U+002C>' ) : <EOL> func = func . strip ( ) <EOL> if func : <EOL> functions . append ( ( func , [ ] ) ) <EOL> elif line . strip ( ) : <EOL> current_func = line . strip ( ) <EOL> elif current_func is not None : <EOL> rest . append ( line . strip ( ) ) <EOL> if current_func : <EOL> functions . append ( ( current_func , rest ) ) <EOL> return functions <EOL> def _parse_index ( self , section , content ) : <EOL> """<STR_LIT>""" <EOL> def strip_each_in ( lst ) : <EOL> return [ s . strip ( ) for s in lst ] <EOL> out = { } <EOL> section = section . split ( '<STR_LIT>' ) <EOL> if len ( section ) > <NUM_LIT:1> : <EOL> out [ '<STR_LIT:default>' ] = strip_each_in ( section [ <NUM_LIT:1> ] . split ( '<STR_LIT:U+002C>' ) ) [ <NUM_LIT:0> ] <EOL> for line in content : <EOL> line = line . split ( '<STR_LIT::>' ) <EOL> if len ( line ) > <NUM_LIT:2> : <EOL> out [ line [ <NUM_LIT:1> ] ] = strip_each_in ( line [ <NUM_LIT:2> ] . split ( '<STR_LIT:U+002C>' ) ) <EOL> return out <EOL> def _parse_summary ( self ) : <EOL> """<STR_LIT>""" <EOL> summary = self . _doc . read_to_next_empty_line ( ) <EOL> summary_str = "<STR_LIT:\n>" . join ( [ s . strip ( ) for s in summary ] ) <EOL> if re . compile ( '<STR_LIT>' ) . match ( summary_str ) : <EOL> self [ '<STR_LIT>' ] = summary_str <EOL> if not self . _is_at_section ( ) : <EOL> self [ '<STR_LIT>' ] = self . _doc . read_to_next_empty_line ( ) <EOL> elif re . compile ( '<STR_LIT>' ) . match ( summary_str ) : <EOL> self [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> self . _doc . reset ( ) <EOL> else : <EOL> self [ '<STR_LIT>' ] = summary <EOL> if not self . _is_at_section ( ) : <EOL> self [ '<STR_LIT>' ] = self . _read_to_next_section ( ) <EOL> def _parse ( self ) : <EOL> self . _doc . reset ( ) <EOL> self . _parse_summary ( ) <EOL> for ( section , content ) in self . _read_sections ( ) : <EOL> if not section . startswith ( '<STR_LIT:..>' ) : <EOL> section = '<STR_LIT:U+0020>' . join ( [ s . capitalize ( ) <EOL> for s in section . split ( '<STR_LIT:U+0020>' ) ] ) <EOL> if section in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> self [ section ] = self . _parse_param_list ( content ) <EOL> self . section_order . append ( section ) <EOL> elif section . startswith ( '<STR_LIT>' ) : <EOL> self [ '<STR_LIT:index>' ] = self . _parse_index ( section , content ) <EOL> self . section_order . append ( '<STR_LIT:index>' ) <EOL> elif section . lower ( ) == '<STR_LIT>' : <EOL> self [ '<STR_LIT>' ] = self . _parse_see_also ( content ) <EOL> self . section_order . append ( '<STR_LIT>' ) <EOL> else : <EOL> self [ section ] = content <EOL> self . section_order . append ( section ) <EOL> def _str_header ( self , name , symbol = '<STR_LIT:->' ) : <EOL> return [ name , len ( name ) * symbol ] <EOL> def _str_indent ( self , doc , indent = <NUM_LIT:4> ) : <EOL> out = [ ] <EOL> for line in doc : <EOL> out += [ '<STR_LIT:U+0020>' * indent + line ] <EOL> return out <EOL> def _str_signature ( self ) : <EOL> if not self [ '<STR_LIT>' ] : <EOL> return [ ] <EOL> return [ "<STR_LIT>" % self [ '<STR_LIT>' ] . replace ( '<STR_LIT:*>' , '<STR_LIT>' ) ] + [ '<STR_LIT>' ] <EOL> def _str_summary ( self ) : <EOL> return self [ '<STR_LIT>' ] + [ '<STR_LIT>' ] <EOL> def _str_extended_summary ( self ) : <EOL> return self [ '<STR_LIT>' ] + [ '<STR_LIT>' ] <EOL> def _str_param_list ( self , name ) : <EOL> out = [ ] <EOL> if self [ name ] : <EOL> out += self . _str_header ( name ) <EOL> for param , param_type , desc in self [ name ] : <EOL> out += [ '<STR_LIT>' % ( param , param_type ) ] <EOL> out += self . _str_indent ( desc ) <EOL> out += [ '<STR_LIT>' ] <EOL> return out <EOL> def _str_section ( self , name ) : <EOL> out = [ ] <EOL> if self [ name ] : <EOL> out += self . _str_header ( name ) <EOL> out += self [ name ] <EOL> out += [ '<STR_LIT>' ] <EOL> return out <EOL> def _str_see_also ( self ) : <EOL> if not self [ '<STR_LIT>' ] : return [ ] <EOL> out = [ ] <EOL> out += self . _str_header ( "<STR_LIT>" ) <EOL> last_had_desc = True <EOL> for func , desc in self [ '<STR_LIT>' ] : <EOL> if desc or last_had_desc : <EOL> out += [ '<STR_LIT>' ] <EOL> out += [ "<STR_LIT>" % func ] <EOL> else : <EOL> out [ - <NUM_LIT:1> ] += "<STR_LIT>" % func <EOL> if desc : <EOL> out += self . _str_indent ( desc ) <EOL> last_had_desc = True <EOL> else : <EOL> last_had_desc = False <EOL> out += [ '<STR_LIT>' ] <EOL> return out <EOL> def _str_index ( self ) : <EOL> idx = self [ '<STR_LIT:index>' ] <EOL> out = [ ] <EOL> out += [ '<STR_LIT>' % idx . get ( '<STR_LIT:default>' , '<STR_LIT>' ) ] <EOL> for section , references in six . iteritems ( idx ) : <EOL> if section == '<STR_LIT:default>' : <EOL> continue <EOL> out += [ '<STR_LIT>' % ( section , '<STR_LIT:U+002CU+0020>' . join ( references ) ) ] <EOL> return out <EOL> def __str__ ( self ) : <EOL> out = [ ] <EOL> out += self . _str_signature ( ) <EOL> out += self . _str_summary ( ) <EOL> out += self . _str_extended_summary ( ) <EOL> for param_list in ( '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> out += self . _str_param_list ( param_list ) <EOL> out += self . _str_see_also ( ) <EOL> for s in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> out += self . _str_section ( s ) <EOL> out += self . _str_index ( ) <EOL> return '<STR_LIT:\n>' . join ( out ) <EOL> def get_errors ( self , check_order = True ) : <EOL> errors = [ ] <EOL> self . _doc . reset ( ) <EOL> for j , line in enumerate ( self . _doc ) : <EOL> if len ( line ) > <NUM_LIT> : <EOL> if hasattr ( self , '<STR_LIT:name>' ) : <EOL> errors . append ( "<STR_LIT>" <EOL> "<STR_LIT>" % ( self . name , j + <NUM_LIT:1> , line [ : <NUM_LIT:30> ] ) ) <EOL> else : <EOL> errors . append ( "<STR_LIT>" <EOL> "<STR_LIT>" % ( j + <NUM_LIT:1> , line [ : <NUM_LIT:30> ] ) ) <EOL> if check_order : <EOL> canonical_order = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT:index>' ] <EOL> canonical_order_copy = list ( canonical_order ) <EOL> for s in self . section_order : <EOL> while canonical_order_copy and s != canonical_order_copy [ <NUM_LIT:0> ] : <EOL> canonical_order_copy . pop ( <NUM_LIT:0> ) <EOL> if not canonical_order_copy : <EOL> errors . append ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" % ( s , canonical_order ) ) <EOL> return errors <EOL> def indent ( str , indent = <NUM_LIT:4> ) : <EOL> indent_str = '<STR_LIT:U+0020>' * indent <EOL> if str is None : <EOL> return indent_str <EOL> lines = str . split ( '<STR_LIT:\n>' ) <EOL> return '<STR_LIT:\n>' . join ( indent_str + l for l in lines ) <EOL> class NumpyFunctionDocString ( NumpyDocString ) : <EOL> def __init__ ( self , docstring , function ) : <EOL> super ( NumpyFunctionDocString , self ) . __init__ ( docstring ) <EOL> args , varargs , keywords , defaults = inspect . getargspec ( function ) <EOL> if ( args and args != [ '<STR_LIT>' ] ) or varargs or keywords or defaults : <EOL> self . has_parameters = True <EOL> else : <EOL> self . has_parameters = False <EOL> def _parse ( self ) : <EOL> self . _parsed_data = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:index>' : { } , <EOL> } <EOL> return NumpyDocString . _parse ( self ) <EOL> def get_errors ( self ) : <EOL> errors = NumpyDocString . get_errors ( self ) <EOL> if not self [ '<STR_LIT>' ] : <EOL> pass <EOL> if not self [ '<STR_LIT>' ] : <EOL> errors . append ( "<STR_LIT>" ) <EOL> if len ( "<STR_LIT:U+0020>" . join ( self [ '<STR_LIT>' ] ) ) > <NUM_LIT:3> * <NUM_LIT> : <EOL> errors . append ( "<STR_LIT>" ) <EOL> if not self [ '<STR_LIT>' ] and self . has_parameters : <EOL> errors . append ( "<STR_LIT>" ) <EOL> return errors <EOL> class NumpyClassDocString ( NumpyDocString ) : <EOL> def __init__ ( self , docstring , class_name , class_object ) : <EOL> super ( NumpyClassDocString , self ) . __init__ ( docstring ) <EOL> self . class_name = class_name <EOL> methods = dict ( ( name , func ) for name , func <EOL> in inspect . getmembers ( class_object ) ) <EOL> self . has_parameters = False <EOL> if '<STR_LIT>' in methods : <EOL> if not inspect . ismethod ( methods [ '<STR_LIT>' ] ) : <EOL> return <EOL> args , varargs , keywords , defaults = inspect . getargspec ( <EOL> methods [ '<STR_LIT>' ] ) <EOL> if ( args and args != [ '<STR_LIT>' ] ) or varargs or keywords or defaults : <EOL> self . has_parameters = True <EOL> def _parse ( self ) : <EOL> self . _parsed_data = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:index>' : { } , <EOL> '<STR_LIT>' : [ ] , <EOL> '<STR_LIT>' : [ ] , <EOL> } <EOL> return NumpyDocString . _parse ( self ) <EOL> def __str__ ( self ) : <EOL> out = [ ] <EOL> out += self . _str_signature ( ) <EOL> out += self . _str_summary ( ) <EOL> out += self . _str_extended_summary ( ) <EOL> for param_list in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ) : <EOL> out += self . _str_param_list ( param_list ) <EOL> out += self . _str_see_also ( ) <EOL> for s in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> out += self . _str_section ( s ) <EOL> out += self . _str_index ( ) <EOL> return '<STR_LIT:\n>' . join ( out ) <EOL> def get_errors ( self ) : <EOL> errors = NumpyDocString . get_errors ( self ) <EOL> if not self [ '<STR_LIT>' ] and self . has_parameters : <EOL> errors . append ( "<STR_LIT>" <EOL> % self . class_name ) <EOL> return errors <EOL> class NumpyModuleDocString ( NumpyDocString ) : <EOL> """<STR_LIT>""" <EOL> def _parse ( self ) : <EOL> self . out = [ ] <EOL> def __str__ ( self ) : <EOL> return "<STR_LIT:\n>" . join ( self . _doc . _str ) <EOL> def get_errors ( self ) : <EOL> errors = NumpyDocString . get_errors ( self , check_order = False ) <EOL> return errors <EOL> def header ( text , style = '<STR_LIT:->' ) : <EOL> return text + '<STR_LIT:\n>' + style * len ( text ) + '<STR_LIT:\n>' <EOL> class SphinxDocString ( NumpyDocString ) : <EOL> def _str_header ( self , name , symbol = '<STR_LIT>' ) : <EOL> return [ '<STR_LIT>' + name + '<STR_LIT>' ] + [ symbol * ( len ( name ) + <NUM_LIT:4> ) ] <EOL> def _str_indent ( self , doc , indent = <NUM_LIT:4> ) : <EOL> out = [ ] <EOL> for line in doc : <EOL> out += [ '<STR_LIT:U+0020>' * indent + line ] <EOL> return out <EOL> def _str_signature ( self ) : <EOL> return [ '<STR_LIT>' % self [ '<STR_LIT>' ] . replace ( '<STR_LIT:*>' , '<STR_LIT>' ) ] + [ '<STR_LIT>' ] <EOL> def _str_summary ( self ) : <EOL> return self [ '<STR_LIT>' ] + [ '<STR_LIT>' ] <EOL> def _str_extended_summary ( self ) : <EOL> return self [ '<STR_LIT>' ] + [ '<STR_LIT>' ] <EOL> def _str_param_list ( self , name ) : <EOL> out = [ ] <EOL> if self [ name ] : <EOL> out += self . _str_header ( name ) <EOL> out += [ '<STR_LIT>' ] <EOL> for param , param_type , desc in self [ name ] : <EOL> out += self . _str_indent ( [ '<STR_LIT>' % ( param , param_type ) ] ) <EOL> out += [ '<STR_LIT>' ] <EOL> out += self . _str_indent ( desc , <NUM_LIT:8> ) <EOL> out += [ '<STR_LIT>' ] <EOL> return out <EOL> def _str_section ( self , name ) : <EOL> out = [ ] <EOL> if self [ name ] : <EOL> out += self . _str_header ( name ) <EOL> out += [ '<STR_LIT>' ] <EOL> content = self . _str_indent ( self [ name ] ) <EOL> out += content <EOL> out += [ '<STR_LIT>' ] <EOL> return out <EOL> def _str_index ( self ) : <EOL> idx = self [ '<STR_LIT:index>' ] <EOL> out = [ ] <EOL> out += [ '<STR_LIT>' % idx . get ( '<STR_LIT:default>' , '<STR_LIT>' ) ] <EOL> for section , references in six . iteritems ( idx ) : <EOL> if section == '<STR_LIT:default>' : <EOL> continue <EOL> out += [ '<STR_LIT>' % ( section , '<STR_LIT:U+002CU+0020>' . join ( references ) ) ] <EOL> return out <EOL> def __str__ ( self , indent = <NUM_LIT:0> ) : <EOL> out = [ ] <EOL> out += self . _str_summary ( ) <EOL> out += self . _str_extended_summary ( ) <EOL> for param_list in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> out += self . _str_param_list ( param_list ) <EOL> for s in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> out += self . _str_section ( s ) <EOL> out = self . _str_indent ( out , indent ) <EOL> return '<STR_LIT:\n>' . join ( out ) <EOL> class FunctionDoc ( object ) : <EOL> def __init__ ( self , func ) : <EOL> self . _f = func <EOL> def __str__ ( self ) : <EOL> out = '<STR_LIT>' <EOL> doclines = inspect . getdoc ( self . _f ) or '<STR_LIT>' <EOL> try : <EOL> doc = SphinxDocString ( doclines ) <EOL> except Exception as e : <EOL> print ( '<STR_LIT:*>' * <NUM_LIT> ) <EOL> print ( "<STR_LIT>" % ( e , self . _f ) ) <EOL> print ( '<STR_LIT:*>' * <NUM_LIT> ) <EOL> return out <EOL> if doc [ '<STR_LIT>' ] : <EOL> out += '<STR_LIT>' % header ( '<STR_LIT>' % <EOL> doc [ '<STR_LIT>' ] . replace ( '<STR_LIT:*>' , '<STR_LIT>' ) , '<STR_LIT:->' ) <EOL> else : <EOL> try : <EOL> argspec = inspect . getargspec ( self . _f ) <EOL> argspec = inspect . formatargspec ( * argspec ) <EOL> argspec = argspec . replace ( '<STR_LIT:*>' , '<STR_LIT>' ) <EOL> out += header ( '<STR_LIT>' % ( self . _f . __name__ , argspec ) , '<STR_LIT:->' ) <EOL> except TypeError as e : <EOL> out += '<STR_LIT>' % header ( '<STR_LIT>' % self . _f . __name__ , '<STR_LIT:->' ) <EOL> out += str ( doc ) <EOL> return out <EOL> class ClassDoc ( object ) : <EOL> def __init__ ( self , cls , modulename = '<STR_LIT>' ) : <EOL> if not inspect . isclass ( cls ) : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> self . _cls = cls <EOL> if modulename and not modulename . endswith ( '<STR_LIT:.>' ) : <EOL> modulename += '<STR_LIT:.>' <EOL> self . _mod = modulename <EOL> self . _name = cls . __name__ <EOL> @ property <EOL> def methods ( self ) : <EOL> return [ name for name , func in inspect . getmembers ( self . _cls ) <EOL> if not name . startswith ( '<STR_LIT:_>' ) and callable ( func ) ] <EOL> def __str__ ( self ) : <EOL> out = '<STR_LIT>' <EOL> def replace_header ( match ) : <EOL> return '<STR_LIT:">' * ( match . end ( ) - match . start ( ) ) <EOL> for m in self . methods : <EOL> print ( "<STR_LIT>" % m ) <EOL> out += str ( FunctionDoc ( getattr ( self . _cls , m ) ) ) + '<STR_LIT>' <EOL> out += '<STR_LIT>' % ( self . _name , m ) <EOL> return out <EOL> def handle_function ( val , name ) : <EOL> func_errors = [ ] <EOL> docstring = inspect . getdoc ( val ) <EOL> if docstring is None : <EOL> func_errors . append ( ( name , '<STR_LIT>' ) ) <EOL> else : <EOL> func_errors = [ <EOL> ( name , e ) for e in <EOL> NumpyFunctionDocString ( docstring , val ) . get_errors ( ) <EOL> ] <EOL> return func_errors <EOL> def handle_module ( val , name ) : <EOL> module_errors = [ ] <EOL> docstring = val <EOL> if docstring is None : <EOL> module_errors . append ( ( name , '<STR_LIT>' ) ) <EOL> else : <EOL> module_errors = [ <EOL> ( name , e ) for e in NumpyModuleDocString ( docstring ) . get_errors ( ) <EOL> ] <EOL> return module_errors <EOL> def handle_method ( method , method_name , class_name ) : <EOL> method_errors = [ ] <EOL> module = inspect . getmodule ( method ) <EOL> if module is not None : <EOL> if not module . __name__ . startswith ( '<STR_LIT>' ) : <EOL> return method_errors <EOL> docstring = inspect . getdoc ( method ) <EOL> if docstring is None : <EOL> method_errors . append ( ( class_name , method_name , <EOL> '<STR_LIT>' ) ) <EOL> else : <EOL> method_errors = [ <EOL> ( class_name , method_name , e ) for e in <EOL> NumpyFunctionDocString ( docstring , method ) . get_errors ( ) <EOL> ] <EOL> return method_errors <EOL> def handle_class ( val , class_name ) : <EOL> cls_errors = [ ] <EOL> docstring = inspect . getdoc ( val ) <EOL> if docstring is None : <EOL> cls_errors . append ( ( class_name , <EOL> '<STR_LIT>' ) ) <EOL> else : <EOL> cls_errors = [ <EOL> ( e , ) for e in <EOL> NumpyClassDocString ( docstring , class_name , val ) . get_errors ( ) <EOL> ] <EOL> methods = dict ( ( ( name , func ) for name , func in inspect . getmembers ( val ) <EOL> if not name . startswith ( '<STR_LIT:_>' ) and callable ( func ) and type ( func ) is not type ) ) <EOL> for m_name , method in six . iteritems ( methods ) : <EOL> if inspect . getmodule ( method ) is not None : <EOL> continue <EOL> cls_errors . extend ( handle_method ( method , m_name , class_name ) ) <EOL> return cls_errors <EOL> def docstring_errors ( filename , global_dict = None ) : <EOL> """<STR_LIT>""" <EOL> if global_dict is None : <EOL> global_dict = { } <EOL> if '<STR_LIT>' not in global_dict : <EOL> global_dict [ '<STR_LIT>' ] = filename <EOL> if '<STR_LIT>' not in global_dict : <EOL> global_dict [ '<STR_LIT>' ] = None <EOL> try : <EOL> with open ( filename ) as f : <EOL> code = compile ( f . read ( ) , filename , '<STR_LIT>' ) <EOL> exec ( code , global_dict ) <EOL> except SystemExit : <EOL> pass <EOL> except SkipTest : <EOL> raise AssertionError ( "<STR_LIT>" + filename + <EOL> "<STR_LIT>" ) <EOL> all_errors = [ ] <EOL> for key , val in six . iteritems ( global_dict ) : <EOL> if not key . startswith ( '<STR_LIT:_>' ) : <EOL> module_name = "<STR_LIT>" <EOL> if hasattr ( inspect . getmodule ( val ) , '<STR_LIT>' ) : <EOL> module_name = inspect . getmodule ( val ) . __name__ <EOL> if ( inspect . isfunction ( val ) or inspect . isclass ( val ) ) and ( inspect . getmodule ( val ) is None <EOL> or module_name == '<STR_LIT>' ) : <EOL> if inspect . isfunction ( val ) : <EOL> all_errors . extend ( handle_function ( val , key ) ) <EOL> elif inspect . isclass ( val ) : <EOL> all_errors . extend ( handle_class ( val , key ) ) <EOL> elif key == '<STR_LIT>' : <EOL> all_errors . extend ( handle_module ( val , key ) ) <EOL> if all_errors : <EOL> all_errors . insert ( <NUM_LIT:0> , ( "<STR_LIT>" % filename , ) ) <EOL> return all_errors <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> all_errors = docstring_errors ( sys . argv [ <NUM_LIT:1> ] ) <EOL> if len ( all_errors ) > <NUM_LIT:0> : <EOL> print ( "<STR_LIT:*>" * <NUM_LIT:30> , "<STR_LIT>" , "<STR_LIT:*>" * <NUM_LIT:30> ) <EOL> for line in all_errors : <EOL> print ( '<STR_LIT::>' . join ( line ) ) <EOL> sys . exit ( int ( len ( all_errors ) > <NUM_LIT:0> ) ) </s>
