
    Mhi=                       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 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)Path)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strc                N    d                     t                                }d| S )z}Add subcommands to epilog on request

        Avoids searching PATH for subcommands unless help output is requested.
         zAvailable subcommands: )joinlist_subcommands)selfsubcommandss     T/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/jupyter_core/command.pyepilogzJupyterParser.epilog   s*     88$4$6$6776666    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      sn        $$7 7 7 X7 ]3 3 3 ]3     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>C   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_argumentr   	completer)parsergroupsubcommand_actions      r   jupyter_parserr<   5   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          t          |                                                     }n# t
          $ r Y >w xY w|D ]}|j        }|                    d          rct          j	                            d          r|j
        }                    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-win-r   Nc              3  0   K   | ]}d |         v V  d S r2   r   ).0isub_tupsubcommand_tupless     r   	<genexpr>z#list_subcommands.<locals>.<genexpr>m   s1      TT72A2;"33TTTTTTr   )set_path_with_selflistr   iterdirOSErrorname
startswithsysplatformstemaddtuplesplitanyrangelenr   sorted)d	bin_pathspathrM   r   rE   rF   s        @@r   r   r   S   sl     B B	T!WW__..//II 	 	 	H	 	B 	BD9Dz** B<**511 %9D!%%eDJJsOOABB,?&@&@AAA	B %%K$ / /TTTTTU1c'll=S=STTTTT 	/OOCHHW--...+s   .A
AAcmdr   argvr   c                   t           j                            d          rt          |           }|| d}t	          |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
 not foundr   r   )rO   rP   rN   r   rL   errnoENOENTr   signalSIGINTSIG_IGNwaitexit
returncodeosexecvp)r\   r]   cmd_pathmsgpra   s         r   _execvprl   r   s    
 |u%%  ::&&&C#u|,,,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?   )r[   Nz
Jupyter command `z` not found.z` is not executable.)rg   pathsepr   rI   r   	ExceptionaccessX_OK)r-   search_pathjupyter_subcommandabs_pathrj   s        r   _jupyter_abspathru      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          |d                                                   r8|                    t           j                            |d                              |D ]y}t!          t          |          j                  }t          |                                          r5t          j        |t           j                  r|                     d|           z| 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   )rg   environgetdefpathrT   rn   	sysconfigget_pathappendKeyErrorrO   r]   r   
is_symlinkr[   realpathr   parentis_dirrp   rq   insert)	path_listbindirrx   scripts       r   rI   rI      sF    ''52:<<RZHHI!#I..
 	    	     x{mGGAJ""$$ 5rw''
33444 ( (T&\\())<<   	(RYvrw%?%? 	( Q'''s   
A4 4
B Br9   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   rA   z3Control flow should not reach end of autocomplete())#traitlets.config.argcomplete_configr   r   rW   rN   r   r   AssertionError)r9   r   r   cwordsrj   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
           |D ]}t          d/|z              4dS |s4| #                    t          j$        0           t          j        d1           	 tK          |          }nd# tL          $ rW}| #                    t          j$        0           |d2k    rY d}~dS t          j        tO          |                     Y d}~nd}~ww xY w	 tQ          ||g|d3d         z              dS # tR          $ r%}t          j        d4|d5|            Y d}~dS d}~ww xY w)6zThe command entry point.N_ARGCOMPLETEr   rA   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    )filez>
Please specify a subcommand or one of the optional arguments.r,      z Error executing Jupyter command z: )*r<   rO   r]   rg   ry   r   rW   rN   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_userrz   siteENABLE_USER_SITEgetuserbaserX   
print_helpstderrru   ro   r   rl   rL   )r9   r]   r-   r3   optspackager   modr   envrM   r[   rk   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T***%%%! * *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\   r   r]   r=   r   r   )r-   r   r   r   )r9   r   r   r=   r    ) r$   
__future__r   argparser_   r   rg   r   rO   r|   pathlibr   shutilr   
subprocessr   typingr    r	   r   r
   ArgumentParserr   r<   r   rl   ru   rI   r   r   r!   r   r   r   <module>r      s    # " " " " "    				  



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