a
    a%                     @   s   d Z dd ZdS )a`  
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            
         sD  ddl m}  | ddr,ddl}td|j ddlm} | rbddlm} G d	d
 d
|j	}||_	ddlm
 G fdddj}|_ddlm mm ddlddlm G  fddd j}| _ddlm} ddlm ddlm G  fddd|j}||_zddl}	d|	jd< W n   Y n0 dS )zMMonkey patching rope

    See [1], [2], [3], [4] and [5] in module docstring.    )is_module_installedropez<0.9.4Nzrope %s can't be patched)is_py2exe_or_cx_Freeze)projectc                   @   s   e Zd Zdd ZdS )zapply.<locals>.PatchedProjectc                 S   s$   ddl m} |dd}t|d S )Nr   )get_module_source_pathZspyderzdefault_config.pyrb)spyder.config.baser   openread)selfr   fname r   Dlib/python3.9/site-packages/spyder/utils/introspection/rope_patch.py_default_config-   s
    z-apply.<locals>.PatchedProject._default_configN)__name__
__module____qualname__r   r   r   r   r   PatchedProject,   s   r   pycorec                       s"   e Zd Zd fdd	Zdd ZdS )zapply.<locals>.PatchedPyCoreNc                    sB   |  |}|dur|S | ||}|du r8 d| | |S )z-Returns a `PyObject` if the module was found.NzModule %s not found)Z_builtin_modulefind_moduleModuleNotFoundErrorZresource_to_pyobject)r   namefolderZpymodmoduler   r   r   
get_module=   s    
z'apply.<locals>.PatchedPyCore.get_modulec                 S   s   |}| d}|d d D ](}| r<||r<||}q d S q| r||d r||d  r||d dr||d S ||d d r||d d  s||d d S d S )N.z__init__.pyz.py)splitZ	is_folderZ	has_childZ	get_child)r   r   modnamer   Zpackagespkgr   r   r   _find_module_in_folderJ   s"    
z3apply.<locals>.PatchedPyCore._find_module_in_folder)N)r   r   r   r   r!   r   r   r   r   PatchedPyCore7   s   r"   )builtinslibutils	pyobjectsc                       s*   e Zd Z fddZfddZdS )z!apply.<locals>.PatchedBuiltinNamec                    s8   | j }|jd ur|j}qt| jr4|jd ur4|jS d S N)pyobjectparent
isinstanceBuiltinModuler   )r   p)r#   r   r   _pycoreb   s
    
z)apply.<locals>.PatchedBuiltinName._pycorec                    s     | js | jj\}} | jj}|drT|d d rT|d d }|  }|r|jr	|j|}
|d |}||fS dS )NZpycr   )NN)Z	isbuiltinr'   ZgetsourcelinesbuiltinZgetfileendswithisfiler,   r   Zpath_to_resourceZPyModule)r   Z_lineslinenopathr   resourcer   )inspectr$   ospr%   r   r   get_definition_locationh   s    
z9apply.<locals>.PatchedBuiltinName.get_definition_locationN)r   r   r   r,   r5   r   )r#   r3   r$   r4   r%   r   r   PatchedBuiltinNamea   s   r6   )
codeassistgetdoc)
exceptionsc                       sP   e Zd ZfddZfddZdfdd	Z fdd	Zd
d Z  ZS )z$apply.<locals>.PatchedPyDocExtractorc                    s   |j } |S r&   )r-   )r   r'   Zbuitinr8   r   r   get_builtin_doc   s    z4apply.<locals>.PatchedPyDocExtractor.get_builtin_docc                    s   t |dr| |}|S t| jrV| }|d ur@| |}nd}ddd|d}|S t|jrl| |S t|jr| 	|S t|j
r| | S | d ur| | S d S )Nr-    )r   argspecZnote	docstring)hasattrr;   r)   r*   get_doc_trim_docstringAbstractFunctionZ_get_function_docstringAbstractClass_get_class_docstringZAbstractModule)r   r'   docr>   )r#   r%   r   r   r@      s.    



z,apply.<locals>.PatchedPyDocExtractor.get_docFc                    s   t |dr$| |}|d |d  S z4t|jr>|d  }t|jsV|d  }W n  jyn   Y d S 0 |rt|jsd S t|jr| j|dd}|r| 	|r|
dd	
d
dS |S d S )Nr-   r   r=   __init____call__T)Z
add_modulez(self)z()z(self, ()r?   r;   r)   rC   
get_objectrB   ZAttributeNotFoundErrorZ
PyFunctionZ_get_function_signatureZ
_is_methodreplace)r   r'   Zignore_unknownZremove_selfrE   result)r:   r%   r   r   get_calltip   s"    

z0apply.<locals>.PatchedPyDocExtractor.get_calltipc                    sx   | j | dd} fdd| D }d| d|f | }d|v rt|d  }t|jrt|d| | 7 }|S )	Nr   indentsc                    s   g | ]}|  qS r   )get_name).0super	__class__r   r   
<listcomp>       zMapply.<locals>.PatchedPyDocExtractor._get_class_docstring.<locals>.<listcomp>zclass %s(%s):

z, rF   z

)	rA   r@   Zget_superclassesrO   joinrI   r)   rB   _get_single_function_docstring)r   ZpyclasscontentsZsupersrE   init)rS   r%   r   r   rD      s    z9apply.<locals>.PatchedPyDocExtractor._get_class_docstringc                 S   s   |  }| j|dd}|S )Nr   rM   )r@   rA   )r   Z
pyfunctionZdocsr   r   r   rW      s    zCapply.<locals>.PatchedPyDocExtractor._get_single_function_docstring)FF)	r   r   r   r;   r@   rL   rD   rW   __classcell__r   )r#   r:   r9   r%   rR   r   PatchedPyDocExtractor   s
   r[   Tzdocstring.hardcopy)Zspyder.utils.programsr   r   ImportErrorZVERSIONr   r   Z	rope.baser   ZProjectr   ZPyCorer#   r$   r%   r3   os.pathr1   ZBuiltinNameZrope.contribr7   Zspyder_kernels.utils.dochelpersr9   r:   ZPyDocExtractorZ
matplotlibZrcParams)
r   r   r   r   r   r"   r6   r7   r[   Zmplr   )r#   r:   r9   r3   r$   r4   r   r%   r   apply   s6    
#Dr^   N)__doc__r^   r   r   r   r   <module>   s   