ó
‹²,]c           @   s   d  Z  d „  Z d S(   s`  
Patching rope:

[1] For compatibility with Spyder's standalone version, built with py2exe or
    cx_Freeze

[2] For better performance, see this thread:
    https://groups.google.com/forum/#!topic/rope-dev/V95XMfICU3o

[3] To avoid considering folders without __init__.py as Python packages, thus
    avoiding side effects as non-working introspection features on a Python
    module or package when a folder in current directory has the same name.
    See this thread:
    https://groups.google.com/forum/#!topic/rope-dev/kkxLWmJo5hg

[4] To avoid rope adding a 2 spaces indent to every docstring it gets, because
    it breaks the work of Sphinx on the Help plugin. Also, to better
    control how to get calltips and docstrings of forced builtin objects.

[5] To make matplotlib return its docstrings in proper rst, instead of a mix
    of rst and plain text.
c    
         s¾  d d l  m }  |  d d ƒ rA d d l } t d | j ƒ ‚ n  d d l m } | ƒ  r d d l m } d	 | j	 f d
 „  ƒ  Y} | | _	 n  d d l m
 ‰ d ˆ j f ‡ f d †  ƒ  Y} | ˆ _ d d l m ‰  m ‰ m ‰ d d l ‰ d d l j ‰ d ˆ  j f ‡  ‡ ‡ ‡ ‡ f d †  ƒ  Y} | ˆ  _ d d l m } d d l m ‰ d d l m ‰ d | j f ‡  ‡ ‡ ‡ f d †  ƒ  Y} | | _ y d d l }	 t |	 j d <Wn n Xd S(   sM   Monkey patching rope

    See [1], [2], [3], [4] and [5] in module docstring.iÿÿÿÿ(   t   is_module_installedt   ropes   <0.9.4Ns   rope %s can't be patched(   t   is_py2exe_or_cx_Freeze(   t   projectt   PatchedProjectc           B   s   e  Z d  „  Z RS(   c         S   s2   d d l  m } | d d ƒ } t | d ƒ j ƒ  S(   Niÿÿÿÿ(   t   get_module_source_patht   spyders   default_config.pyt   rb(   t   spyder.config.baseR   t   opent   read(   t   selfR   t   fname(    (    sD   lib/python2.7/site-packages/spyder/utils/introspection/rope_patch.pyt   _default_config-   s    	(   t   __name__t
   __module__R   (    (    (    sD   lib/python2.7/site-packages/spyder/utils/introspection/rope_patch.pyR   ,   s   (   t   pycoret   PatchedPyCorec              s#   e  Z d ‡  f d  † Z d „  Z RS(   c            s`   |  j  | ƒ } | d k	 r | S|  j | | ƒ } | d k rS ˆ  j d | ƒ ‚ n  |  j | ƒ S(   s-   Returns a `PyObject` if the module was found.s   Module %s not foundN(   t   _builtin_modulet   Nonet   find_modulet   ModuleNotFoundErrort   resource_to_pyobject(   R   t   namet   foldert   pymodt   module(   R   (    sD   lib/python2.7/site-packages/spyder/utils/introspection/rope_patch.pyt
   get_module=   s    c         S   s  | } | j  d ƒ } xC | d  D]7 } | j ƒ  rS | j | ƒ rS | j | ƒ } q  d  Sq  W| j ƒ  r| j | d ƒ rÀ | j | d ƒ j ƒ  rÀ | j | d ƒ j d ƒ rÀ | j | d ƒ S| j | d d ƒ r| j | d d ƒ j ƒ  r| j | d d ƒ Sn  d  S(   Nt   .iÿÿÿÿs   __init__.pys   .py(   t   splitt	   is_foldert	   has_childt	   get_childR   (   R   R   t   modnameR   t   packagest   pkg(    (    sD   lib/python2.7/site-packages/spyder/utils/introspection/rope_patch.pyt   _find_module_in_folderJ   s    N(   R   R   R   R   R$   (    (   R   (    sD   lib/python2.7/site-packages/spyder/utils/introspection/rope_patch.pyR   7   s   (   t   builtinst   libutilst	   pyobjectst   PatchedBuiltinNamec              s/   e  Z ‡  f d  †  Z ‡ ‡ ‡ ‡ f d †  Z RS(   c            sT   |  j  } x | j d  k	 r' | j } q Wt | ˆ  j ƒ rP | j d  k	 rP | j Sd  S(   N(   t   pyobjectt   parentR   t
   isinstancet   BuiltinModuleR   (   R   t   p(   R%   (    sD   lib/python2.7/site-packages/spyder/utils/introspection/rope_patch.pyt   _pycoreb   s
    	!c            sÇ   ˆ  j  |  j ƒ sÃ ˆ  j |  j j ƒ \ } } ˆ  j |  j j ƒ } | j d ƒ rq ˆ j | d  ƒ rq | d  } n  |  j ƒ  } | rÃ | j rÃ ˆ j	 | j | ƒ } ˆ j
 | d  | ƒ } | | f Sn  d S(   Nt   pyciÿÿÿÿ(   NN(   t	   isbuiltinR)   t   getsourcelinest   builtint   getfilet   endswitht   isfileR.   R   t   path_to_resourcet   PyModuleR   (   R   t   _linest   linenot   pathR   t   resourceR   (   t   inspectR&   t   ospR'   (    sD   lib/python2.7/site-packages/spyder/utils/introspection/rope_patch.pyt   get_definition_locationh   s    "(   R   R   R.   R>   (    (   R%   R<   R&   R=   R'   (    sD   lib/python2.7/site-packages/spyder/utils/introspection/rope_patch.pyR(   a   s   (   t
   codeassist(   t   getdoc(   t
   exceptionst   PatchedPyDocExtractorc              sY   e  Z ‡ f d  †  Z ‡  ‡ f d †  Z e e ‡ ‡ f d † Z ‡ f d †  Z d „  Z RS(   c            s   | j  } ˆ  | ƒ S(   N(   R2   (   R   R)   t   buitin(   R@   (    sD   lib/python2.7/site-packages/spyder/utils/introspection/rope_patch.pyt   get_builtin_docˆ   s    	c            s  t  | d ƒ r" |  j | ƒ } | St | ˆ  j ƒ rŠ | j ƒ  } | d  k	 r^ |  j | ƒ } n d } i d d 6d d 6d d 6| d 6} | St | ˆ j ƒ r© |  j | ƒ St | ˆ j	 ƒ rÈ |  j
 | ƒ St | ˆ j ƒ rí |  j | j ƒ  ƒ S| j ƒ  d  k	 r|  j | j ƒ  ƒ Sd  S(   NR2   t    R   t   argspect   notet	   docstring(   t   hasattrRD   R+   R,   t   get_docR   t   _trim_docstringt   AbstractFunctiont   _get_function_docstringt   AbstractClasst   _get_class_docstringt   AbstractModule(   R   R)   t   docRH   (   R%   R'   (    sD   lib/python2.7/site-packages/spyder/utils/introspection/rope_patch.pyRJ   Œ   s,    

c            s  t  | d ƒ r. |  j | ƒ } | d | d SyN t | ˆ j ƒ rV | d j ƒ  } n  t | ˆ j ƒ s{ | d j ƒ  } n  Wn ˆ  j k
 r“ d  SX| r± t | ˆ j ƒ r± d  St | ˆ j ƒ r|  j	 | d t
 ƒ} | r	|  j | ƒ r	| j d d ƒ j d	 d
 ƒ S| Sd  S(   NR2   R   RF   t   __init__t   __call__t
   add_modules   (self)s   ()s   (self, t   ((   RI   RD   R+   RN   t
   get_objectRL   t   AttributeNotFoundErrorR   t
   PyFunctiont   _get_function_signaturet   Truet
   _is_methodt   replace(   R   R)   t   ignore_unknownt   remove_selfRQ   t   result(   RA   R'   (    sD   lib/python2.7/site-packages/spyder/utils/introspection/rope_patch.pyt   get_calltip©   s"    c            s²   |  j  | j ƒ  d d ƒ} g  | j ƒ  D] } | j ƒ  ^ q( } d | j ƒ  d j | ƒ f | } d | k r® | d j ƒ  } t | ˆ  j ƒ r® | d |  j | ƒ 7} q® n  | S(   Nt   indentsi    s   class %s(%s):

s   , RR   s   

(	   RK   RJ   t   get_superclassest   get_namet   joinRV   R+   RL   t   _get_single_function_docstring(   R   t   pyclasst   contentst   supert   supersRQ   t   init(   R'   (    sD   lib/python2.7/site-packages/spyder/utils/introspection/rope_patch.pyRO   ¼   s    %#c         S   s%   | j  ƒ  } |  j | d d ƒ} | S(   NRa   i    (   RJ   RK   (   R   t
   pyfunctiont   docs(    (    sD   lib/python2.7/site-packages/spyder/utils/introspection/rope_patch.pyRe   Ç   s    (   R   R   RD   RJ   t   FalseR`   RO   Re   (    (   R%   RA   R@   R'   (    sD   lib/python2.7/site-packages/spyder/utils/introspection/rope_patch.pyRB   ‡   s
   s   docstring.hardcopy(   t   spyder.utils.programsR    R   t   ImportErrort   VERSIONR   R   t	   rope.baseR   t   ProjectR   t   PyCoreR%   R&   R'   R<   t   os.pathR:   t   BuiltinNamet   rope.contribR?   t   spyder_kernels.utils.dochelpersR@   RA   t   PyDocExtractort
   matplotlibRZ   t   rcParams(
   R    R   R   R   R   R   R(   R?   RB   t   mpl(    (   R%   RA   R@   R<   R&   R=   R   R'   sD   lib/python2.7/site-packages/spyder/utils/introspection/rope_patch.pyt   apply   s6    	#	+	(D	N(   t   __doc__R|   (    (    (    sD   lib/python2.7/site-packages/spyder/utils/introspection/rope_patch.pyt   <module>   s   