<s> """<STR_LIT>""" <EOL> from __future__ import division , absolute_import , print_function <EOL> import os , sys , re , pydoc <EOL> import sphinx <EOL> import inspect <EOL> import collections <EOL> import textwrap <EOL> if sphinx . __version__ < '<STR_LIT>' : <EOL> raise RuntimeError ( "<STR_LIT>" ) <EOL> from numpydoc . numpydoc import mangle_docstrings <EOL> from docutils . parsers . rst import Directive <EOL> from docutils . statemachine import ViewList <EOL> from sphinx . domains . python import PythonDomain <EOL> if sys . version_info [ <NUM_LIT:0> ] >= <NUM_LIT:3> : <EOL> sixu = lambda s : s <EOL> else : <EOL> sixu = lambda s : unicode ( s , '<STR_LIT>' ) <EOL> def setup ( app ) : <EOL> app . add_domain ( ScipyOptimizeInterfaceDomain ) <EOL> def _option_required_str ( x ) : <EOL> if not x : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> return str ( x ) <EOL> def _import_object ( name ) : <EOL> parts = name . split ( '<STR_LIT:.>' ) <EOL> module_name = '<STR_LIT:.>' . join ( parts [ : - <NUM_LIT:1> ] ) <EOL> __import__ ( module_name ) <EOL> obj = getattr ( sys . modules [ module_name ] , parts [ - <NUM_LIT:1> ] ) <EOL> return obj <EOL> class ScipyOptimizeInterfaceDomain ( PythonDomain ) : <EOL> name = '<STR_LIT>' <EOL> def __init__ ( self , * a , ** kw ) : <EOL> super ( ScipyOptimizeInterfaceDomain , self ) . __init__ ( * a , ** kw ) <EOL> self . directives = dict ( self . directives ) <EOL> self . directives [ '<STR_LIT>' ] = wrap_mangling_directive ( self . directives [ '<STR_LIT>' ] ) <EOL> BLURB = """<STR_LIT>""" <EOL> def wrap_mangling_directive ( base_directive ) : <EOL> class directive ( base_directive ) : <EOL> def run ( self ) : <EOL> env = self . state . document . settings . env <EOL> name = self . arguments [ <NUM_LIT:0> ] . strip ( ) <EOL> obj = _import_object ( name ) <EOL> args , varargs , keywords , defaults = inspect . getargspec ( obj ) <EOL> impl_name = self . options [ '<STR_LIT>' ] <EOL> impl_obj = _import_object ( impl_name ) <EOL> impl_args , impl_varargs , impl_keywords , impl_defaults = inspect . getargspec ( impl_obj ) <EOL> args = list ( args ) <EOL> defaults = list ( defaults ) <EOL> def set_default ( arg , value ) : <EOL> j = args . index ( arg ) <EOL> defaults [ len ( defaults ) - ( len ( args ) - j ) ] = value <EOL> def remove_arg ( arg ) : <EOL> if arg not in args : <EOL> return <EOL> j = args . index ( arg ) <EOL> if j < len ( args ) - len ( defaults ) : <EOL> del args [ j ] <EOL> else : <EOL> del defaults [ len ( defaults ) - ( len ( args ) - j ) ] <EOL> del args [ j ] <EOL> options = [ ] <EOL> for j , opt_name in enumerate ( impl_args ) : <EOL> if opt_name in args : <EOL> continue <EOL> if j >= len ( impl_args ) - len ( impl_defaults ) : <EOL> options . append ( ( opt_name , impl_defaults [ len ( impl_defaults ) - ( len ( impl_args ) - j ) ] ) ) <EOL> else : <EOL> options . append ( ( opt_name , None ) ) <EOL> set_default ( '<STR_LIT>' , dict ( options ) ) <EOL> set_default ( '<STR_LIT>' , self . options [ '<STR_LIT>' ] . strip ( ) ) <EOL> for arg in list ( args ) : <EOL> if arg not in impl_args and arg not in ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:args>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> remove_arg ( arg ) <EOL> signature = inspect . formatargspec ( args , varargs , keywords , defaults ) <EOL> self . options [ '<STR_LIT>' ] = True <EOL> self . arguments [ <NUM_LIT:0> ] = name + signature <EOL> lines = textwrap . dedent ( pydoc . getdoc ( impl_obj ) ) . splitlines ( ) <EOL> new_lines = [ ] <EOL> for line in lines : <EOL> if line . strip ( ) == '<STR_LIT>' : <EOL> new_lines . append ( "<STR_LIT>" ) <EOL> elif line . strip ( ) == "<STR_LIT:->" * len ( '<STR_LIT>' ) : <EOL> new_lines . append ( "<STR_LIT:->" * len ( "<STR_LIT>" ) ) <EOL> else : <EOL> new_lines . append ( line ) <EOL> mangle_docstrings ( env . app , '<STR_LIT>' , name , None , None , new_lines ) <EOL> lines = new_lines <EOL> new_lines = [ ] <EOL> for line in lines : <EOL> if line . strip ( ) == '<STR_LIT>' : <EOL> new_lines . extend ( ( BLURB % ( name , ) ) . splitlines ( ) ) <EOL> new_lines . append ( '<STR_LIT>' ) <EOL> else : <EOL> new_lines . append ( line ) <EOL> self . content = ViewList ( new_lines , self . content . parent ) <EOL> return base_directive . run ( self ) <EOL> option_spec = dict ( base_directive . option_spec ) <EOL> option_spec [ '<STR_LIT>' ] = _option_required_str <EOL> option_spec [ '<STR_LIT>' ] = _option_required_str <EOL> return directive </s>
