
    @eJ=                       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        yy)zgThe root `jupyter` command.

This does nothing other than dispatch to subcommands or output path info.
    )annotationsN)which)Popen)Any   )paths)__version__c                  P    e Zd ZdZedd       Zej                  dd       ZddZy)	JupyterParserzA Jupyter argument parser.c                :    ddj                  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    6/usr/lib/python3/dist-packages/jupyter_core/command.pyepilogzJupyterParser.epilog   s     +SXX6F6H-III    c                     y)z$Ignore epilog set in Parser.__init__N )r   xs     r   r   zJupyterParser.epilog%   s     	r   c                N    	 ddl }|j                  |        y# t        $ r Y yw xY w)z#Trigger auto-completion, if enabledr   N)argcompleteautocompleteImportError)r   r   s     r   r   zJupyterParser.argcomplete*   s*    	$$T* 		s    	$$N)returnz
str | None)r   r   r   Noner   r   )__name__
__module____qualname____doc__propertyr   setterr   r   r   r   r   r      s6    $J J ]] r   r   c                    t        d      } | j                  d      }|j                  ddd       |j                  d	t        d
d      }d |_        |j                  ddd       |j                  ddd       |j                  ddd       |j                  ddd       | j                  ddd       | j                  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 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   s    4F ///?E	L/d   **3c0J +  #M	~lAZ[	|L?VW	|B\]	N  
 <cd
	,=cdMr   c            
     Z   t               t               D ]  } 	 t        j                  |       }|D ]  }|j                  d      st        j                  j                  d      r"t        j                  j                  |      d   }j                  t        |j                  d      dd                t               }D ]K  t        fdt        dt                    D              r,|j                  dj!                               M t#        |      S # t        $ r Y w xY w)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  ,   K   | ]  }d | v   y wr/   r   ).0isub_tupsubcommand_tupless     r   	<genexpr>z#list_subcommands.<locals>.<genexpr>k   s     T72A;"33Ts   )set_path_with_selfoslistdirOSError
startswithsysplatformpathsplitextaddtuplesplitanyrangelenr   sorted)dnamesnamesubcommandsrB   rC   s       @@r   r   r   R   s     
B	JJqME  	BDz*<<**5177++D1!4D!%%eDJJsOAB,?&@A	B
B %K$ /TU1c'l=STTOOCHHW-./ +  		s   D	D*)D*c                   t         j                  j                  d      rt        |       }|t	        d| z  t
        j                        t        |g|dd z         }ddl}|j                  |j                  |j                         |j                          t        j                  |j                         yt        j                  | |       y)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   )rK   rL   rJ   r   rI   errnoENOENTr   signalSIGINTSIG_IGNwaitexit
returncoderG   execvp)cmdargvcmd_pathpr]   s        r   _execvprh   p   s    
 ||u% :.3.==8*tABx'( 	fmmV^^4	
		#tr   c                   t         j                  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<   )rM   z
Jupyter command `z` not found.z` is not executable.)rG   pathsepr   rF   r   	ExceptionaccessX_OK)r*   search_pathjupyter_subcommandabs_pathmsgs        r   _jupyter_abspathrr      s    
 **///"34K#J<0'k:H#$6#7|Dn99Xrww'#$6#77KLnOr   c                    t         j                  j                  d      xs t         j                  j	                  t         j
                        } 	 t        j                  d      }| j                  |       t        j                  d   g}t         j                  j                  |d         r1|j                  t         j                  j                  |d                |D ]x  }t         j                  j                  |      }t         j                  j!                  |      sBt        j"                  |t         j$                        sg| j'                  d|       z | S # t        $ r Y w xY w)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   )rG   environgetdefpathrQ   rj   	sysconfigget_pathappendKeyErrorrK   re   rM   islinkrealpathdirnameisdirrl   rm   insert)	path_listbindirru   scripts       r   rF   rF      s    '52::<<RZZHI!##I.
 	 xx{mG	ww~~gaj!rww''
34 ((77== RYYvrww%? Q'( #  s   E 	E('E(c                    	 ddl m}m}  |       }|r+t        |      dkD  r|d   j	                  d      s	 |        |S | j                          	 d}t        |      # t        $ r | j                          Y (w xY w)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   rT   rJ   r   r   AssertionError)r7   r   r   cwordsrq   s        r   _evaluate_argcompleter      s    	

 ()c&kAofQi.B.B3.G ()M  
 @C

   	s   ;A A A87A8c                 d   t               } t        j                  }d}dt        j                  v rt        |       }|d   }nxt        |      dkD  r|d   j                  d      s|d   }nO| j                         \  }}|j                  }|j                  rGt        d       dD ]6  }	 |dk(  rt        }nt        |      }|j                  }t        |d	d
|       8 y|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(                                y|j*                  rt        t!        j,                                y|j.                  rt        t!        j0                                y|j                   ri }t!        j0                         g|d<   t!        j2                         |d<   t!        j4                         |d<   |j                  rt        t        j6                  |             y|j$                  rt        j                  }	t!        j8                         rt        d       nt        d       t!        j:                         rt        d       nt        d       |	j=                  d      rt        d       nt        d       |	j=                  d      rt        d|	j=                  d       d       nt        d       |	j=                  d      rt        d|	j=                  d       d       nt        d       t>        j@                  r"t        d t?        jB                          d!       n!t        d"t?        jB                          d!       |	j=                  d#      rt        d$|	j=                  d#       d%       nt        d&       |	j=                  d'      rt        d(|	j=                  d'       d)       nt        d*       |	j=                  d+      rt        d,|	j=                  d+       d-       nt        d.       t                tE        |      D ]*  }
||
   }t        d/|
z         |D ]  }t        d0|z           , y|s5| jG                  t        jH                  1       t        j"                  d2       	 tK        |      }	 tQ        |g|d4d z          y# t        $ r d}Y Vw xY w# tL        $ rR}| jG                  t        jH                  1       |d3k(  rY d}~yt        j"                  tO        |             Y d}~}d}~ww xY w# tR        $ r%}t        j"                  d5|d6|        Y d}~y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:   rK   re   rG   rv   r   rT   rJ   parse_known_argsr*   versionprintr	   
__import__r   jsonr   ra   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_userrw   siteENABLE_USER_SITEgetuserbaserU   
print_helpstderrrr   rk   r5   rh   rI   )r7   re   r*   r0   optspackager   modr   envrX   rM   rg   commandes                  r   mainr      sG   F88DJ#$V,!W
	TQtAw11#6 !W
,,.
d__
<<56 2..0"-(1"%// Q'1/20 99TZZHH78::djjHH89::$))HH9:??%**,-==%((*+%++-.::D$88:;DO"668DN --/DLyydjj&'@ } ::**C..0 I  _ 99; t  {
 ww23u c ww45=cggF[>\=]  ^m  n o ww34<SWWEY=Z<[  \Q  R n ,,ijnjzjzj|i}}~ {  }A  }M  }M  }O  |P  PQ  R
 ww~.6sww~7N6OOvw f ww12:377CU;V:W  XK  L j
 ww45=cggF[>\=]  ^I  J e G"4L *D:D%$,'! *fqj)**
 szz*RS":.I'T!"X-.S # .-G.B  szz*Q  I3J>A3GHHIsH   &#T1T# =V T T #	U>,%U9U99U>	V/
V**V/__main__)r   r   )r   	list[str])rd   r5   re   r   r   r   )r*   r5   r   r5   )r7   r   r   r   r   )r!   
__future__r   argparser[   r   rG   r   rK   ry   shutilr   
subprocessr   typingr    r   r   r	   ArgumentParserr   r:   r   rh   rr   rF   r   r   r   r   r   r   <module>r      s    #    	  
       H++ 4<<.(#L@qIh zF r   