#NEWLINE# def parse_docstring( docstring ) : #NEWLINE# #INDENT# "\n    Parse a docstring into its parts.\n\n    Currently only parses dependencies, can be extended to parse whatever is\n    needed.\n\n    Parses into a dictionary:\n        {\n            'full': full docstring,\n            'deps': list of dependencies (empty list if none)\n        }\n    " #NEWLINE# ret = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# ret [ 'full' ] = docstring #NEWLINE# regex = '([ \\t]*):depends:[ \\t]+- (\\w+)[^\\n]*\\n(\\1[ \\t]+- (\\w+)[^\\n]*\\n)*' #NEWLINE# match = re . search ( regex , docstring , re . M ) #NEWLINE# if match : #NEWLINE# #INDENT# deps = [ ] #NEWLINE# regex = '- (\\w+)' #NEWLINE# for line in match . group ( 0 ) . strip ( ) . splitlines ( ) : #NEWLINE# #INDENT# deps . append ( re . search ( regex , line ) . group ( 1 ) ) #NEWLINE# #UNINDENT# ret [ 'deps' ] = deps #NEWLINE# return ret #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# txt = 'Required python modules: ' #NEWLINE# data = docstring . splitlines ( ) #NEWLINE# dep_list = list ( ( x for x in data if x . strip ( ) . startswith ( txt ) ) ) #NEWLINE# if ( not dep_list ) : #NEWLINE# #INDENT# ret [ 'deps' ] = [ ] #NEWLINE# return ret #NEWLINE# #UNINDENT# deps = dep_list [ 0 ] . replace ( txt , '' ) . strip ( ) . split ( ', ' ) #NEWLINE# ret [ 'deps' ] = deps #NEWLINE# return ret