
,]c           @   sz  d  Z  d d l Z d d l Z d d l m Z d d l m Z m Z d d l m	 Z	 m
 Z
 d d l m Z d d l m Z d d l m Z m Z d d	 l m Z m Z m Z d d
 l m Z d d l m Z d d l m Z yN y d d l m Z e j   Wn e k
 rn Xd d l Z d d l  Z Wn e k
 r=n Xi e! d 6e! d 6d d 6g  d 6Z" d e f d     YZ# d S(   s   
Rope introspection plugin
iN(   t   getsignaturefromtext(   t   get_conf_patht   STDERR(   t   encodingt   programs(   t   PY2(   t
   sourcecode(   t   log_last_errort   log_dt(   t   DEBUG_EDITORt   LOG_FILENAMEt   IntrospectionPlugin(   t   get_preferred_submodules(   t   ROPE_REQVER(   t   default_info_response(   t
   rope_patcht   ignore_syntax_errorst   ignore_bad_importsi   t   soa_followed_callst   extension_modulest
   RopePluginc           B   sb   e  Z d  Z d
 Z d Z d   Z d   Z d   Z d   Z	 d   Z
 d   Z d   Z d	   Z RS(   sk   
    Rope based introspection plugin for jedi

    Editor's code completion, go-to-definition and help
    t   ropec         C   s   t  j d t  s% t d t   n  d |  _ |  j d t    t   } g  } x@ | D]8 } y t	 j
 |  | j |  WqW t k
 r qW XqW W|  j d k	 r |  j j j d |  n  d S(   s"   Load the Rope introspection pluginR   s   Requires Rope %st	   root_pathR   N(   R   t   is_module_installedR   t   ImportErrort   Nonet   projectt   create_rope_projectR   R   t   impt   find_modulet   appendt   prefst   set(   t   selft   submodst   actualt   submod(    (    sE   lib/python2.7/site-packages/spyder/utils/introspection/rope_plugin.pyt   load_plugin=   s    		c         C   s  |  j  d k r g  S| d } | d } | d } |  j  j j d | d  t j | |   } | d j   } | j d  s | j d  r d	 | k r g  S| d k	 r t r | j	 d
  } q n  y t
 j j j |  j  |  } Wn3 t k
 r} t rt t d |  n  d } n Xy t r0t j   }	 n  t
 j j j |  j  | | | d d }
 t
 j j j |
  }
 t rt t d |	  n  g  |
 D] } | j | j f ^ qSWn) t k
 r} t rt t d  qn Xg  S(   s2   Get a list of (completion, type) tuples using Ropet   filenamet   source_codet   positiont   python_patht   sys_pathis   import s   from t   ;s   utf-8s   path_to_resource: %rt   maxfixesi   s   code_assist/sorted_proposalst   get_completion_listN(   R   R   R   R    R   t   split_sourcet   lstript
   startswithR   t   encodeR   t   baset   libutilst   path_to_resourcet	   ExceptionR	   R   R
   t   timet   contribt
   codeassistt   code_assistt   sorted_proposalsR   t   namet   type(   R!   t   infoR&   R'   t   offsett   linest	   last_linet   resourcet   _errort   t0t	   proposalst   proposal(    (    sE   lib/python2.7/site-packages/spyder/utils/introspection/rope_plugin.pyt   get_completionsN   sF    



'c   
      C   s@  |  j  d k r t   S| d } | d } | d } |  j  j j d | d  | d k	 ru t ru | j d  } qu n  y t j j	 j
 |  j  |  } Wn3 t k
 r } t r t t d |  n  d } n XyFt r t j   } n  t j j j |  j  | | | d t d	 t d
 d } t r.t t d |  n  | d k	 rx" d | k r^| j d d  } q=Wd | k r| j d d  } qn  yD t j j j |  j  | | | d
 d }	 t rt t d |  n  Wn/ t k
 r} d }	 t rt t d  qn X|  j | |	 | |  SWn) t k
 r;} t r<t t d  q<n Xd S(   s/   Get a formatted calltip and docstring from RopeR&   R'   R(   R)   R*   s   utf-8s   path_to_resource: %rt   ignore_unknownt   remove_selfR,   i   t   get_calltips   ..t   .s   (.)s   (...)t   get_doct    t   get_calltip_textN(   R   R   R   R   R    R   R1   R   R2   R3   R4   R5   R	   R   R
   R6   R7   R8   RI   t   Falset   TrueR   t   replaceRK   t   handle_info(
   R!   R=   R&   R'   R>   RA   RB   RC   t   ctst   doc_text(    (    sE   lib/python2.7/site-packages/spyder/utils/introspection/rope_plugin.pyt   get_info}   sV    



c         C   s  d } d } d } d } | r | j  d d  } | j d  }	 |	 r | |	  } | j d  d }
 | j  | |
  } | } d | k s d | k r t | |
  } q q n  | s t j | |  } n  | rf| j d  rft |  t k r| d	 p | } | d
 } | d } | d } qf| rf| j d  } | | } | j	 d  } | |  } d | } qfn  | r{| r{t
   St d	 | d
 | d | d | d |  S(   NRL   s	   .__init__t   (RJ   is   ()s   (...)s   self.R;   t   argspect   notet	   docstrings   Present in %s modulet   calltip(   RP   t   findt   splitR    R   t   get_primary_atR0   R<   t   dictt   rfindR   (   R!   RR   RS   R'   R>   t   obj_fullnameRY   RV   RW   t   parpost   obj_namet
   argspec_stt
   module_endt   module(    (    sE   lib/python2.7/site-packages/spyder/utils/introspection/rope_plugin.pyRQ      s@    




c   	      C   s  |  j  d k r d S| d } | d } | d } |  j  j j d | d  | d k	 rr t rr | j d  } qr n  y t j j j	 |  j  |  } Wn3 t
 k
 r } t r t t d |  n  d } n Xy t r t j   } n  t j j j |  j  | | | d	 d
 \ } } t r%t t d |  n  | d k	 r=| j } n  | rS| rS| | f SWn) t
 k
 r} t rt t d  qn Xd S(   s%   Find a definition location using RopeNR&   R'   R(   R)   R*   s   utf-8s   path_to_resource: %rR,   i   t   get_definition_location(   R   R   R   R    R   R1   R   R2   R3   R4   R5   R	   R   R
   R6   R7   R8   Re   R   t	   real_path(	   R!   R=   R&   R'   R>   RA   RB   RC   t   lineno(    (    sE   lib/python2.7/site-packages/spyder/utils/introspection/rope_plugin.pyt   get_definition   s>    



!c         C   sD   |  j  d k	 r@ y |  j  j |  j  j  Wq@ t k
 r< q@ Xn  d S(   s   Validate the Rope projectN(   R   R   t   validatet   roott   RuntimeError(   R!   (    (    sE   lib/python2.7/site-packages/spyder/utils/introspection/rope_plugin.pyRi     s
    c         C   s   t  r t j |  } n  y+ d d l } | j j j | t  |  _ Wnq t k
 r t	 d IJd |  _ t r t t d |  q n4 t k
 r d |  _ t r t t d |  q n X|  j   d S(   s'   Create a Rope project on a desired pathiNs   project errors   create_rope_project: %r(   R   R   t   to_fs_from_unicodet   rope.base.projectR2   R   t   Projectt
   ROPE_PREFSR   R   R   R	   R   R
   t	   TypeErrorRi   (   R!   R   R   (    (    sE   lib/python2.7/site-packages/spyder/utils/introspection/rope_plugin.pyR     s"    
		c         C   s#   |  j  d k	 r |  j  j   n  d S(   s   Close the Rope projectN(   R   R   t   close(   R!   (    (    sE   lib/python2.7/site-packages/spyder/utils/introspection/rope_plugin.pyt   close_rope_project%  s    N(   t   __name__t
   __module__t   __doc__R   R   R;   R%   RF   RT   RQ   Rh   Ri   R   Rr   (    (    (    sE   lib/python2.7/site-packages/spyder/utils/introspection/rope_plugin.pyR   1   s   		/	4	*	(	
	($   Ru   R6   R   t   spyder_kernels.utils.dochelpersR    t   spyder.config.baseR   R   t   spyder.utilsR   R   t   spyder.py3compatR   R   t   spyder.utils.debugR   R   t"   spyder.utils.introspection.managerR	   R
   R   t,   spyder.utils.introspection.module_completionR   R   t    spyder.utils.introspection.utilsR   t   spyder.utils.introspectionR   t   applyR   t   rope.base.libutilsR   t   rope.contrib.codeassistRO   Ro   R   (    (    (    sE   lib/python2.7/site-packages/spyder/utils/introspection/rope_plugin.pyt   <module>	   s6   

