TL i@dZddlZddlmZddlmZddlmZddlm Z m Z ddl m Z ddl mZdd lmZmZdd lmZmZmZdd lmZdd lmZdd lmZmZddlmZdZdZ dZ!dZ"dZ#GddZ$dZ%dZ&ddZ'dZ(y)a Projects are a way to handle Python projects within Jedi. For simpler plugins you might not want to deal with projects, but if you want to give the user more flexibility to define sys paths and Python interpreters for a project, :class:`.Project` is the perfect way to allow for that. Projects can be saved to disk and loaded again, to allow project definitions to be used across repositories. N)Path)chain)debug)get_cached_default_environmentcreate_environment) WrongVersion)search_in_module)split_search_stringget_module_names)load_module_from_pathload_namespace_from_pathiter_module_names)discover_buildout_paths)%inference_state_as_method_param_cache)%recurse_find_python_folders_and_filessearch_in_file_ios)FolderIOz.jedi)zsetup.pyz.gitz.hgzrequirements.txtz MANIFEST.inzpyproject.tomlcfd}|S)Nc?Kg}g}|i|D]y}|jj}|||vr |jdk(r6|j*|j|vrJ|j |j||j |{yw)Nmodule)_name tree_nametype module_pathappend)argskwargsfound_tree_nodes found_modules definition tree_nodefuncs V/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/jedi/api/project.pywrapperz(_try_to_skip_duplicates..wrapper"s // /J"((22I$6F)F(*z/E/E/Q))]:$$Z%;%;<   # #I . /sB B )r#r%s` r$_try_to_skip_duplicatesr'!s / Nc#bKt}|D]}||vr|j||ywN)setadd)pathusedps r$_remove_duplicates_from_pathr02s6 5D  9    s-/ceZdZdZdZedZedZedZ dZ ddddd d  dd Z e d Z e d Ze dZe dZedZeddZdZdddZdZeddZdZy)Projectz Projects are a simple way to manage Python folders and define how Jedi does import resolution. It is mostly used as a parameter to :class:`.Script`. Additionally there are functions to search a whole project. Nc,|jtSr*)joinpath_CONFIG_FOLDER base_paths r$_get_config_folder_pathzProject._get_config_folder_pathCs!!.11r(cJtj|jdS)Nz project.json)r2r8r4r6s r$_get_json_pathzProject._get_json_pathGs..y9BB>RRr(ct|tr t|}t|j |5}t j |\}}ddddk(r|diStd#1swY!xYw)z Loads a project from a specific path. You should not provide the path to ``.jedi/project.json``, but rather the path to the project folder. :param path: The path of the directory you want to use as a project. NrzEThe Jedi version of this project seems newer than what we can handle.r&) isinstancestrropenr:jsonloadr)clsr-fversiondatas r$r@z Project.loadKsw dC :D #$$T* + )q IIaLMGT ) a<;; W   ) )s A//A8c t|j}|jdd|jdd|jDcic]\}}|j d|}}}t |d|d<|j |jjddt|j|jd5}tjt|f|cdddScc}}w#1swYyxYw) z[ Saves the project configuration in the project in ``.jedi/project.json``. _environmentN_django_r-T)parentsexist_okw)dict__dict__popitemslstripr=r8_pathmkdirr>r:r?dump_SERIALIZER_VERSION)selfrDkvrBs r$savez Project.save_sDMM" & D!-1ZZ\:TQ q ::4<(V  $$TZZ066td6S $%%djj13 7 =199148!< = = ; = =s C4C::DFr&T)environment_pathload_unsafe_extensionssys_pathadded_sys_pathsmart_sys_pathct|trt|j}||_||_|t tt|}||_||_ ||_ d|_ t tt||_ y)a$ :param path: The base path for this project. :param environment_path: The Python executable path, typically the path of a virtual environment. :param load_unsafe_extensions: Default False, Loads extensions that are not in the sys path and in the local directories. With this option enabled, this is potentially unsafe if you clone a git repository and analyze it's code, because those compiled extensions will be important and therefore have execution privileges. :param sys_path: list of str. You can override the sys path if you want. By default the ``sys.path.`` is generated by the environment (virtualenvs, etc). :param added_sys_path: list of str. Adds these paths at the end of the sys path. :param smart_sys_path: If this is enabled (default), adds paths from local directories. Otherwise you will have to rely on your packages being properly configured on the ``sys.path``. NF) r<r=rabsoluterQ_environment_pathlistmap _sys_path_smart_sys_path_load_unsafe_extensionsrGr\)rUr-rYrZr[r\r]s r$__init__zProject.__init__ms{: dC :&&(D !1  CX./H!-'=$ "3sN#;<Gr(c|jS)z1 The base path for this project. )rQrUs r$r-z Project.paths zzr(c|jS)zz The sys path provided to this project. This can be None and in that case will be auto generated. )rcrhs r$r[zProject.sys_paths ~~r(c|jS)zu If the sys path is going to be calculated in a smart way, where additional paths are added. )rdrhs r$r]zProject.smart_sys_paths ###r(c|jS)z= Wheter the project loads unsafe extensions. )rerhs r$rZzProject.load_unsafe_extensionss +++r(ct|jj} |jd|S#t$rY|SwxYw)N)ra environment get_sys_pathremove ValueError)rUinference_stater[s r$_get_base_sys_pathzProject._get_base_sys_pathsN33@@BC  OOB    s8 AAc*t|j}g}|jt|j|}nt|j}|jr|j t |j|j|tt t||jz }|rg}|jjD]g}||jk(s|j|jvrn>|s |jdjrN|j t |i|t|z }|jr$|j t |j||z|z} tt!| S)z Keep this method private for all users of jedi. However internally this one is used like a public method. __init__.py)rar\rcrsrdrr=rQ script_pathrbrrIr4is_filereversedrGr0) rUrradd_parent_pathsadd_init_pathssuffixedprefixedr[ traversed parent_pathr-s r$ _get_sys_pathzProject._get_sys_pathsZ ++, >> !D33ODEHDNN+H    OOC O ,**6C%<##//& $!#I'6'B'B'J'J; &$**4#'::[5H5H#H!-$/$8$8$G$O$O$Q$!(([)9:; 33H << OOC O ,("X-0677r(c|jC|j(t|jd|_|jSt|_|jS)NF)safe)rFr`rrrhs r$get_environmentzProject.get_environmentsX    $%%1$6t7M7MTY$Z!   %C$D!   r( all_scopesc(|j||S)aO Searches a name in the whole project. If the project is very big, at some point Jedi will stop searching. However it's also very much recommended to not exhaust the generator. Just display the first ten results to the user. There are currently three different search patterns: - ``foo`` to search for a definition foo in any file or a file called ``foo.py`` or ``foo.pyi``. - ``foo.bar`` to search for the ``foo`` and then an attribute ``bar`` in it. - ``class foo.bar.Bar`` or ``def foo.bar.baz`` to search for a specific API type. :param bool all_scopes: Default False; searches not only for definitions on the top level of a module level, but also in functions and classes. :yields: :class:`.Name` r _search_func)rUstringrs r$searchzProject.searchs*  J ??r(c ,|j|fddi|S)au Like :meth:`.Script.search`, but completes that string. An empty string lists all definitions in a project, so be careful with that. :param bool all_scopes: Default False; searches not only for definitions on the top level of a module level, but also in functions and classes. :yields: :class:`.Completion` completeTr)rUrrs r$complete_searchzProject.complete_searchs!!t  A$A&AAr(c #dKddlm}|d|}|j}|j}t j d||t |\}} | d} | dz} ttt|j} g} | D]\}}|H|j}|| k(s|| k(r-|jd} t||j}nWP| j#|t%|j&j(| d z| d zfvrt||j}nt j d |t+|||j(g|| |d d Ed{t-|| | |D]\}t/|j0|}|Dcgc]}|j3|}}t5|}t+||||| |d Ed{^|j7|Dcgc]}||jk7r|}}t9t;|||}t+||||| |d Ed{y#t$rZ|jd} t||j}n)#t$rt!||j}YnwxYwYlwxYw79cc}w7cc}w7zw)Nr)Scriptrm)projectz!Search for string %s, complete=%sz-stubsruz __init__.pyiz.pyz.pyizSearch of a specific module %sT)names wanted_type wanted_namesrconvertignore_imports)rr)rrrrr)rrrrr)jedir_inference_state_get_module_contextrdbgr rrr=rQ get_base_name get_file_ior as_contextFileNotFoundErrorr rrr-namer rr r" create_name_remove_importsrrar)rUrrrrsrrempty_module_contextrrrstub_folder_nameiosfile_ios folder_iofile_io file_namerBmmodule_contextrnr/r[s r$rzProject._search_funcs 2t $,, 446 5vxH$7$?! \A(?3HS_4MN#&  Iw%335 $ 5E(E!--m) __class____name__rQrhs r$__repr__zProject.__repr__qs!^^44djjAAr()returnN)TF)FF)r __module__ __qualname____doc__rF staticmethodr8r: classmethodr@rXrfpropertyr-r[r]rZrrsrrrrr'rrr&r(r$r2r2;s$ L22SS& =$$+H +HZ $$,, +,-+,-8--8^!,1@. BQ Q fBr(r2c|tD]$} |j|jry&y#t$rY3wxYw)NTF)_CONTAINS_POTENTIAL_PROJECTr4existsOSError)r-rs r$_is_potential_projectrusL+ }}T"))+,    s / ;;c t|jdd5}d|jvcdddS#1swYyxYw#ttt f$rYywxYw)zB Detects the path of the very well known Django library (if used) z manage.pyrbsDJANGO_SETTINGS_MODULENF)r>r4readrIsADirectoryErrorPermissionError) directoryrBs r$_is_django_pathrsZ )$$[14 8 9A,8 9 9 9 0/ Bs*A9 AAAAAAc|tj}nt|tr t|}|j }d}d}t |g|j D]} tj|cS| t|S| t|S|j'r|n |j(}t|S#tttf$rYnt$rYwxYw|2|jdjr|js|}t!|rt|}d|_|cS|t%|s|})aI If a project is not defined by the user, Jedi tries to define a project by itself as well as possible. Jedi traverses folders until it finds one of the following: 1. A ``.jedi/config.json`` 2. One of the following files: ``setup.py``, ``.git``, ``.hg``, ``requirements.txt`` and ``MANIFEST.in``. NruT)rcwdr<r=r_rrIr2r@rrrNotADirectoryErrorr4rrwrrGris_dirparent)r-check probable_pathfirst_no_init_filedirrcurdirs r$get_default_projectrs7 |xxz D# Dz MMOEMeWemm,  <<$ $ 0 }%%%)**[[]T F 6?9"#4oF  !     %||M*113[[]%(" 3 clG"GON  %:3%?Ms"B==CCCc`|Dcgc]}|j|jdvr| c}Scc}w)N)r namespace)rapi_type)rrs r$rrs8  ;; !**4K"K   s#+r*))rr?pathlibr itertoolsrrrjedi.api.environmentrrjedi.api.exceptionsrjedi.api.completionr jedi.api.helpersr r jedi.inference.importsr r rjedi.inference.sys_pathrjedi.inference.cacherjedi.inference.referencesrr jedi.file_iorr5rrTr'r0r2rrrrr&r(r$rs} S,0B00;F_!R"wBwBt 1hr(