Format: application/x-python-code
⬇ Download File (7.1 KB)
   1  o
   2  
   3  �h�'�@s�ddlZddlZddlmZddlmZddlmZddlm	Z	ddl
   4  mZmZddl
   5  mZddlmZdd	lmZdd
   6  lmZdZdefd
   7  d�Zdd�Zdd�Zegd�dd��Zdd�Zdd�Zdefdd�Zdefdd�Zd d!�Zd"d#�ZdS)$�N)�Path)�all_suffixes)�inference_state_method_cache)�ContextualizedNode)�	is_string�get_str_or_none)�get_cached_code_lines)�FileIO)�settings)�debug�
   8  �str_pathcCs<t|�}|��r
   9  |S|��}|durdS|j}|�|���S�N)r�is_absoluteZ
  10  py__file__�parent�joinpath�absolute)�module_contextr
  11  �path�module_path�base_dir�r�Mc:\Users\shubh\Videos\agent\nova\Lib\site-packages\jedi/inference/sys_path.py�	_abs_pathsrc
  12  	cs�t|jddd�|jddd��D]w\}}z>|dvsJ�|jdvr)t|j�dks+J�|j}|djdkr<|djdks>J�|d}|jdd	krQ|jdjd
  13  ksSJ�Wn	ty]Yqwt|�|�|�}|���	|�D]}|��D]}t
  14  |�r�t||���}	|	dur�|	VqsqmqdS)a�
  15      Extracts the assigned strings from an assignment that looks as follows::
  16  
  17          sys.path[0:0] = ['module/path', 'another/module/path']
  18  
  19      This function is in general pretty tolerant (and therefore 'buggy').
  20      However, it's not a big issue usually to add more paths to Jedi's sys_path,
  21      because it will only affect Jedi in very random situations and by adding
  22      more paths than necessary, it usually benefits the general user.
  23      N��)�=z+=��powerZ	atom_exprr�name�sys�.r)
  24  �zip�children�type�len�value�AssertionErrorr�create_contextZinferZiteraterrZget_safe_value)
  25  r�	expr_stmtZassignee�operator�c�trailerZcnZ
  26  lazy_valuer&�abs_pathrrr�_paths_from_assignment s2�*
  27   "�����r.ccs��|jdkr |jddkr |jdkr |jddkr t|j�dks"dS|jdj}|dvr.dS|jd}|d	krCt|j�d
  28  vrC|jd}|�|��|�D]}t|�}|durVqKt||�}|durb|VqKdS)zE extract the path from either "sys.path.append" or "sys.path.insert" r,rr!�(�Nr)�insert�appendr1)r0�r)r$r#r%r&r(Z
  29  infer_noderr)rZtrailer1Ztrailer2r�argr&�pr-rrr�_paths_from_list_modificationsKs(�
  30  
  31  
  32  ��r6)�defaultcCs�dd�}|jdurgSg}z	|j��d}Wn
  33  ty Y|Sw||�D]0\}}|j}t|j�dkrD|�t|g|jdd��R��q%|durU|jdkrU|�t	||��q%|S)z6
  34      Detect sys.path modifications within module.
  35      css��|D]=}|jj}|dur@|jdvr@|j}|djdkr@|djdkr@|djdkr@|djd}|jdkr@|jdkr@||fVqdS)Nrrrr rr,r)rr$r#r&)�namesrrr+�nrrr�get_sys_path_powersis�
  36  ��z9check_sys_path_modifications.<locals>.get_sys_path_powersNrr3rr))
  37  Z	tree_nodeZget_used_names�KeyErrorrr%r#�extendr6r$r.)rr:�addedZpossible_namesrrr)rrr�check_sys_path_modificationsds0
  38  �����r>cCsBt�}t|�D]}t||�D]}|�|�t|�tkrnqq|Sr)�set�_get_buildout_script_paths�_get_paths_from_buildout_script�addr%�_BUILDOUT_PATH_INSERTION_LIMIT)�inference_stateZscript_pathZbuildout_script_paths�buildout_script_pathrrrr�discover_buildout_paths�s
  39  ��rFccs��tt|��}z|j|dtjd�}Wnty"t�d|�YdSwddlm	}||||dt
  40  |j|�d���}t
  41  |�EdHdS)NT)�file_io�cache�
  42  cache_pathz(Error trying to read buildout_script: %sr)�ModuleValue)rGZstring_namesZ
  43  code_lines)r	�str�parser
  44  Zcache_directory�IOErrorr�warningZjedi.inference.valuerJrZgrammarZ
  45  as_contextr>)rDrErGZmodule_noderJrrrrrA�s,�
  46  ��
  47  ��rArc	Cs>|jD]}z|�|���r|WSWqtyYqwdSr)�parentsr�is_file�OSError)r�filenamerrrr�_get_parent_dir_with_file�s
  48  
  49  ��rS�search_pathccs��t|d�}|s
  50  dS|�d�}|��sdSt�|�D]I}z,|�|�}t|d��}|��}|�d�r8d|vr8|VWd�n1sBwYWqtt	fyc}z
  51  t
  52  �t|��WYd}~qd}~wwdS)z�
  53      if there is a 'buildout.cfg' file in one of the parent directories of the
  54      given module it will return a list of all files in the buildout bin
  55      directory that look like python files.
  56  
  57      :param search_path: absolute path to the module.
  58      zbuildout.cfgN�bin�rz#!�python)
  59  rSr�exists�os�listdir�open�readline�
  60  startswith�UnicodeDecodeErrorrMrrNrK)rTZproject_rootZbin_pathrR�filepath�f�	firstline�errrr@�s.�
  61  
  62  
  63  ������r@cCs2t�dgD]}|j|kr|�|j�}|Sq|S)Nz.pyi)r�suffix�	with_name�stem)rrcrrr�remove_python_path_suffix�s
  64  �rfcsdt����j�d�rdS�jdk}|r�j���fdd�}t|��}|s&dSt|dd�d�d	|fS)
  65  aK
  66      Returns the dotted path inside a sys.path as a list of names. e.g.
  67  
  68      >>> transform_path_to_dotted([str(Path("/foo").absolute())], Path('/foo/bar/baz.py').absolute())
  69      (('bar', 'baz'), False)
  70  
  71      Returns (None, False) if the path doesn't really resolve to anything.
  72      The second return part is if it is a package.
  73      r!)NF�__init__c3s���D]?}t���|�rBt��t|�d�}|�tjj�s"|�d�r(|dd�}|rB|�tjj�}t|�s8dStdd�|D��VqdS)N�/rcss�|]
  74  }t�dd|�VqdS)z-stubs$�N)�re�sub)�.0�srrr�	<genexpr>s�zMtransform_path_to_dotted.<locals>.iter_potential_solutions.<locals>.<genexpr>)	rKr]r%rYr�sep�split�all�tuple)r5�restrp�r�sys_pathrr�iter_potential_solutions�s���z:transform_path_to_dotted.<locals>.iter_potential_solutionscSst|�Sr)r%)r5rrr�<lambda>sz*transform_path_to_dotted.<locals>.<lambda>)�keyr)rfrr]rrr�sorted)rur�
  75  is_packagervZpotential_solutionsrrtr�transform_path_to_dotted�s
  76  
  77  r{) rYrj�pathlibr�importlib.machineryrZjedi.inference.cacherZjedi.inference.base_valuerZjedi.inference.helpersrrZjedi.parser_utilsrZjedi.file_ior	Zjedir
  78  rrCrKrr.r6r>rFrArSr@rfr{rrrr�<module>s.+
  79  %
  80