TL i'ddlZddlZddlmZddlmZddlmZddlm Z ddl m Z m Z ddl mZddlmZdd lmZdd lmZd Zd efd ZdZdZegdZdZdZdefdZdefdZdZdZy)N)Path) all_suffixes)inference_state_method_cache)ContextualizedNode) is_stringget_str_or_none)get_cached_code_lines)FileIO)settings)debug str_pathct|}|jr|S|j}|y|j}|j |j SN)r is_absolute py__file__parentjoinpathabsolute)module_contextrpath module_pathbase_dirs ]/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/jedi/inference/sys_path.py _abs_pathrsZ >D   ++-K!!H   T " + + --c#Kt|jddd|jdddD]\}} |dvsJ|jdvrt|jdkDsJ|j}|djdk(r|djdk(sJ|d}|jdd k(r|jdjd k(sJ t |j||}|jj|D]D}|jD]/}t|st||j} | ,| 1F!y#t $rY/wxYww) 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_exprrnamesys.r) zipchildrentypelenvalueAssertionErrorrcreate_contextinferiteraterrget_safe_value) r expr_stmtassigneeoperatorctrailercn lazy_valuer+abs_paths r_paths_from_assignmentr9 s|")"4"4SqS"99;M;MadQRd;ST'( {* **==$::H%%&* ++!!AQ499&1Q4::+> >>dG##A&#-'2B2B12E2K2Kv2U UU    = =i H) T((*,,R0 'J#))+ 'U#(9M9M9OPH+&  ' '1'(   s64E"BE AE")E" E" EE"EE"c#K|jdk(rK|jddk(r9|jdk(r*|jddk(rt|jdk(sy|jdj}|dvry|jd}|d k(r&t|jd vr|jd }|j |j |D]#}t |}|t||}| |%yw) zE extract the path from either "sys.path.append" or "sys.path.insert" r5rr&(Nr)insertappendr=)r<r)r)r(r*r+r- infer_noderr)rtrailer1trailer2r$argr+pr8s r_paths_from_list_modificationsrEKs MMY &8+<+>sC E " 9 ^Q/  N s C3C=6C=)defaultc d}|jgSg} |jjd}||D]\}}|j}t|jdk\r)|j t |g|jddS|V|jdk(sf|j t|||S#t$rY|SwxYw)z6 Detect sys.path modifications within module. c3dK|D]}|jj}||jdvs+|j}|djdk(sJ|djdk(s]|djdk(sp|djd}|jdk(s|jdk(s||fyw)Nr!rr$r%rr5r)rr)r(r+)namesr$r"r4ns rget_sys_path_powersz9check_sys_path_modifications..get_sys_path_powersis *DKK&&E UZZ3I%INNQ499&1Q4::+>aDII2! a(Avv'AGGv,="Ek) *s-B0B0B0B0"B05!B0B0' B0rr?rr1) tree_nodeget_used_namesrr*r(extendrEr)r9KeyError)rrKaddedpossible_namesr$r"r1s rcheck_sys_path_modificationsrRds *' EP'11@@B6J/~> PKD% I5>>"a' 2&).!)< &9>>[+H 3NINO P L    L sB?? C  C ct}t|D]8}t||D]'}|j|t |t k\s'8:|Sr)set_get_buildout_script_paths_get_paths_from_buildout_scriptaddr*_BUILDOUT_PATH_INSERTION_LIMIT)inference_state script_pathbuildout_script_pathsbuildout_script_pathrs rdiscover_buildout_pathsr]s^E :; G3OEYZ D ! % %d +()-KK  ! rc #XKtt|} |j|dtj}ddlm }||||dt|j|j}t|Ed{y#t $rt jd|YywxYw7*w)NT)file_iocache cache_pathz(Error trying to read buildout_script: %sr) ModuleValue)r_ string_names code_lines)r strparser cache_directoryIOErrorr warningjedi.inference.valuerbr grammar as_contextrR)rYr\r_ module_noderbrs rrVrVsS-./G%++//, 1 ()@)@BVW  jl  ,N;;;  @BVWB*B%"B*$B%%B*rc|jD]&} |j|jr|cS(y#t$rY5wxYwr)parentsris_fileOSError)rfilenamers r_get_parent_dir_with_filerssR,, x(002 3    s 7 AA search_pathc#Kt|d}|sy|jd}|jsytj|D]R} |j|}t |d5}|j }|jdrd|vr|dddTy#1swY xYw#ttf$r(}tjt|Yd}~d}~wwxYww)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.cfgNbinrz#!python) rsrexistsoslistdiropenreadline startswithUnicodeDecodeErrorrhr rire)rt project_rootbin_pathrrfilepathf firstlinees rrUrUs-[.IL $$U+H ?? JJx(  ((2Hh$ #JJL ''-(i2G"N #  # ##G,  MM#a& !   sHA C% B+**BB+C%B( $B++C":CC%C""C%ctdgzD]/}|j|k(s|j|j}|S|S)Nz.pyi)rsuffix with_namestem)rrs rremove_python_path_suffixrsG.F8+ ;;& >>$)),D  K  Krctjjdryjdk(}|r jfd}t |}|syt |dd|fS)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__c3KD]}tj|stt|d}|jtjj s|jdr|dd}|sw|j tjj }t|sytd|Dyw)N/rc3JK|]}tjdd|yw)z-stubs$N)resub).0ss r zMtransform_path_to_dotted..iter_potential_solutions..sIaz2q 9Is!#) rer~r*rzrsepsplitalltuple)rDrestrrsys_paths riter_potential_solutionsz:transform_path_to_dotted..iter_potential_solutionss JA;**1-;'A0??277;;/4??33G8D JJrww{{3Eu: I5III% Js C AC =A C ct|Sr)r*)rDs rz*transform_path_to_dotted..s SVr)keyr)rr$r~rrsorted)rr is_packagerpotential_solutionss`` rtransform_path_to_dottedrs~,K8K""3' !!Z/J!(( J* 8 :;  %+; rs ,=8=3!# . .('V2b)"*"J !<,DD:5Lr