Format: application/x-python-code
⬇ Download File (13.9 KB)
   1  o
   2  
   3  �h*Z�@s�dZddlZddlmZddlmZddlmZddlm	Z	ddlm
   4  Z
   5  ddlmZdd	l
   6  mZdd
   7  lmZddlmZddlmZdd
   8  lmZddlmZddlmZddlmZmZddlmZmZddlmZm Z m!Z!ddl"m#Z#ddl$m%Z%Gdd�d�Z&eed�dd��Z'egd�dd��Z(dd�Z)dd�Z*d d!�Z+Gd"d#�d#�Z,		$d6d%d&�Z-e%�.�ed'd(���Z/	)d7d*d+�Z0d8d,d-�Z1d8d.d/�Z2d0d1�Z3d2d3�Z4ed$fd4d5�Z5dS)9a�
   9  :mod:`jedi.inference.imports` is here to resolve import statements and return
  10  the modules/classes/functions/whatever, which they stand for. However there's
  11  not any actual importing done. This module is about finding modules in the
  12  filesystem. This can be quite tricky sometimes, because Python imports are not
  13  always that simple.
  14  
  15  This module also supports import autocompletion, which means to complete
  16  statements like ``from datetim`` (cursor at the end would return ``datetime``).
  17  �N)�Path)�tree)�search_ancestor)�debug)�settings)�FolderIO)�get_cached_code_lines)�sys_path)�helpers)�compiled)�analysis)�unite)�inference_state_method_cache)�
  18  ImportName�
  19  SubModuleName)�ValueSet�	NO_VALUES)�import_module_decorator�create_stub_module�parse_stub_module)�ImplicitNSInfo)�plugin_managerc@s$eZdZdd�Zdd�Zdd�ZdS)�ModuleCachecCs
  20  i|_dS�N��_name_cache��self�r�Lc:\Users\shubh\Videos\agent\nova\Lib\site-packages\jedi/inference/imports.py�__init__$s
  21  zModuleCache.__init__cCs|dur||j|<dSdSrr)r�string_names�	value_setrrr�add's�zModuleCache.addcCs|j�|�Sr)r�get)rr!rrrr$+szModuleCache.getN)�__name__�
  22  __module__�__qualname__r r#r$rrrrr#sr)�defaultc	Csl|��}t||�\}}}}|r.|dur.|j||dd�}|s.||f}t|j|||�}|��}t�d|�|S)NF�Zname_contextZanalysis_errorszafter import: %s)�get_root_context�_prepare_infer_importZpy__getattribute__�Importer�inference_state�followr�dbg)	�context�	tree_name�module_context�from_import_name�import_path�level�values�path�importerrrr�infer_import1s 
  23  ��
  24  r9c	s����}t|��\�}}}|sgS�durAt��fdd�|D��}|r0t�fdd�|D��s0|S|�f}t�j|||�}|��}tdd�|D��S)Ncsg|]
  25  }|j��dd��qS)Fr))Zgoto)�.0�c)r0r3rr�
  26  <listcomp>Ps���zgoto_import.<locals>.<listcomp>c3s�|]}|j�uVqdSr�r1)r:�nr=rr�	<genexpr>Xs�zgoto_import.<locals>.<genexpr>css�|]}|jVqdSr)�name)r:�srrrr?^s�)r*r+r
  27  �anyr,r-r.�set)	r0r1r2r4r5r6�namesr7r8r)r0r3r1r�goto_importGs
  28  ��
  29  rEcCs�t|dd�}|�|�}d}z|��}Wn	tyYnwt|�dt|�kr-|d}|}t|jt|�||j�}|t|�|j|�	�fS)N�import_nameZimport_from������)
  30  rZget_path_for_nameZget_from_names�AttributeError�lenr,r-�tupler5r.)r2r1Zimport_noder4r3Z
  31  from_namesr8rrrr+as
  32  ��r+cCs8t|d�r|durt�|d||�dSt�d|�dS)N�parentzimport-errorzImportError without origin: )�hasattrrr#r�warning)�valuer@�messagerrr�
  33  _add_errorwsrQcCs~t|d�D]}|}tj�|�}||krdSq|}g}	||kr%||fStj�|�}|r:|�d|�tj�|�}nd|fSq)z�
  34      In case the level is outside of the currently known package (something like
  35      import .....foo), we can still try our best to help the user for
  36      completions.
  37      rG�NNTrN)�range�osr7�dirname�basename�insert)�project_path�	directoryr5�i�old�dZlevel_import_paths�dir_namerrr�_level_to_base_import_path~s"��r^c@sFeZdZddd�Zedd��Zdd�Zdd	�Zddd�Zddd�Z	d
  38  S)r,rcCs
  39  t�d||f�||_||_||_d|_d|_|r�|����}|t	|�kr>t
  40  |�}|dkr7|d|d�}|t
  41  |�}nB|��}|jjj
  42  }t|�}|durR|}ntj
  43  �|�}t|||�\}	}
  44  |
  45  durhd|_n|
  46  g|_|	dur||r{t||ddd�n|	|}||_dS)	a
  47          An implementation similar to ``__import__``. Use `follow`
  48          to actually follow the imports.
  49  
  50          *level* specifies whether to use absolute or relative imports. 0 (the
  51          default) means only perform absolute imports. Positive values for level
  52          indicate the number of parent directories to search relative to the
  53          directory of the module calling ``__import__()`` (see PEP 328 for the
  54          details).
  55  
  56          :param import_path: List of namespaces (strings or Names).
  57          zimport %s %sNTrGFrz3Attempted relative import beyond top-level package.)rP)r�speed�_inference_stater5�_module_context�_fixed_sys_path�_infer_possible�	get_valueZ
  58  py__package__rJrKZ
  59  py__file__�projectr7�listrTrUr^rQr4)rr-r4r2r5�baser7rXrYZbase_import_pathZbase_directoryrrrr �sD
  60  
  61  
  62  ���
  63  zImporter.__init__cCstdd�|jD��S)z:Returns the import path as pure strings instead of `Name`.cs�&�|]}t|tj�r
  64  |jn|VqdSr��
  65  isinstancer�NamerO)r:r@rrrr?��
  66  ��
  67  �z,Importer._str_import_path.<locals>.<genexpr>)rKr4rrrr�_str_import_path�s�zImporter._str_import_pathcCs6|jdur|jS|jj|d�dd�t�|j�D�S)N)Zadd_init_pathscSsg|]}t|��qSr)�str�r:�prrrr<�s�z9Importer._sys_path_with_modifications.<locals>.<listcomp>)rbr`�get_sys_pathr	Zcheck_sys_path_modificationsra)r�
  68  is_completionrrr�_sys_path_with_modifications�s
  69  
  70  ���z%Importer._sys_path_with_modificationscCs�|js&|jr$ddlm}tj�|jd�f}||j||jd�}t|h�St	S|j
  71  s+t	S|jj�|j
  72  �}|dur<t|h�S|jj�|j
  73  �}|durJ|S|jdd�}t|j|j||j�S)Nr��ImplicitNamespaceValue�r!�pathsF�rr)r4rb�jedi.inference.value.namespacerurTr7rVr`rrrcZstub_module_cacher$rm�module_cachers�import_module_by_namesra)rrur4�ns�
  74  from_cacher	rrrr.�s.�
  75  
  76  �zImporter.followNcCsL|dur|jdd�}n|}tt|j|j||durtnt|duo"|dud��S)z�
  77          Get the names of all modules in the search_path. This means file names
  78          and not names defined in the files.
  79          NTrx)�
  80  module_cls�add_builtin_modules)rsrf�iter_module_namesr`rarr)r�search_pathZ	in_moduler	rrr�_get_module_names,s
  81  �zImporter._get_module_namesFcCs>|jsgSg}|jr�|jdkrM|��D]}|j}|�d�r.|td�d�}|�t|j	|��q|j
  82  dd�D]}tj�
  83  |d�}tj�|�rL||�|g�7}q5|��}	|	D]}
  84  |
  85  jdvr[qS|
  86  ��sg||
  87  ����7}qS|s�dd	lm}|	||	�B}|D]}
  88  |
  89  ��D]}||��7}q~qx|S|jr�||�|j�7}|S||��7}|S)
  90  z�
  91          :param only_modules: Indicates wheter it's possible to import a
  92              definition that is not defined in a module.
  93          )Zflask�extZflask_NTrx�flaskext)�module�	namespacer)�convert_values)rcr4rmr�Zstring_name�
  94  startswithrJ�appendrrarsrTr7�join�isdirr.Zapi_typeZis_compiledZsub_modules_dictr6Z!jedi.inference.gradual.conversionr�Zget_filtersr5rb)rr-Zonly_modulesrD�mod�modnameZextname�dirr�r6rOr�Zboth_valuesr;�filterrrr�completion_names;sH
  95  
  96  ��
  97  ��	��zImporter.completion_names)rrR)F)
  98  r%r&r'r �propertyrmrsr.r�r�rrrrr,�s
  99  F
 100  
 101  5r,Tcs��dur����tdd�|D���dg}t|�D]4\�}t������fdd�|D��}|sLdd���}|durCt|||�t	St�|�t	Sq|S)Ncsrhrri)r:rZrrrr?rrlz)import_module_by_names.<locals>.<genexpr>c	s*g|]}t��d�d�|��d��qS)NrG)�prefer_stubs)�
 102  import_module)r:�parent_module_value�rZr-r�Zstr_import_namesr	rrr<xs���z*import_module_by_names.<locals>.<listcomp>zNo module named �.)
 103  rqrK�	enumeraterZ	from_setsr�rQrrNr)r-�import_namesr	r2r�r"r@rPrr�rr{ms&��	
 104  ��r{c
 105  CsD|dtjvrt|||�}|durtSt|g�Sd�|�}|dur6|jj|d||dd�\}}|dur5tSn|��}|dur@tS|jj|d||dd�\}}|durTtSt	|t
 106  �rndd	lm}	|	|t
 107  |j�d��|jd
 108  �}n|durt|||�}|dur~tSnt||||d�}|dur�t�d|d|�nt�d
 109  |||�t|g�S)zC
 110      This method is very similar to importlib's `_gcd_import`.
 111      rNr�rHT)�string�	full_namer	�is_global_searchF)r�r7r�r�rtrv�r��
 112  is_packagezglobal search_module %s: %sz search_module %s in paths %s: %s)rZauto_import_modules�_load_builtin_modulerrr��compiled_subprocessZget_module_infoZ
 113  py__path__rjrryrurKr@�splitrw�_load_python_modulerr/)
 114  r-r�r�r	r��module_nameZ
 115  file_io_or_nsZis_pkgrwrurrrr��s`
 116  
 117  
 118  ��
 119  �
 120  ���
 121  r�FcCs@|j|dtjtjd�}ddlm}|||||t|j|j�|d�S)NT)�file_io�cacheZ
 122  diff_cache�
 123  cache_pathr)�ModuleValue)r�r!Z
 124  code_linesr�)	�parserZfast_parserZcache_directoryZjedi.inference.valuer�rZgrammarr7)r-r�r�r�Zmodule_noder�rrrr��s��r�csn|j}|dur|��}|js|�|���fdd�|D�}d�|�}|dus'J�tj|||d�}|dur5dS|S)Ncsg|]}|�vr|�qSrrro�Z
 125  safe_pathsrrr<�sz(_load_builtin_module.<locals>.<listcomp>r�)�dotted_namer	)rerqZ_load_unsafe_extensionsZ_get_base_sys_pathr�r�load_module)r-r�r	rer�r�rr�rr��s
 126  
 127  r�cCst|j�}|dur|��}t�||�\}}nt|t�sJ�|jdk}|rs|��}|j�	d�r7t
 128  |jdd��}|jdkrB|�d�}n	|�|dd�}zt
 129  ||||d	�}	t|	g�}
 130  Wntyet}
 131  Ynwt||j|
 132  t||�||�St||||d
 133  �}|j�|t|g��|S)z�
 134      This should pretty much only be used for get_modules_containing_name. It's
 135      here to ensure that a random path is still properly loaded into the Jedi
 136      module structure.
 137      Nz.pyiz-stubsi����z__init__.pyiz__init__.pyrHz.py)r�r�)rr7rqr	�transform_path_to_dottedrj�bool�suffixZget_parent_folder�endswithrr@Zget_file_io�load_module_from_pathr�FileNotFoundErrorrrZlatest_grammarrr�rzr#)r-r�r�r�r7Z
 138  e_sys_pathZis_stub�	folder_ioZpython_file_io�vr6r�rrrr��sB
 139  
 140  
 141  ����r�cCs6t�|��t|j��\}}ddlm}||||jg�S)Nrrt)r	r�rqrr7ryru)r-r�r�r�rurrr�load_namespace_from_paths�r�cCs�t�|d�}|durRd}t|j�D]\}}|j|jkrn	|dkr%|d}q|j|d�}|d��j}|dvrR|dk}tj|||d�\}	}
 142  t	|j
 143  |
 144  |��|	���SdS)N�
 145  error_noder�;rG)�from�importr�)�is_import_fromZ
 146  until_node)
 147  rrr��children�	start_posZget_first_leafrOr
 148  Zparse_dotted_namesr,r-r*r.)r0r@r�Zstart_index�indexr>�nodesZ
 149  first_namer�r5rDrrr�%follow_error_node_imports_if_possible's0�
 150  ���r�ccsD�|r|j��D]}|||�Vq|j�|�D]}|||�VqdS)zx
 151      Get the names of all modules in the search_path. This means file names
 152      and not names defined in the files.
 153      N)r�Zget_builtin_module_namesr�)r-r2r�r~rr@rrrr�Ds��r�)NNT)NFrR)6�__doc__rT�pathlibrZparso.pythonrZ
 154  parso.treerZjedirrZjedi.file_iorZjedi.parser_utilsrZjedi.inferencer	r
 155  rrZjedi.inference.utilsr
 156  Zjedi.inference.cacherZjedi.inference.namesrrZjedi.inference.base_valuerrZjedi.inference.gradual.typeshedrrrZ,jedi.inference.compiled.subprocess.functionsrZjedi.pluginsrrr9rEr+rQr^r,r{Zdecorater�r�r�r�r�r�r�rrrr�<module>sX
 157  
 158  
 159  U
 160  �?
 161  �
 162  
 163  .	�