
    G@d$                        d Z ddlZddl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 ddlmZmZ ddlmZ ddlmZmZ dd	lmZ dd
lmZmZmZ ddlmZmZ ddlmZ ddl m!Z!  ej"        e#          Z$ G d d          Z% G d de          Z&dS )zKite completion HTTP client.    N)Slot)QMessageBox)on_conf_change)_running_under_pytest)SpyderCompletionProvider)ApplicationMenusToolsMenuSections)
KiteClient)check_if_kite_runningcheck_if_kite_installed"check_kite_installers_availability)KiteInstallationErrorMessageKiteStatusWidget)ima)run_programc                       e Zd ZdZdS )KiteProviderActionskite_installationN)__name__
__module____qualname__Installation     Qlib/python3.11/site-packages/spyder/plugins/completion/providers/kite/provider.pyr   r   %   s        &LLLr   r   c                       e Zd ZdZdZdZg dZdZ fdZd Z	d Z
d	 Zd
 Zd Zd Z ee          d             Z ee           ee          d                         Zd Z edd          d             Z edd          d             Zed             Zd Z ee          d             Z eee          d             Zd Zd Zd Z  xZ!S )KiteProviderkite   T))spyder_runsr    )show_installation_dialogT)show_onboardingT)show_installation_error_messageT)installers_availableTz0.1.0c                    t                                          ||           g | _        t          d           | _        d | _        | j        j                            | j                   | j        j	        t                                       | j                   | j        j	        t                                       | j                   | j        j                            t          j        | j        j        | j                             | j        j                            | j                   | j        g| _        |                     | j                   |                                  d S N)super__init__available_languagesr   clientkite_processsig_client_startedconnecthttp_client_readysig_status_response_readystr
set_statusdictsig_response_ready	functoolspartialemitCOMPLETION_PROVIDER_NAMEsig_client_wrong_response_wrong_response_errorcreate_statusbarSTATUS_BAR_CLASSESupdate_kite_configurationconfigsetup_menus)selfparentr>   	__class__s      r   r)   zKiteProvider.__init__6   sL   (((#%  &&  	&..t/EFFF-c2::O	 	 	-d3;;O	 	 	&..d5:";= =	> 	> 	> 	-55&	( 	( 	(
 !#

 	&&t{333 	r   c                     dS )NKiter   r@   s    r   get_namezKiteProvider.get_nameU   s    vr   c                     || j         v r#| j        j                            |||           d S | j                            | j        |i            d S r'   )r*   r+   sig_perform_requestr7   r4   r8   )r@   languagereq_typereqreq_ids        r   send_requestzKiteProvider.send_requestX   sb    t///K+003GGGGG#(()F)/5 5 5 5 5r   c                     || j         v S r'   )r*   )r@   rI   s     r   &start_completion_services_for_languagez3KiteProvider.start_completion_services_for_language_   s    4333r   c                 ~   	 t                      \  }}|s	 | j                                         d S t                              d                    |                     t                      }|r	 | j                                         d S t                              d           t          |          | _        n# t          $ r t                      \  }}t                              d                    |                     | 
                    d          rit          d                              t          j        |                    }t          j        || j                  }| j                            |           Y nw xY w| j                                         d S # | j                                         w xY w)Nz!Kite was found on the system: {0}zStarting Kite service...z(Error starting Kite service at {path}...)pathr$   zIt seems that your Kite installation is faulty. If you want to use Kite, please remove the directory that appears bellow, and try a reinstallation:<br><br><code>{kite_dir}</code>)kite_dir)r   r+   startloggerdebugformatr   r   r,   OSErrorget_confr   ospdirnamer   instanceset_confsig_show_widgetr7   )r@   	installedrQ   runningerr_strdialog_wrappers         r   rS   zKiteProvider.startb   s   	 577OIt 2 K1 LL<CCDIIJJJ+--G * K) LL3444 +D 1 1D 	: 	: 	:577OItLL:AAtALLN N N}}>?? :./ /
 06v!$T!2!2 06 04 04  ">!FT]", ",$)).999	:$ KDKs5   B9 =B9 
.B9 8F! 9CF F! FF! !F<c                     	 |                      t          j        t          j                   n# t
          $ r Y nw xY w| j                                         | j        | j        	                                 d S d S )N)menu_id)
!remove_item_from_application_menur   r   r	   ToolsKeyErrorr+   stopr,   killrE   s    r   shutdownzKiteProvider.shutdown   s    	22#0(. 3 0 0 0 0  	 	 	D	 	(""$$$$$ )(s   +. 
;;c                     | j         j                            | j                   | j         j                            | j                   | j         j                            | j                   d S r'   )r+   r4   r.   _kite_onboardingr0   sig_onboarding_response_ready_show_onboarding_filerE   s    r   on_mainwindow_visiblez"KiteProvider.on_mainwindow_visible   sg    &..t/DEEE-55d6KLLL199&	( 	( 	( 	( 	(r   c                     t                               d                    |                     || _        | j                            | j                   |                                  d S )Nz Kite client is available for {0})rT   rU   rV   r*   sig_provider_readyr7   r8   rk   )r@   	languagess     r   r/   zKiteProvider.http_client_ready   s]    7>>yIIJJJ#, $$T%BCCCr   c                 V    | j                             t          j        d|fi            dS )z&Show Kite status for the current file.	set_valueNsig_call_statusbarr7   r   ID)r@   statuss     r   r2   zKiteProvider.set_status   s7     	$$vi	= 	= 	= 	= 	=r   c                 D    | j         j                            |           dS )z"Request status for the given file.N)r+   sig_perform_status_requestr7   )r@   filename	_languages      r   file_opened_closed_or_updatedz*KiteProvider.file_opened_closed_or_updated   s!    .33H=====r   completions)enabled_providersr   )sectionoptionc                 T    | j                             t          j        ddi            d S )Nrs   r'   rt   r@   values     r   on_kite_enable_changedz#KiteProvider.on_kite_enable_changed   s5     	$$gr	; 	; 	; 	; 	;r   enable_code_snippetsc                     t                      r!t          j                            d          sd S |                     dd          | j        _        d S )NSPY_TEST_USE_INTROSPECTIONr   r}   )r   )r   osenvirongetrX   r+   r   r   s     r   on_code_snippets_changedz%KiteProvider.on_code_snippets_changed   sT    !! 	:>>">?? +/=="M ,9 ,; ,;(((r   c                     t                      r!t          j                            d          sd S |                     d          | _        d S )Nr   r#   )r   r   r   r   rX   _show_onboarding)r@   r>   s     r   r=   z&KiteProvider.update_kite_configuration   sG    !! 	:>>">??  $.? @ @r   c                 t    | j         sdS | j        sdS d| _         | j        j                                         dS )zRequest the onboarding file.NF)r   r*   r+   sig_perform_onboarding_requestr7   rE   s    r   rk   zKiteProvider._kite_onboarding   sI     $ 	F' 	F %27799999r   c                 |    |s	d| _         dS | j                            |           |                     dd           dS )z
        Opens the onboarding file, which is retrieved
        from the Kite HTTP endpoint. This skips onboarding if onboarding
        is not possible yet or has already been displayed before.
        TNr#   F)r   sig_open_filer7   r\   )r@   onboarding_files     r   rm   z"KiteProvider._show_onboarding_file   sK      	$(D!F000'/////r   c                     t          d                              ||          fd}| j                            |           | j                            | j                   d S )NaX  The Kite completion engine returned an unexpected result for the request <tt>{0}</tt>: <br><br><tt>{1}</tt><br><br>Please make sure that your Kite installation is correct. In the meantime, Spyder will disable the Kite client to prevent further errors. For more information, please visit the <a href='https://help.kite.com/'>Kite help center</a>c                 J    t          j        | t          d                    S )Nz
Kite error)r   criticalr   )rA   err_msgs    r   wrap_messagez8KiteProvider._wrong_response_error.<locals>.wrap_message   s    ',IIIr   )r   rV   r]   r7   sig_disable_providerr8   )r@   methodrespr   r   s       @r   r:   z"KiteProvider._wrong_response_error   s      !&.. 		J 	J 	J 	J 	J 	!!,///!&&t'DEEEEEr   c                 "    t          ||           S r'   )r   )r@   rA   s     r   r;   zKiteProvider.create_statusbar   s    ---r   c                 l    | j                             t          j        dt	                      i            d S )Nr"   )ru   r7   r   rv   tuplerE   s    r   show_kite_installationz#KiteProvider.show_kite_installation   s=    $$!;UWWb	J 	J 	J 	J 	Jr   c                 |   t                      }|                     d|           t                      \  }}|s|r|                     t          j        t          d          t          j        d          | j	                  }| 
                    |t          j        t          j        t          j                   d S d S d S )Nr%   zInstall Kite completion enginer   )icon	triggered)rc   r   before_section)r   r\   r   create_actionr   r   r   r   r   r   add_item_to_application_menur	   re   r
   ExternalExtras)r@   r%   is_kite_installed	kite_pathinstall_kite_actions        r   r?   zKiteProvider.setup_menus   s    ACC,.BCCC'>'@'@$9  	9%9 	9"&"4"4#0233Xf%%5	 #5 #7 #7 --#(.)207	 . 9 9 9 9 9	9 	9 	9 	9r   )"r   r   r   r8   DEFAULT_ORDERSLOWCONF_DEFAULTSCONF_VERSIONr)   rF   rM   rO   rS   ri   rn   r   listr/   r1   r3   r2   r|   r   r   r   r=   rk   rm   objectr:   r;   r   r?   __classcell__)rB   s   @r   r   r   )   s3       %MD  M L    >  5 5 54 4 4     >% % %( ( ( 
T$ZZ    Z  
T#YY	T$ZZ= = Z Y=
> > > ^&CE E E; ;E E; ^M2HIII; ; JI; A A ^A
: 
: 
: 
T#YY0 0 Y0 
T#vF F F . . .J J J9 9 9 9 9 9 9r   r   )'__doc__loggingr5   r   os.pathrQ   rY   qtpy.QtCorer   qtpy.QtWidgetsr   spyder.api.config.decoratorsr   spyder.config.baser   r   spyder.plugins.completion.apir   spyder.plugins.mainmenu.apir	   r
   /spyder.plugins.completion.providers.kite.clientr   5spyder.plugins.completion.providers.kite.utils.statusr   r   r   0spyder.plugins.completion.providers.kite.widgetsr   r   spyder.utils.icon_managerr   spyder.utils.programsr   	getLoggerr   rT   r   r   r   r   r   <module>r      s   # "      				             & & & & & & 8 7 7 7 7 7 6 6 6 6 6 6 6 6 B B B B B B K K K K K K K K F F F F F F( ( ( ( ( ( ( ( ( (4 4 4 4 4 4 4 4 ) ) ) ) ) ) - - - - - - 
	8	$	$' ' ' ' ' ' ' 'V9 V9 V9 V9 V9+ V9 V9 V9 V9 V9r   