Ë
    ¬;jŸ@  ã                   óú   — d Z ddlZddlmZ ddlmZ ddlmZ ddlm	Z	m
Z
 ddlmZ ddlmZ dd	lmZmZ dd
lmZmZmZ ddlmZ ddlmZ ddlmZmZ ddlmZ dZdZ dZ!d„ Z"d„ Z# G d„ d«      Z$d„ Z%d„ Z&dd„Z'd„ Z(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_environmentÚcreate_environment)ÚWrongVersion)Úsearch_in_module)Úsplit_search_stringÚget_module_names)Úload_module_from_pathÚload_namespace_from_pathÚiter_module_names)Údiscover_buildout_paths)Ú%inference_state_as_method_param_cache)Ú%recurse_find_python_folders_and_filesÚsearch_in_file_ios)ÚFolderIOz.jedi)zsetup.pyz.gitz.hgzrequirements.txtzMANIFEST.inzpyproject.tomlé   c                 ó   ‡ — ˆ fd„}|S )Nc               ?   ó  •K  — g }g } ‰| i |¤ŽD ]y  }|j                   j                  }|�||v rŒ |j                  dk(  r6|j                  �*|j                  |v rŒJ|j	                  |j                  «       |–— |j	                  |«       Œ{ y ­w)NÚmodule)Ú_nameÚ	tree_nameÚtypeÚmodule_pathÚappend)ÚargsÚkwargsÚfound_tree_nodesÚfound_modulesÚ
definitionÚ	tree_nodeÚfuncs         €úa/workspace/moltex-experiments/.pixi/envs/default/lib/python3.12/site-packages/jedi/api/project.pyÚwrapperz(_try_to_skip_duplicates.<locals>.wrapper"   s˜   øè ø€ ØÐØˆÙ Ð/¨Ô/ˆJØ"×(Ñ(×2Ñ2ˆIØÐ$¨Ð6FÑ)FØØ�‰ (Ò*¨z×/EÑ/EÐ/QØ×)Ñ)¨]Ñ:ØØ×$Ñ$ Z×%;Ñ%;Ô<ØÒØ×#Ñ# IÕ.ñ 0ùs   ƒB
B© )r#   r%   s   ` r$   Ú_try_to_skip_duplicatesr'   !   s   ø€ ô/ð €Nó    c              #   ób   K  — t        «       }| D ]  }||v rŒ|j                  |«       |–— Œ y ­w©N)ÚsetÚadd)ÚpathÚusedÚps      r$   Ú_remove_duplicates_from_pathr0   2   s1   è ø€ Ü‹5€DÛˆØ�‰9ØØ�‰�ŒØ‹ñ	 ùs   ‚-/c                   ó  — e Zd ZdZdZed„ «       Zed„ «       Zed„ «       Z	d„ Z
ddddd	d
œ	 dd„Zed„ «       Zed„ «       Zed„ «       Zed„ «       Z e«       d„ «       Z e«       dd„«       Zd„ Zddœd„Zd„ Zedd„«       Zd„ Zy)Ú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                 ó,   — | j                  t        «      S r*   )ÚjoinpathÚ_CONFIG_FOLDER©Ú	base_paths    r$   Ú_get_config_folder_pathzProject._get_config_folder_pathC   s   € à×!Ñ!¤.Ó1Ð1r(   c                 óJ   — t         j                  | «      j                  d«      S )Nzproject.json)r2   r8   r4   r6   s    r$   Ú_get_json_pathzProject._get_json_pathG   s   € ä×.Ñ.¨yÓ9×BÑBÀ>ÓRÐRr(   c                 óö   — t        |t        «      rt        |«      }t        | j	                  |«      «      5 }t        j                  |«      \  }}ddd«       dk(  r | di ¤ŽS t        d«      ‚# 1 sw Y   Œ!xY w)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.
        Nr   zEThe Jedi version of this project seems newer than what we can handle.r&   )Ú
isinstanceÚstrr   Úopenr:   ÚjsonÚloadr   )Úclsr-   ÚfÚversionÚdatas        r$   r@   zProject.loadK   sp   € ô �dœCÔ Ü˜“:ˆDÜ�#×$Ñ$ TÓ*Ô+¨qÜ ŸI™I a›L‰MˆG�T÷ ,ð �aŠ<Ù‘;˜‘;ÐäØWóð ÷ ,Ð+ús   ¶A/Á/A8c                 ó  — t        | j                  «      }|j                  dd«       |j                  dd«       |j                  «       D ��ci c]  \  }}|j	                  d«      |“Œ }}}t        |d   «      |d<   | j                  | j                  «      j                  dd¬«       t        | j                  | j                  «      d«      5 }t        j                  t        |f|«      cddd«       S c c}}w # 1 sw Y   yxY w)	z[
        Saves the project configuration in the project in ``.jedi/project.json``.
        Ú_environmentNÚ_djangoÚ_r-   T)ÚparentsÚexist_okÚw)ÚdictÚ__dict__ÚpopÚitemsÚlstripr=   r8   Ú_pathÚmkdirr>   r:   r?   ÚdumpÚ_SERIALIZER_VERSION)ÚselfrD   ÚkÚvrB   s        r$   ÚsavezProject.save_   sÒ   € ô �D—M‘MÓ"ˆØ�‰� Ô&Ø�‰�˜DÔ!Ø-1¯Z©Z¬\Ô:©\¡T Q¨�—‘˜“˜qÑ ¨\ˆÑ:Ü˜4 ™<Ó(ˆˆV‰à×$Ñ$ T§Z¡ZÓ0×6Ñ6¸tÈdÐ6ÔSÜ�$×%Ñ% d§j¡jÓ1°3Ô7¸1Ü—9‘9Ô1°4Ð8¸!Ó<÷ 8Ñ7ùó	 ;÷ 8Ð7ús   ÁC4ÃC:Ã:DFr&   T)Úenvironment_pathÚload_unsafe_extensionsÚsys_pathÚadded_sys_pathÚsmart_sys_pathc                ó  — t        |t        «      rt        |«      j                  «       }|| _        || _        |�t        t        t        |«      «      }|| _        || _	        || _
        d| _        t        t        t        |«      «      | _        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=   r   ÚabsoluterQ   Ú_environment_pathÚlistÚmapÚ	_sys_pathÚ_smart_sys_pathÚ_load_unsafe_extensionsrG   r\   )rU   r-   rY   rZ   r[   r\   r]   s          r$   Ú__init__zProject.__init__m   s{   € ô: �dœCÔ Ü˜“:×&Ñ&Ó(ˆDØˆŒ
à!1ˆÔØÐäœC¤ XÓ.Ó/ˆHØ!ˆŒØ-ˆÔØ'=ˆÔ$ØˆŒä"¤3¤s¨NÓ#;Ó<ˆÔØGr(   c                 ó   — | j                   S )z1
        The base path for this project.
        )rQ   ©rU   s    r$   r-   zProject.pathš   s   € ð
 �z‰zÐr(   c                 ó   — | j                   S )zz
        The sys path provided to this project. This can be None and in that
        case will be auto generated.
        )rc   rh   s    r$   r[   zProject.sys_path¡   s   € ð �~‰~Ðr(   c                 ó   — | j                   S )zu
        If the sys path is going to be calculated in a smart way, where
        additional paths are added.
        )rd   rh   s    r$   r]   zProject.smart_sys_path©   s   € ð ×#Ñ#Ð#r(   c                 ó   — | j                   S )z=
        Wheter the project loads unsafe extensions.
        )re   rh   s    r$   rZ   zProject.load_unsafe_extensions±   s   € ð
 ×+Ñ+Ð+r(   c                 ó�   — t        |j                  j                  «       «      }	 |j                  d«       |S # t        $ r Y |S w xY w)NÚ )ra   ÚenvironmentÚget_sys_pathÚremoveÚ
ValueError)rU   Úinference_stater[   s      r$   Ú_get_base_sys_pathzProject._get_base_sys_path¸   sN   € ô ˜×3Ñ3×@Ñ@ÓBÓCˆð	Ø�O‰O˜BÔð ˆøô ò 	ØØˆð	ús   ¥8 ¸	AÁAc                 ó*  — t        | j                  «      }g }| j                  €t        | j                  |«      «      }nt        | j                  «      }| j                  ré|j                  t        | j                  «      «       |j                  �¹|t        t        t        ||j                  «      «      z  }|r�g }|j                  j                  D ]g  }|| j                  k(  s| j                  |j                  vr n>|s |j                  d«      j                  «       rŒN|j                  t        |«      «       Œi |t        |«      z  }| j                  r$|j                  t        | j                  «      «       ||z   |z   }	t        t!        |	«      «      S )zƒ
        Keep this method private for all users of jedi. However internally this
        one is used like a public method.
        ú__init__.py)ra   r\   rc   rs   rd   r   r=   rQ   Úscript_pathrb   r   rI   r4   Úis_fileÚreversedrG   r0   )
rU   rr   Úadd_parent_pathsÚadd_init_pathsÚsuffixedÚprefixedr[   Ú	traversedÚparent_pathr-   s
             r$   Ú_get_sys_pathzProject._get_sys_pathÂ   sV  € ô ˜×+Ñ+Ó,ˆØˆà�>‰>Ð!Ü˜D×3Ñ3°OÓDÓE‰Hä˜DŸN™NÓ+ˆHà×ÒØ�O‰OœC §
¡
›OÔ,à×*Ñ*Ð6ØœC¤Ô%<Ø#Ø#×/Ñ/ó&ó ñ �ñ
 $ð !#�IØ'6×'BÑ'B×'JÔ'J˜Ø&¨$¯*©*Ò4Ø#'§:¡:°[×5HÑ5HÑ#HÙ!Ù-Ø$/×$8Ñ$8¸Ó$G×$OÑ$OÔ$QØ$Ø!×(Ñ(¬¨[Ó)9Õ:ð (Kð ¤¨Ó 3Ñ3�Hà�<Š<Ø�O‰OœC §
¡
›OÔ,à˜(Ñ" XÑ-ˆÜÔ0°Ó6Ó7Ð7r(   c                 ó¸   — | j                   €C| j                  �(t        | j                  d¬«      | _         | j                   S t        «       | _         | j                   S )NF)Úsafe)rF   r`   r   r   rh   s    r$   Úget_environmentzProject.get_environmentò   sX   € Ø×ÑÐ$Ø×%Ñ%Ð1Ü$6°t×7MÑ7MÐTYÔ$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)rU   Ústringr„   s      r$   ÚsearchzProject.searchú   s   € ð* × Ñ  °JÐ Ó?Ð?r(   c                 ó,   —  | j                   |fddi|¤Ž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†   )rU   rˆ   r   s      r$   Úcomplete_searchzProject.complete_search  s!   € ð !ˆt× Ñ  ÑA°$ÐA¸&ÑAÐAr(   c              #   ód  K  — ddl m}  |d| ¬«      }|j                  }|j                  «       }t	        j
                  d||«       t        |«      \  }}	|	d   }
|
dz   }t        t        t        | j                  «      «      «      }g }|D ]á  \  }}|€H|j                  «       }||
k(  s||k(  r-|j                  d«      }	 t        ||«      j                  «       }nWŒP|j#                  |«       t%        |j&                  «      j(                  |
d	z   |
d
z   fv rt        ||«      j                  «       }nŒ¦t	        j
                  d|«       t+        |||j(                  g||	|dd¬«      E d {  –—†  Œã t-        |||
|¬«      D ]\  }t/        |j0                  |¬«      }|D �cg c]  }|j3                  |«      ‘Œ }}t5        |«      }t+        |||||	|d¬«      E d {  –—†  Œ^ | j7                  |«      D �cg c]  }|| j                  k7  r|‘Œ }}t9        t;        |||«      «      }t+        |||||	|d¬«      E d {  –—†  y # t        $ rZ |j                  d«      }	 t        ||«      j                  «       }n)# t        $ r t!        ||«      j                  «       }Y nw xY wY �Œlw xY w7 �Œ9c c}w 7 ŒÒc c}w 7 Œz­w)Nr   )ÚScriptrm   )Úprojectz!Search for string %s, complete=%sz-stubsru   z__init__.pyiz.pyz.pyizSearch of a specific module %sT)ÚnamesÚwanted_typeÚwanted_namesr‹   ÚconvertÚignore_imports)r‹   rƒ   )r�   r‘   r’   r‹   r”   )r�   r‘   r’   r‹   r“   )ÚjedirŽ   Ú_inference_stateÚ_get_module_contextr   Údbgr
   r   r   r=   rQ   Úget_base_nameÚget_file_ior   Ú
as_contextÚFileNotFoundErrorr   r   r   r-   Únamer	   r   r   r"   Úcreate_nameÚ_remove_importsr   ra   r   )rU   rˆ   r‹   r„   rŽ   Úsrr   Úempty_module_contextr‘   r’   r�   Ústub_folder_nameÚiosÚfile_iosÚ	folder_ioÚfile_ioÚ	file_namerB   ÚmÚmodule_contextr�   Únr/   r[   s                           r$   r‡   zProject._search_func  sß  è ø€ õ 	 Ù�2˜tÔ$ˆØ×,Ñ,ˆØ ×4Ñ4Ó6Ðä�	‰	Ð5°v¸xÔHÜ$7¸Ó$?Ñ!ˆ�\Ø˜A‰ˆØ (™?Ðä3´H¼SÀÇÁ»_Ó4MÓNˆØˆó #&ÑˆI�wØˆØ%×3Ñ3Ó5�	Ø Ò$¨	Ð5EÒ(EØ!×-Ñ-¨mÓ<�AðbÜ1°/À1ÓE×PÑPÓR™ð à—‘ Ô(Ü˜Ÿ™Ó%×*Ñ*¨t°e©|¸TÀF¹]Ð.KÑKÜ-¨o¸wÓG×RÑRÓT‘Aàä�I‰IÐ6¸Ô:Ü'ØØØ—v‘v�hØ'Ø)Ø!ØØ#ô	÷ 	ñ 	ð/ #&ôF 1°À(Ø15À÷JˆNä$ ^×%=Ñ%=È*ÔUˆEÙ<AÓB¹E°q�^×/Ñ/°Õ2¸EˆEÐBÜ# EÓ*ˆEÜ'ØØØØ'Ø)Ø!Ø#ô÷ ñ ðJð" ×)Ñ)¨/Ô:ó
Ù:�!à�D—J‘JŠò Ð:ð 	ð 
ô
 Ô& Ð8LÈhÓWÓXˆÜ#ØØ ØØ#Ø%ØØô
÷ 	
ñ 	
øôe -ò bØ%×1Ñ1°.ÓA˜ðbÜ 5°oÀqÓ I× TÑ TÓ V™AøÜ0ò bÜ 8¸È)Ó T× _Ñ _Ó ašAðbýð	búð 	ûò Cðúò
ð	
ús—   ‚B:J0Â=H9ÃBJ0Å&JÅ'3J0ÆJ"Æ2"J0ÇJ'ÇJ0Ç.J)È-J0È3J.È4J0È9JÉI/É.JÉ/#JÊJÊJÊJÊJ0ÊJÊJ0Ê"J0Ê)J0c                 óP   — d| j                   j                  ›d| j                  ›d�S )NÚ<z: Ú>)Ú	__class__Ú__name__rQ   rh   s    r$   Ú__repr__zProject.__repr__q  s   � Ø!Ÿ^™^×4Ó4°d·j³jÐAÐAr(   )ÚreturnN)TF)FF)r¯   Ú
__module__Ú__qualname__Ú__doc__rF   Ústaticmethodr8   r:   Úclassmethodr@   rX   rf   Úpropertyr-   r[   r]   rZ   r   rs   r   r‚   r‰   rŒ   r'   r‡   r°   r&   r(   r$   r2   r2   ;   s$  „ ñð
 €Làñ2ó ð2ð ñSó ðSð ñó ðò&=ð$ Ø$ØØØñ+Hð 
ó+HðZ ñó ðð ñó ðð ñ$ó ð$ð ñ,ó ð,ñ +Ó,ñó -ðñ +Ó,ò-8ó -ð-8ò^!ð ,1ô @ò.
Bð òQ
ó ðQ
ófBr(   r2   c                 ó|   — t         D ]$  }	 | j                  |«      j                  «       r yŒ& y# t        $ r Y Œ3w xY w)NTF)Ú_CONTAINS_POTENTIAL_PROJECTr4   ÚexistsÚOSError)r-   r�   s     r$   Ú_is_potential_projectr¼   u  sG   € ß+ˆð	Ø�}‰}˜TÓ"×)Ñ)Ô+Ùð ,ð ,ð øô ò 	Ùð	ús   ‹/¯	;º;c                 ó¾   — 	 t        | j                  d«      d«      5 }d|j                  «       v cddd«       S # 1 sw Y   yxY w# t        t        t
        f$ r Y yw xY w)zB Detects the path of the very well known Django library (if used) z	manage.pyÚrbs   DJANGO_SETTINGS_MODULENF)r>   r4   Úreadrœ   ÚIsADirectoryErrorÚPermissionError)Ú	directoryrB   s     r$   Ú_is_django_pathrÃ     sQ   € ðÜ�)×$Ñ$ [Ó1°4Ô8¸AØ,°·±³Ð8÷ 9×8Ò8ûäÔ0´/ÐBò Ùðús*   ‚A �9¯	A ¹A¾A ÁA ÁAÁAc                 ó�  — | €t        j                  «       } nt        | t        «      rt        | «      } | j	                  «       }d}d}t        |g|j                  «      D ]  }	 t        j                  |«      c S  |�t        |«      S |�t        |«      S | j'                  «       r| n| j(                  }t        |«      S # t        t        t        f$ r Y nt        $ r Y Œw xY w|€2|j                  d«      j                  «       rŒ¥|j                  «       s|}t!        |«      rt        |«      }d|_        |c S |�ŒÛ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``.
    Nru   T)r   Úcwdr<   r=   r_   r   rI   r2   r@   rœ   rÀ   rÁ   ÚNotADirectoryErrorr4   rº   rw   rÃ   rG   r¼   Úis_dirÚparent)r-   ÚcheckÚprobable_pathÚfirst_no_init_fileÚdirr�   Úcurdirs          r$   Úget_default_projectrÎ   ˆ  s2  € ð €|Ü�x‰x‹z‰Ü	�Dœ#Ô	Ü�D‹zˆà�M‰M‹O€EØ€MØÐÜ�e�W˜eŸm™mÖ,ˆð	Ü—<‘< Ó$Ò$ð -ð0 Ð Ü�}Ó%Ð%àÐ%ÜÐ)Ó*Ð*à—[‘[”]‰T¨¯©€FÜ�6‹?Ðøô9 "Ô#4´oÐFò 	ÙÜ!ò 	Ùð	úð Ð%Ø�|‰|˜MÓ*×1Ñ1Ô3ð Ø—[‘[”]Ø%(Ð"ä˜3ÔÜ˜c“lˆGØ"ˆGŒOØŠNàÑ Ô%:¸3Õ%?Ø‰Ms   Á"B=Â=CÃCÃCc                 ó`   — | D �cg c]  }|j                   �|j                  dvr|‘Œ  c}S c c}w )N)r   Ú	namespace)r   Úapi_type)r�   rª   s     r$   rŸ   rŸ   ¼  s<   € áóÙˆaØ�;‰;Ð !§*¡*Ð4KÑ"Kò 	
�5ñð ùò s   …#+r*   ))r´   r?   Úpathlibr   Ú	itertoolsr   r•   r   Újedi.api.environmentr   r   Újedi.api.exceptionsr   Újedi.api.completionr	   Újedi.api.helpersr
   r   Újedi.inference.importsr   r   r   Újedi.inference.sys_pathr   Újedi.inference.cacher   Újedi.inference.referencesr   r   Újedi.file_ior   r5   r¹   rT   r'   r0   r2   r¼   rÃ   rÎ   rŸ   r&   r(   r$   Ú<module>rÝ      s}   ðñó Ý Ý å ß SÝ ,Ý 0ß B÷0ñ 0å ;Ý Fß _Ý !à€àRð ð Ð òò"÷wBñ wBòt	òó1óhr(   