def parse_docstring(docstring):
 ret = {}
 ret['full'] = docstring
 regex = '([ \\t]*):depends:[ \\t]+- (\\w+)[^\\n]*\\n(\\1[ \\t]+- (\\w+)[^\\n]*\\n)*'
 match = re.search(regex, docstring, re.M)
 if match:
  deps = []
  regex = '- (\\w+)'
  for line in match.group(0).strip().splitlines():
   deps.append(re.search(regex, line).group(1))
  ret['deps'] = deps
  return ret
 else:
  txt = 'Required python modules: '
  data = docstring.splitlines()
  dep_list = list((x for x in data if x.strip().startswith(txt)))
  if (not dep_list):
   ret['deps'] = []
   return ret
  deps = dep_list[0].replace(txt, '').strip().split(', ')
  ret['deps'] = deps
  return ret

def parse_docstring ( docstring ) : ret = { } ret [ 'full' ] = docstring regex = '([ \\t]*):depends:[ \\t]+- (\\w+)[^\\n]*\\n(\\1[ \\t]+- (\\w+)[^\\n]*\\n)*' match = re . search ( regex , docstring , re . M ) if match : deps = [ ] regex = '- (\\w+)' for line in match . group ( 0 ) . strip ( ) . splitlines ( ) : deps . append ( re . search ( regex , line ) . group ( 1 ) ) ret [ 'deps' ] = deps return ret else : txt = 'Required python modules: ' data = docstring . splitlines ( ) dep_list = list ( ( x for x in data if x . strip ( ) . startswith ( txt ) ) ) if ( not dep_list ) : ret [ 'deps' ] = [ ] return ret deps = dep_list [ 0 ] . replace ( txt , '' ) . strip ( ) . split ( ', ' ) ret [ 'deps' ] = deps return ret
parse out the parts of a docstring .