Format: application/x-python-code
⬇ Download File (12.6 KB)
   1  o
   2  
   3  �hfC�@s�dZddlZddlZddlZddlZddlmZddlmZddl	m
   4  Z
   5  ddlmZm
   6  Z
   7  ddlmZmZmZddlZe
   8  rBddlmZed	d
   9  �Zgd�Zdd
  10  gZdZdejjejjfZGdd�de�ZGdd�d�Zdd�Z Gdd�de�Z!Gdd�d�Z"Gdd�de"e!�Z#Gdd�de"e�Z$dEdd �Z%d!d"�Z&d#d$�Z'd%d&�Z(d'd(�Z)e
  11  d)d*�d+d,��Z*dFd-d-d.�d/d0�Z+dd1�d2d3�Z,dd1�d4d5�Z-d-dd6�d7d8�Z.dGd9d:�Z/d;d<�Z0d=d>�Z1d?d@�Z2dAdB�Z3dCdD�Z4dS)Hz�
  12  Environments are a way to activate different Python versions or Virtualenvs for
  13  static analysis. The Python binary in that environment is going to be executed.
  14  �N)�
  15  namedtuple)�which)�
  16  TYPE_CHECKING)�memoize_method�
  17  time_cache)�CompiledSubprocess�InferenceStateSameProcess�InferenceStateSubprocess)�InferenceState�VersionInfozmajor minor micro)z3.13z3.12z3.11z3.10z3.9z3.8z3.7z3.6z/usr/binz/usr/local/binZCONDA_PREFIX�%s.%sc@seZdZdZdS)�InvalidPythonEnvironmentz�
  18      If you see this exception, the Python executable or Virtualenv you have
  19      been trying to use is probably not a correct Python version.
  20      N)�__name__�
  21  __module__�__qualname__�__doc__�rr�Jc:\Users\shubh\Videos\agent\nova\Lib\site-packages\jedi/api/environment.pyr
  22  sr
  23  c@s$eZdZedd��Zedd��ZdS)�_BaseEnvironmentcCs d|jj|jjf}tj|d�S)Nr��version)�version_info�major�minor�parsoZload_grammar)�self�version_stringrrr�get_grammar'sz_BaseEnvironment.get_grammarcCs.z|jWStyt|j�|_|jYSw�N)�_hash�AttributeError�_calculate_sha256_for_file�
  24  executable�rrrr�_sha256,s
  25  �z_BaseEnvironment._sha256N)rrrrr�propertyr$rrrrr&s
  26  
  27  rcCstjtjtjdd�fS�N�)�sysr"�prefixrrrrr�	_get_info5s�r*c@sLeZdZdZdZddd�Zdd�Zdd�Zd	d
  28  defdd
  29  �Z	e
  30  dd��ZdS)�Environmentz�
  31      This class is supposed to be created by internal Jedi architecture. You
  32      should not create it directly. Please use create_environment or the other
  33      functions instead. It is then returned by that function.
  34      NcCs||_||_|��dSr)�_start_executable�	_env_vars�_get_subprocess)rr"�env_varsrrr�__init__EszEnvironment.__init__c
  35  Cs�|jdur|jjs|jSzt|j|jd�|_|j�dt�}Wnty3}z	td|j|f��d}~ww|d|_		|d|_
  36  	t|d�|_	|jS)N�r/z,Could not get version information for %r: %rr��)
  37  �_subprocessZ
  38  is_crashedrr,r-Z_sendr*�	Exceptionr
  39  r"�path�_VersionInfor)r�info�excrrrr.Ks.�����
  40  
  41  zEnvironment._get_subprocesscCs*d�dd�|jD��}d|jj||jfS)N�.css�|]}t|�VqdSr)�str)�.0�irrr�	<genexpr>ks�z'Environment.__repr__.<locals>.<genexpr>z<%s: %s in %s>)�joinr�	__class__rr6)rrrrr�__repr__jszEnvironment.__repr__�inference_stater
  42  �returncCst||���Sr)r	r.�rrBrrr�get_inference_state_subprocessnsz*Environment.get_inference_state_subprocesscCs|����S)z�
  43          The sys path for this environment. Does not include potential
  44          modifications from e.g. appending to :data:`sys.path`.
  45  
  46          :returns: list of str
  47          )r.�get_sys_pathr#rrrrFts
  48  zEnvironment.get_sys_pathr)rrrrr4r0r.rAr	rErrFrrrrr+=s
  49  �
  50  �r+c@seZdZdd�ZdS)�_SameEnvironmentMixincCs4tj|_|_tj|_ttjdd��|_d|_dSr&)r(r"r,r)r6r7rr-r#rrrr0�s
  51  z_SameEnvironmentMixin.__init__N)rrrr0rrrrrG�srGc@seZdZdS)�SameEnvironmentN)rrrrrrrrH�srHc@s&eZdZdddefdd�Zdd�ZdS)	�InterpreterEnvironmentrBr
  52  rCcCst|�Sr)rrDrrrrE�sz5InterpreterEnvironment.get_inference_state_subprocesscCstjSr)r(r6r#rrrrF�sz#InterpreterEnvironment.get_sys_pathN)rrrrrErFrrrrrI�s�
  53  �rI�VIRTUAL_ENVcCsXtj�|�}|r*tj�|�tj�tj�krt�Szt|dd�WSt	y)YdSwdS)z�Get virtualenv environment from VIRTUAL_ENV environment variable.
  54  
  55      It uses `safe=False` with ``create_environment``, because the environment
  56      variable is considered to be safe / controlled by the user solely.
  57      F��safeN)
  58  �os�environ�getr6�realpathr(r)�_try_get_same_env�create_environmentr
  59  )�env_var�varrrr�_get_virtual_env_from_var�s��rUcsbt��}t|d���t�fdd�d�D]}|�|�qWd�|��S1s(wY|��S)N�rbcs��tj�Sr)�read�filecmp�BUFSIZEr��frr�<lambda>�sz,_calculate_sha256_for_file.<locals>.<lambda>�)�hashlib�sha256�open�iter�update�	hexdigest)r6r_�blockrrZrr!�s�
  60  ��r!cCs,t�}|dur	|Stt�}|dur|St�S)a|
  61      Tries to return an active Virtualenv or conda environment.
  62      If there is no VIRTUAL_ENV variable or no CONDA_PREFIX variable set
  63      set it will return the latest Python version installed on the system. This
  64      makes it possible to use as many new Python features as possible when using
  65      autocompletion and other functionality.
  66  
  67      :returns: :class:`.Environment`
  68      N)rU�
  69  _CONDA_VARrQ)�virtual_env�	conda_envrrr�get_default_environment�s
  70  rhcCs�t�}tj�|j����d�sGtjdkrd}ndtj	dtj
  71  dfdtj	ddf}|D]}tj�tj|�}tj�
  72  |�rCt|�Sq-t�S|S)	N�python�nt)zScripts\python.exe�
  73  python.exezbin/python%s.%srr2zbin/python%sz
  74  bin/python)rHrMr6�basenamer"�lower�
  75  startswith�namer(rrr?�exec_prefix�isfiler+rI)�envZchecks�check�guessrrrrQ�s
  76  ��rQcCsNtj�d�ptj�t�}t�}|r%tj�|�tj�|j�kr%t��t�S|S)NrJ)rMrNrOre�_get_cached_default_environmentr6rP�clear_cache)rT�environmentrrr�get_cached_default_environment�srxiX)�secondscCs"zt�WStyt�YSwr)rhr
  77  rIrrrrrus
  78  
  79  �ruT)rL�use_environment_varsc	
  80  cs��|durg}t�}|r-t�}|dur|V|�|j�tt�}|dur-|V|�|j�|D]>}tj�|�s8q/tj�|�}t�|�D])}tj�	||�}||vrQqC|�|�z
  81  t
  82  ||d�}t|�VWqCtylYqCwq/dS)a
  83  
  84      :param paths: A list of paths in your file system to be scanned for
  85          Virtualenvs. It will search in these paths and potentially execute the
  86          Python binaries.
  87      :param safe: Default True. In case this is False, it will allow this
  88          function to execute potential `python` environments. An attacker might
  89          be able to drop an executable in a path this function is searching by
  90          default. If the executable has not been installed by root, it will not
  91          be executed.
  92      :param use_environment_vars: Default True. If True, the VIRTUAL_ENV
  93          variable will be checked if it contains a valid VirtualEnv.
  94          CONDA_PREFIX will be checked to see if it contains a valid conda
  95          environment.
  96  
  97      :yields: :class:`.Environment`
  98      NrK)
  99  �setrU�addr6rerM�isdir�abspath�listdirr?�_get_executable_pathr+r
 100  )	�pathsrLrzZ_used_pathsrfrg�	directoryr6r"rrr�find_virtualenvss<�
 101  ���r�r1c	cs4�tD]}z	t||d�VWqtyYqwdS)a&
 102      Ignores virtualenvs and returns the Python versions that were installed on
 103      your system. This might return nothing, if you're running Python e.g. from
 104      a portable version.
 105  
 106      The environments are sorted from latest to oldest Python version.
 107  
 108      :yields: :class:`.Environment`
 109      r1N)�_SUPPORTED_PYTHONS�get_system_environmentr
 110  )r/rrrr�find_system_environmentsEs�
 111  ��r�c	Csptd|�}|r|tjkrt�St|�Stjdkr2t|�D]}z	t||d�WSty1Yqwtd|��)z�
 112      Return the first Python environment found for a string of the form 'X.Y'
 113      where X and Y are the major and minor versions of Python.
 114  
 115      :raises: :exc:`.InvalidPythonEnvironment`
 116      :returns: :class:`.Environment`
 117      rirjr1z Cannot find executable python%s.)	rr(r"rHr+rMro�&_get_executables_from_windows_registryr
 118  )rr/�exerrrr�Xs
 119  
 120  �r�)rLr/cCs6tj�|�rt||�t||d�Stt||d�|d�S)z�
 121      Make it possible to manually create an Environment object by specifying a
 122      Virtualenv path or an executable path and optional environment variables.
 123  
 124      :raises: :exc:`.InvalidPythonEnvironment`
 125      :returns: :class:`.Environment`
 126      r1rK)rMr6rq�_assert_safer+r�)r6rLr/rrrrRos
 127  rRcCsptjdkrtj�|dd�tj�|d�g}n	tj�|dd�g}|D]
 128  }tj�|�r*nq td|��t||�|S)z:
 129      Returns None if it's not actually a virtual env.
 130      rj�Scriptsrk�binriz%s seems to be missing.)rMror6r?�existsr
 131  r�)r6rLZpythonsrirrrr�}s
 132   �
 133  r�c
 134  cs��ddl}gd�}|j|jfD]F}|D]A}|j|d�}z0|�||�� }|�|d�d}tj�|d�}tj�	|�r;|VWd�n1sEwYWqt
 135  yTYqwqdS)Nr)z0SOFTWARE\Python\PythonCore\{version}\InstallPathz<SOFTWARE\Wow6432Node\Python\PythonCore\{version}\InstallPathz3SOFTWARE\Python\PythonCore\{version}-32\InstallPathz?SOFTWARE\Wow6432Node\Python\PythonCore\{version}-32\InstallPathr�rk)�winreg�HKEY_CURRENT_USER�HKEY_LOCAL_MACHINE�format�OpenKey�QueryValueExrMr6r?rq�WindowsError)rr�Zsub_keysZroot_key�sub_key�keyr)r�rrrr��s(�������r�cCs|r
 136  t|�std��dSdS)Nz(The python binary is potentially unsafe.)�_is_safer
 137  )�executable_pathrLrrrr��s
 138  ��r�cCsLtj�|�}t|�rdSt�D]}|j|krdS|jt|�kr#dSqdS)NTF)rMr6rP�_is_unix_safe_simpler�r"r$r!)r��	real_pathrwrrrr��s
 139  
 140  
 141  �r�cs0t�rt�fdd�tD��St���j}|dkS)Nc3s�|]}��|�VqdSr)rn)r<�p�r�rrr>�s�z'_is_unix_safe_simple.<locals>.<genexpr>r)�_is_unix_admin�any�_SAFE_PATHSrM�stat�st_uid)r��uidrr�rr��s
 142  r�cCs$zt��dkWStyYdSw)NrF)rM�getuidr rrrrr��s
 143  �r�)rJr)T)5rrMr(r^rX�collectionsr�shutilr�typingrZ
 144  jedi.cacherrZ"jedi.inference.compiled.subprocessrrr	rZjedi.inferencer
 145  r7r�r�rerrrZ_CURRENT_VERSIONr5r
 146  rr*r+rGrHrIrUr!rhrQrxrur�r�r�rRr�r�r�r�r�r�rrrr�<module>sT
 147  G
 148  (
 149  6
 150