o
    ï›hê'  ã                   @   sô   d dl Z d dlZd dlmZ d dlmZ d dlmZ d dlm	Z	 d dl
mZmZ d dlmZ d dlmZ d d	lmZ d d
lmZ dZdefdd„Zdd„ Zdd„ Zeg d�dd„ ƒZdd„ Zdd„ Zdefdd„Zdefdd„Zd d!„ Zd"d#„ ZdS )$é    N)ÚPath)Úall_suffixes)Úinference_state_method_cache)ÚContextualizedNode)Ú	is_stringÚget_str_or_none)Úget_cached_code_lines)ÚFileIO)Úsettings)Údebugé
   Ústr_pathc                 C   s<   t |ƒ}| ¡ r
|S |  ¡ }|d u rd S |j}| |¡ ¡ S ©N)r   Úis_absoluteZ
py__file__ÚparentÚjoinpathÚabsolute)Úmodule_contextr   ÚpathÚmodule_pathÚbase_dir© r   úMc:\Users\shubh\Videos\agent\nova\Lib\site-packages\jedi/inference/sys_path.pyÚ	_abs_path   s   r   c           
   	   c   s  � t |jddd… |jddd… ƒD ]w\}}z>|dv sJ ‚|jdv r)t|jƒdks+J ‚|j}|d jdkr<|d jdks>J ‚|d }|jd d	krQ|jd jd
ksSJ ‚W n	 ty]   Y qw t|  |¡|ƒ}| ¡  	|¡D ]}| ¡ D ]}t
|ƒr‡t| | ¡ ƒ}	|	dur‡|	V  qsqmqdS )a¾  
    Extracts the assigned strings from an assignment that looks as follows::

        sys.path[0:0] = ['module/path', 'another/module/path']

    This function is in general pretty tolerant (and therefore 'buggy').
    However, it's not a big issue usually to add more paths to Jedi's sys_path,
    because it will only affect Jedi in very random situations and by adding
    more paths than necessary, it usually benefits the general user.
    Né   é   )ú=z+=©ÚpowerZ	atom_exprr   ÚnameÚsysÚ.r   )ÚzipÚchildrenÚtypeÚlenÚvalueÚAssertionErrorr   Úcreate_contextZinferZiterater   r   Zget_safe_value)
r   Ú	expr_stmtZassigneeÚoperatorÚcÚtrailerZcnZ
lazy_valuer&   Úabs_pathr   r   r   Ú_paths_from_assignment    s2   €*
 "ÿ€üÿèr.   c                 c   sÊ   � |j dkr |jd dkr |j dkr |jd dkr t|jƒdks"dS |jd j}|dvr.dS |jd }|d	krCt|jƒd
v rC|jd }|  |¡ |¡D ]}t|ƒ}|du rVqKt| |ƒ}|durb|V  qKdS )zE extract the path from either "sys.path.append" or "sys.path.insert" r,   r   r!   ú(é   Nr   )ÚinsertÚappendr1   )r0   é   r   )r$   r#   r%   r&   r(   Z
infer_noder   r   )r   Ztrailer1Ztrailer2r   Úargr&   Úpr-   r   r   r   Ú_paths_from_list_modificationsK   s(   €


€úr6   )Údefaultc                 C   s°   dd„ }| j du rg S g }z	| j  ¡ d }W n
 ty    Y |S w ||ƒD ]0\}}|j}t|jƒdkrD| t| g|jdd… ¢R Ž ¡ q%|durU|jdkrU| t	| |ƒ¡ q%|S )z6
    Detect sys.path modifications within module.
    c                 s   s†   � | D ]=}|j j }|d ur@|jdv r@|j}|d jdkr@|d jdkr@|d jdkr@|d jd }|jdkr@|jdkr@||fV  qd S )Nr   r   r   r    r   r,   r   )r   r$   r#   r&   )Únamesr   r   r+   Únr   r   r   Úget_sys_path_powersi   s   €
€øz9check_sys_path_modifications.<locals>.get_sys_path_powersNr   r3   r   r)   )
Z	tree_nodeZget_used_namesÚKeyErrorr   r%   r#   Úextendr6   r$   r.   )r   r:   ÚaddedZpossible_namesr   r   r)   r   r   r   Úcheck_sys_path_modificationsd   s0   
óÿÿÿ€r>   c                 C   sB   t ƒ }t|ƒD ]}t| |ƒD ]}| |¡ t|ƒtkr nqq|S r   )ÚsetÚ_get_buildout_script_pathsÚ_get_paths_from_buildout_scriptÚaddr%   Ú_BUILDOUT_PATH_INSERTION_LIMIT)Úinference_stateZscript_pathZbuildout_script_pathsÚbuildout_script_pathr   r   r   r   Údiscover_buildout_pathsŠ   s   
ÿ€rF   c                 c   s‚   � t t|ƒƒ}z| j|dtjd�}W n ty"   t d|¡ Y d S w ddlm	} || ||d t
| j|ƒd� ¡ }t|ƒE d H  d S )NT)Úfile_ioÚcacheÚ
cache_pathz(Error trying to read buildout_script: %sr   )ÚModuleValue)rG   Zstring_namesZ
code_lines)r	   ÚstrÚparser
   Zcache_directoryÚIOErrorr   ÚwarningZjedi.inference.valuerJ   r   ZgrammarZ
as_contextr>   )rD   rE   rG   Zmodule_noderJ   r   r   r   r   rA   –   s,   €
ýþ
üûrA   r   c              	   C   s>   | j D ]}z| |¡ ¡ r|W   S W q ty   Y qw d S r   )Úparentsr   Úis_fileÚOSError)r   Úfilenamer   r   r   r   Ú_get_parent_dir_with_file¬   s   

ÿÿrS   Úsearch_pathc                 c   sÌ   � t | dƒ}|s
dS | d¡}| ¡ sdS t |¡D ]I}z,| |¡}t|dƒ�}| ¡ }| d¡r8d|v r8|V  W d  ƒ n1 sBw   Y  W q tt	fyc } zt
 t|ƒ¡ W Y d}~qd}~ww dS )zü
    if there is a 'buildout.cfg' file in one of the parent directories of the
    given module it will return a list of all files in the buildout bin
    directory that look like python files.

    :param search_path: absolute path to the module.
    zbuildout.cfgNÚbinÚrz#!Úpython)rS   r   ÚexistsÚosÚlistdirÚopenÚreadlineÚ
startswithÚUnicodeDecodeErrorrM   r   rN   rK   )rT   Zproject_rootZbin_pathrR   ÚfilepathÚfÚ	firstlineÚer   r   r   r@   ¶   s.   €


€ý€€üùr@   c                 C   s2   t ƒ dg D ]}| j|kr|  | j¡}  | S q| S )Nz.pyi)r   ÚsuffixÚ	with_nameÚstem)r   rc   r   r   r   Úremove_python_path_suffixÓ   s   
ýrf   c                    sd   t ˆ ƒ‰ ˆ j d¡rdS ˆ jdk}|rˆ j‰ ‡ ‡fdd„}t|ƒ ƒ}|s&dS t|dd„ d�d	 |fS )
aK  
    Returns the dotted path inside a sys.path as a list of names. e.g.

    >>> transform_path_to_dotted([str(Path("/foo").absolute())], Path('/foo/bar/baz.py').absolute())
    (('bar', 'baz'), False)

    Returns (None, False) if the path doesn't really resolve to anything.
    The second return part is if it is a package.
    r!   )NFÚ__init__c                  3   sŠ   � ˆD ]?} t ˆ ƒ | ¡rBt ˆ ƒt| ƒd … }| tjj¡s"| d¡r(|dd … }|rB| tjj¡}t|ƒs8 d S tdd„ |D ƒƒV  qd S )Nú/r   c                 s   s   � | ]
}t  d d|¡V  qdS )z-stubs$Ú N)ÚreÚsub)Ú.0Úsr   r   r   Ú	<genexpr>  s   € zMtransform_path_to_dotted.<locals>.iter_potential_solutions.<locals>.<genexpr>)	rK   r]   r%   rY   r   ÚsepÚsplitÚallÚtuple)r5   Úrestrp   ©r   Úsys_pathr   r   Úiter_potential_solutionsò   s   €€îz:transform_path_to_dotted.<locals>.iter_potential_solutionsc                 S   s   t | ƒS r   )r%   )r5   r   r   r   Ú<lambda>  s    z*transform_path_to_dotted.<locals>.<lambda>)Úkeyr   )rf   r   r]   r   rr   Úsorted)ru   r   Ú
is_packagerv   Zpotential_solutionsr   rt   r   Útransform_path_to_dottedÛ   s   

r{   ) rY   rj   Úpathlibr   Úimportlib.machineryr   Zjedi.inference.cacher   Zjedi.inference.base_valuer   Zjedi.inference.helpersr   r   Zjedi.parser_utilsr   Zjedi.file_ior	   Zjedir
   r   rC   rK   r   r.   r6   r>   rF   rA   rS   r@   rf   r{   r   r   r   r   Ú<module>   s.    +
%
