
    lCe4=                       d Z ddlmZ ddlZddlZddlZddl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  G d
 dej                  ZddZddZddZddZddZd dZd!dZedk    r e             dS dS )"zgThe root `jupyter` command.

This does nothing other than dispatch to subcommands or output path info.
    )annotationsN)which)Popen)Any   )paths)__version__c                  T    e Zd ZdZedd            Zej        dd            Zdd	Zd
S )JupyterParserzA Jupyter argument parser.return
str | Nonec                J    dd                     t                                z  S )z}Add subcommands to epilog on request

        Avoids searching PATH for subcommands unless help output is requested.
        zAvailable subcommands: %s )joinlist_subcommands)selfs    4lib/python3.11/site-packages/jupyter_core/command.pyepilogzJupyterParser.epilog   s"     +SXX6F6H6H-I-III    xr   Nonec                    dS )z$Ignore epilog set in Parser.__init__N )r   r   s     r   r   zJupyterParser.epilog%   s	     	r   c                \    	 ddl }|                    |            dS # t          $ r Y dS w xY w)z#Trigger auto-completion, if enabledr   N)argcompleteautocompleteImportError)r   r   s     r   r   zJupyterParser.argcomplete*   sO    	$$T***** 	 	 	DD	s    
++N)r   r   )r   r   r   r   r   r   )__name__
__module____qualname____doc__propertyr   setterr   r   r   r   r   r      sr        $$J J J XJ ]   ]     r   r   r   c                    t          d          } |                     d          }|                    ddd           |                    d	t          d
d          }d |_        |                    ddd           |                    ddd           |                    ddd           |                    ddd           |                     ddd           |                     ddd           | S )zCreate a jupyter parser object.zJupyter: Interactive Computing)descriptionF)requiredz	--version
store_truez3show the versions of core jupyter packages and exit)actionhelp
subcommand?zthe subcommand to launch)typenargsr*   c                     t                      S N)r   )argskwargss     r   <lambda>z jupyter_parser.<locals>.<lambda>B   s    :J:L:L r   z--config-dirzshow Jupyter config dirz
--data-dirzshow Jupyter data dirz--runtime-dirzshow Jupyter runtime dirz--pathsz?show all Jupyter paths. Add --json for machine-readable format.z--jsonz%output paths as machine-readable jsonz--debugz$output debug information about paths)r   add_mutually_exclusive_groupadd_argumentstr	completer)parsergroupsubcommand_actions      r   jupyter_parserr;   4   sE   4  F ///??E	L/d     **3c0J +   #M"L	~lAZ[[[	|L?VWWW	|B\]]]	N    
 <cddd
	,=cdddMr   	list[str]c            
        t                      t                      D ]} 	 t          j        |           }n# t          $ r Y $w xY w|D ]}|                    d          rt          j                            d          r%t          j        	                    |          d         }
                    t          |                    d          dd                              t                      }D ]at          fdt          dt                              D                       s(|
                    d                                         bt#          |          S )zList all jupyter subcommands

    searches PATH for `jupyter-name`

    Returns a list of jupyter's subcommand names, without the `jupyter-` prefix.
    Nested children (e.g. jupyter-sub-subsub) are not included.
    jupyter-winr   -r   Nc              3  0   K   | ]}d |         v V  d S r0   r   ).0isub_tupsubcommand_tupless     r   	<genexpr>z#list_subcommands.<locals>.<genexpr>k   s1      TT72A2;"33TTTTTTr   )set_path_with_selfoslistdirOSError
startswithsysplatformpathsplitextaddtuplesplitanyrangelenr   sorted)dnamesnamesubcommandsrD   rE   s       @@r   r   r   R   sh     
B 
B	JqMMEE 	 	 	H	 	B 	BDz** B<**511 57++D11!4D!%%eDJJsOOABB,?&@&@AAA	B %%K$ / /TTTTTU1c'll=S=STTTTT 	/OOCHHW--...+s   7
AAcmdr6   argvr   c                   t           j                            d          rt          |           }|t	          d| z  t
          j                  t          |g|dd         z             }ddl}|                    |j	        |j
                   |                                 t          j        |j                   dS t          j        | |           dS )zexecvp, except on Windows where it uses Popen

    Python provides execvp on Windows, but its behavior is problematic (Python bug#9148).
    r?   Nz%r not foundr   r   )rM   rN   rL   r   rK   errnoENOENTr   signalSIGINTSIG_IGNwaitexit
returncoderI   execvp)r\   r]   cmd_pathpra   s        r   _execvprj   p   s    
 |u%%  ::.3.===8*tABBx'(( 	fmV^444	
	#tr   r+   c                   t           j                            t                                }d|  }t	          ||          }|d| d}t          |          t          j        |t           j                  sd| d}t          |          |S )z^This method get the abspath of a specified jupyter-subcommand with no
    changes on ENV.
    r>   )rO   Nz
Jupyter command `z` not found.z` is not executable.)rI   pathsepr   rH   r   	ExceptionaccessX_OK)r+   search_pathjupyter_subcommandabs_pathmsgs        r   _jupyter_abspathrt      s    
 *///"3"344K0J00'k:::HD$6DDDnn9Xrw'' L$6LLLnnOr   c                    t           j                            d          pt           j                            t           j                  } 	 t          j        d          }|                     |           n# t          $ r Y nw xY wt          j        d         g}t           j                            |d                   r8|                    t           j                            |d                              |D ]u}t           j                            |          }t           j                            |          r5t          j        |t           j                  r|                     d|           v| S )zPut `jupyter`'s dir at the front of PATH

    Ensures that /path/to/jupyter subcommand
    will do /path/to/jupyter-subcommand
    even if /other/jupyter-subcommand is ahead of it on PATH
    PATHscriptsr   )rI   environgetdefpathrS   rl   	sysconfigget_pathappendKeyErrorrM   r]   rO   islinkrealpathdirnameisdirrn   ro   insert)	path_listbindirrw   scripts       r   rH   rH      s9    ''52:<<RZHHI!#I..
 	    	     x{mG	w~~gaj!! 5rw''
33444 ( (((7==   	(RYvrw%?%? 	( Q'''s   
A4 4
B Br8   c                4   	 ddl m}m}  |            }|r:t          |          dk    r'|d                             d          s |             |S |                                  n$# t          $ r |                                  Y nw xY wd}t          |          )a  If argcomplete is enabled, trigger autocomplete or return current words

    If the first word looks like a subcommand, return the current command
    that is attempting to be completed so that the subcommand can evaluate it;
    otherwise auto-complete using the main parser.
    r   )get_argcomplete_cwordsincrement_argcomplete_indexr   r@   z3Control flow should not reach end of autocomplete())#traitlets.config.argcomplete_configr   r   rV   rL   r   r   AssertionError)r8   r   r   cwordsrs   s        r   _evaluate_argcompleter      s    	
 	
 	
 	
 	
 	
 	
 	

 (')) 	!c&kkAoofQi.B.B3.G.Go (')))M         	 @C


s   AA% A% %BBc                 D   t                      } t          j        }d}dt          j        v rt          |           }|d         }nt          |          dk    r%|d                             d          s
|d         }n|                                 \  }}|j	        }|j
        rbt          d           dD ]N}	 |dk    rt          }nt          |          }|j        }n# t          $ r d}Y nw xY wt          |d	d
|           OdS |j        r|j        st          j        d           |j        r|j        st          j        d           |j        r|j        rt          j        d           |j        r"t          t!          j                               dS |j        r"t          t!          j                               dS |j        r"t          t!          j                               dS |j        r:i }t!          j                    g|d<   t!          j                    |d<   t!          j                    |d<   |j        r#t          t          j        |                     n|j        r~t          j        }	t!          j                    rt          d           nt          d           t!          j                    rt          d           nt          d           |	                    d          rt          d           nt          d           |	                    d          r't          d|	                    d           d           nt          d           |	                    d          r't          d|	                    d           d           nt          d           t>          j         r%t          d t?          j!                     d!           n$t          d"t?          j!                     d!           |	                    d#          r't          d$|	                    d#           d%           nt          d&           |	                    d'          r't          d(|	                    d'           d)           nt          d*           |	                    d+          r't          d,|	                    d+           d-           nt          d.           t                       tE          |          D ]3}
||
         }t          d/|
z             |D ]}t          d0|z              4dS |s4| #                    t          j$        1           t          j        d2           	 tK          |          }nd# tL          $ rW}| #                    t          j$        1           |d3k    rY d}~dS t          j        tO          |                     Y d}~nd}~ww xY w	 tQ          ||g|d4d         z              dS # tR          $ r%}t          j        d5|d6|            Y d}~dS d}~ww xY w)7zThe command entry point.N_ARGCOMPLETEr   r@   z!Selected Jupyter core packages...)IPython	ipykernel
ipywidgetsjupyter_clientjupyter_corejupyter_server
jupyterlabnbclient	nbconvertnbformatnotebook	qtconsole	traitletsr   znot installedz<17:z --json is only used with --pathsz!--debug is only used with --pathsz"--debug cannot be used with --jsonruntimeconfigdatazjJUPYTER_PLATFORM_DIRS is set to a true value, so we use platformdirs to find platform-specific directorieszJUPYTER_PLATFORM_DIRS is set to a false value, or is not set, so we use hardcoded legacy paths for platform-specific directorieszJUPYTER_PREFER_ENV_PATH is set to a true value, or JUPYTER_PREFER_ENV_PATH is not set and we detected a virtual environment, making the environment-level path preferred over the user-level path for data and configzJUPYTER_PREFER_ENV_PATH is set to a false value, or JUPYTER_PREFER_ENV_PATH is not set and we did not detect a virtual environment, making the user-level path preferred over the environment-level path for data and configJUPYTER_NO_CONFIGzWJUPYTER_NO_CONFIG is set, making the config path list only a single temporary directoryzEJUPYTER_NO_CONFIG is not set, so we use the full path list for configJUPYTER_CONFIG_PATHzJUPYTER_CONFIG_PATH is set to 'zO', which is prepended to the config path list (unless JUPYTER_NO_CONFIG is set)zQJUPYTER_CONFIG_PATH is not set, so we do not prepend anything to the config pathsJUPYTER_CONFIG_DIRzJUPYTER_CONFIG_DIR is set to 'z5', overriding the default user-level config directoryzPJUPYTER_CONFIG_DIR is not set, so we use the default user-level config directoryzKPython's site.ENABLE_USER_SITE is True, so we add the user site directory ''z]Python's site.ENABLE_USER_SITE is not True, so we do not add the Python site user directory 'JUPYTER_PATHzJUPYTER_PATH is set to 'z'', which is prepended to the data pathszHJUPYTER_PATH is not set, so we do not prepend anything to the data pathsJUPYTER_DATA_DIRzJUPYTER_DATA_DIR is set to 'z3', overriding the default user-level data directoryzLJUPYTER_DATA_DIR is not set, so we use the default user-level data directoryJUPYTER_RUNTIME_DIRzJUPYTER_RUNTIME_DIR is set to 'z+', overriding the default runtime directoryzGJUPYTER_RUNTIME_DIR is not set, so we use the default runtime directoryz%s:z    )filez>
Please specify a subcommand or one of the optional arguments.r*      z Error executing Jupyter command z: )*r;   rM   r]   rI   rx   r   rV   rL   parse_known_argsr+   versionprintr	   
__import__r   jsonr   re   debug
config_dirjupyter_config_dirdata_dirjupyter_data_dirruntime_dirjupyter_runtime_dirjupyter_config_pathjupyter_pathdumpsuse_platform_dirsprefer_environment_over_userry   siteENABLE_USER_SITEgetuserbaserW   
print_helpstderrrt   rm   r6   rj   rK   )r8   r]   r+   r1   optspackager   modr   envrZ   rO   ri   commandes                  r   mainr      s   F8DJ##$V,,!W

	TQtAw11#66 !W

,,..
d_
< 	5666 2 2..00"-(11"%/" . . .-GGG.''''1111F9 	9TZ 	9H7888: 	:dj 	:H8999: 	;$) 	;H9:::? 	%*,,---F= 	%(**+++F 	%+--...F: f	D$8::;DO"688DN -//DLy `*dj&&'''': W*C.00  I     _   9;;  t     {  
 ww233 u    c   ww455  ncggF[>\>\  n  n  n    o   ww344  RSWWEY=Z=Z  R  R  R    n   , jnjzj|j|     R  }A  }M  }O  }O  R  R  R  
 ww~.. wsww~7N7Nwww    f   ww122  L377CU;V;V  L  L  L    j  
 ww455  JcggF[>\>\  J  J  J    e   GGG"4LL * *D:D%$,'''! * *fqj))))*F Tsz***RSSS":..   sz***FFFFFQI'T!""X-..... I I IGJGGAGGHHHHHHHHHIsH   5$CC)(C)U- -
W7&W	#!W		WW0 0
X:XX__main__)r   r   )r   r<   )r\   r6   r]   r<   r   r   )r+   r6   r   r6   )r8   r   r   r<   r   )r"   
__future__r   argparser_   r   rI   r   rM   r{   shutilr   
subprocessr   typingr    r   r   r	   ArgumentParserr   r;   r   rj   rt   rH   r   r   r   r   r   r   <module>r      s    # " " " " "    				  



                                            H+   4   <   <   .   (# # # #L   @qI qI qI qIh zDFFFFF r   