
    ^h'                         S SK r S SKrS SKJr  S SKJr  S SKJr  S SKJ	r	  S SK
JrJr  S SKJr  S SKJr  S S	KJr  S S
KJr  SrS\4S jrS rS r\" / S9S 5       rS rS rS\4S jrS\4S jrS rS rg)    N)Path)all_suffixes)inference_state_method_cache)ContextualizedNode)	is_stringget_str_or_none)get_cached_code_lines)FileIO)settings)debug
   str_pathc                     [        U5      nUR                  5       (       a  U$ U R                  5       nUc  g UR                  nUR	                  U5      R                  5       $ N)r   is_absolute
py__file__parentjoinpathabsolute)module_contextr   pathmodule_pathbase_dirs        Q/home/james-whalen/.local/lib/python3.13/site-packages/jedi/inference/sys_path.py	_abs_pathr      s]    >D ++-K !!HT"++--    c              #     #    [        UR                  SSS2   UR                  SSS2   5       GH2  u  p# US;   d   eUR                  S;   a  [        UR                  5      S:  d   eUR                  nUS   R                  S:X  a  US   R                  S:X  d   eUS   nUR                  S   S	:X  a  UR                  S   R                  S
:X  d   e [        U R                  U5      U5      nUR                  5       R                  U5       HN  nUR                  5        H7  n[        U5      (       d  M  [        XR                  5       5      n	U	c  M3  U	v   M9     MP     GM5     g! [
         a     GMF  f = f7f)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+=power	atom_exprr   namesys.r   )zipchildrentypelenvalueAssertionErrorr   create_contextinferiterater   r   get_safe_value)
r   	expr_stmtassigneeoperatorctrailercn
lazy_valuer+   abs_paths
             r   _paths_from_assignmentr9       sl     ")"4"4SqS"99;M;MadQRd;ST	{***==$::H%%&*+ +!!AQ499&1Q4::+>>>dG##A&#-'2B2B12E2K2Kv2UUU
   = =i H)T((*,,R0J#))+U##(9M9M9OPH+&	 , 11 U(  		s6   3E9BE'AE97E9E9'
E61E95E66E9c              #     #    UR                   S:X  aO  UR                  S   S:X  a<  UR                   S:X  a,  UR                  S   S:X  a  [        UR                  5      S:X  d  gUR                  S   R                  nUS;  a  gUR                  S   nUS	:X  a(  [        UR                  5      S
;   a  UR                  S   nU R	                  U5      R                  U5       H'  n[        U5      nUc  M  [        X5      nUc  M#  Uv   M)     g7f)zDextract the path from either "sys.path.append" or "sys.path.insert" r5   r   r&   (   Nr   )insertappendr=   )r<      r   )r)   r(   r*   r+   r-   
infer_noder   r   )r   trailer1trailer2r$   argr+   pr8   s           r   _paths_from_list_modificationsrE   K   s      MMY&8+<+<Q+?3+F*x/@/@/Cs/JH%%&!+Q%%D''


A
CxC-7ll1o..s3>>sCE"9^/N Ds   C=D	D)defaultc           	         S nU R                   c  / $ / n U R                   R                  5       S   nU" U5       H  u  pEUR                  n[        UR                  5      S:  a*  UR                  [        U /UR                  SS Q76 5        MT  Uc  MY  UR                  S:X  d  Mk  UR                  [        X5      5        M     U$ ! [         a     U$ f = f)z.
Detect sys.path modifications within module.
c              3     #    U  H  nUR                   R                   nUc  M  UR                  S;   d  M0  UR                  nUS   R                  S:X  d  MQ  US   R                  S:X  d  Mf  US   R                  S:X  d  M{  US   R                  S   nUR                  S:X  d  M  UR                  S:X  d  M  X4v   M     g 7f)Nr!   r   r$   r%   r   r5   r   )r   r)   r(   r+   )namesr$   r"   r4   ns        r   get_sys_path_powers9check_sys_path_modifications.<locals>.get_sys_path_powersi   s     DKK&&E UZZ3I%INNQ499&1Q4::+>aDII2!a(Avv'AGGv,="k) s-   C C C C +C   C $C 6
C r   r?   r   r1   )
	tree_nodeget_used_namesr   r*   r(   extendrE   r)   r9   KeyError)r   rK   addedpossible_namesr$   r"   r1   s          r   check_sys_path_modificationsrS   d   s    
	* '	EP'11@@B6J /~>KDI5>>"a'2&).!)<
 &9>>[+H3NNO ? L   Ls   C 
CCc                     [        5       n[        U5       H<  n[        X5       H*  nUR                  U5        [	        U5      [
        :  d  M)    M:     M>     U$ r   )set_get_buildout_script_paths_get_paths_from_buildout_scriptaddr*   _BUILDOUT_PATH_INSERTION_LIMIT)inference_statescript_pathbuildout_script_pathsbuildout_script_pathr   s        r   discover_buildout_pathsr^      sS    E :; G3OZD!%%d+()-KK [ !H ! r   c           
   #   N  #    [        [        U5      5      n U R                  US[        R                  S9nSSKJ	n  U" XUS [        U R                  U5      S9R                  5       n[        U5       S h  vN   g ! [
         a    [        R                  " SU5         g f = f N,7f)NT)file_iocache
cache_pathz(Error trying to read buildout_script: %sr   )ModuleValue)r`   string_names
code_lines)r
   strparser   cache_directoryIOErrorr   warningjedi.inference.valuerc   r	   grammar
as_contextrS   )rZ   r]   r`   module_noderc   r   s         r   rW   rW      s     S-./G%++// , 
 1 ()@)@BVW	
 jl  ,N;;;  @BVW <s3   B%A< ?B%6B#7B%<!B B%B  B%r   c                     U R                    H,  n UR                  U5      R                  5       (       a  Us  $ M.     g ! [         a     M>  f = fr   )parentsr   is_fileOSError)r   filenamer   s      r   _get_parent_dir_with_filert      sP    ,,	x(0022 3    		s   %>
AAsearch_pathc              #     #    [        U S5      nU(       d  gUR                  S5      nUR                  5       (       d  g[        R                  " U5       HZ  n UR                  U5      n[        US5       nUR                  5       nUR                  S5      (       a
  SU;   a  Uv   SSS5        M\     g! , (       d  f       Mn  = f! [        [        4 a*  n[        R                  " [        U5      5         SnAM  SnAff = f7f)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)rt   r   existsoslistdiropenreadline
startswithUnicodeDecodeErrorri   r   rj   rf   )ru   project_rootbin_pathrs   filepathf	firstlinees           r   rV   rV      s      -[.IL$$U+H??JJx(
	((2Hh$JJL	''--(i2G"N %$ ) %$ #G, 	 MM#a&!		sT   ADC51B3&C.D3
C	=C DCC?C:4D:C??Dc                     [        5       S/-    H1  nU R                  U:X  d  M  U R                  U R                  5      n   U $    U $ )Nz.pyi)r   suffix	with_namestem)r   r   s     r   remove_python_path_suffixr      sB    .F8+;;& >>$)),DK	 , Kr   c                    ^ ^ [        T5      mTR                  R                  S5      (       a  gTR                  S:H  nU(       a  TR                  mUU 4S jn[	        U" 5       5      nU(       d  g[        US S9S   U4$ )a3  
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     >#    T H  n [        T5      R                  U 5      (       d  M$  [        T5      [        U 5      S  nUR                  [        R                  R
                  5      (       d  UR                  S5      (       a  USS  nU(       d  M  UR                  [        R                  R
                  5      n[        U5      (       d    g [        S U 5       5      v   M     g 7f)N/r   c              3   R   #    U  H  n[         R                  " S SU5      v   M     g7f)z-stubs$ N)resub).0ss     r   	<genexpr>Mtransform_path_to_dotted.<locals>.iter_potential_solutions.<locals>.<genexpr>  s      I5az2q 9 95s   %')	rf   r   r*   r{   r   sepsplitalltuple)rD   restr   r   sys_paths      r   iter_potential_solutions:transform_path_to_dotted.<locals>.iter_potential_solutions   s     A;**1--;'A0??277;;//4??33G3G8D4 JJrww{{3Eu::   I5III% s   #C'A%C'AC'c                     [        U 5      $ r   )r*   )rD   s    r   <lambda>*transform_path_to_dotted.<locals>.<lambda>  s    SVr   )keyr   )r   r$   r   r   r   sorted)r   r   
is_packager   potential_solutionss   ``   r   transform_path_to_dottedr      s     ,K8K""3'' !!Z/J!((J*   8 :; %+;<Q?KKr   ) r{   r   pathlibr   importlib.machineryr   jedi.inference.cacher   jedi.inference.base_valuer   jedi.inference.helpersr   r   jedi.parser_utilsr	   jedi.file_ior
   jedir   r   rY   rf   r   r9   rE   rS   r^   rW   rt   rV   r   r    r   r   <module>r      s    	 	  , = 8 = 3   !# . .('V2 b)" *"J	!<,D D :5Lr   