
    Xhi=                       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        yy)zgThe root `jupyter` command.

This does nothing other than dispatch to subcommands or output path info.
    )annotationsN)Path)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j                  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     H/var/www/html/myenv/lib/python3.12/site-packages/jupyter_core/command.pyepilogzJupyterParser.epilog   s#     88$4$67(66    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)returnstr)r   r   r   Noner   r   )__name__
__module____qualname____doc__propertyr   setterr   r   r   r   r   r      s4    $7 7 ]]3 3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>C   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_argumentr   	completer)parsergroupsubcommand_actions      r   jupyter_parserr<   5   s    4F ///?E	L/d   **3c0J +  #M	~lAZ[	|L?VW	|B\]	N  
 <cd
	,=cdMr   c            
     `   t               t               D ]  } 	 t        t        |       j	                               }|D ]w  }|j                  }|j                  d      s!t        j                  j                  d      r|j                  }j                  t        |j                  d      dd              y  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-win-r   Nc              3  ,   K   | ]  }d | v   y wr2   r   ).0isub_tupsubcommand_tupless     r   	<genexpr>z#list_subcommands.<locals>.<genexpr>m   s     T72A;"33Ts   )set_path_with_selflistr   iterdirOSErrorname
startswithsysplatformstemaddtuplesplitanyrangelenr   sorted)d	bin_pathspathrL   r   rD   rE   s        @@r   r   r   S   s     B	T!W__./I  	BD99Dz*<<**5199D!%%eDJJsOAB,?&@A	BB %K$ /TU1c'l=STTOOCHHW-./ +  		s   "D  	D-,D-c                   t         j                  j                  d      rt        |       }|| d}t	        |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
 not foundr   r   )rN   rO   rM   r   rK   errnoENOENTr   signalSIGINTSIG_IGNwaitexit
returncodeosexecvp)cmdargvcmd_pathmsgpr^   s         r   _execvprk   r   s    
 ||u% :G:&C#u||,,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>   )rZ   z
Jupyter command `z` not found.z` is not executable.)rd   pathsepr   rH   r   	ExceptionaccessX_OK)r-   search_pathjupyter_subcommandabs_pathri   s        r   _jupyter_abspathrt      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        |d         j                         r1|j                  t         j                  j                  |d                |D ]q  }t!        t        |      j"                        }t        |      j%                         s;t        j&                  |t         j(                        s`| j+                  d|       s | 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   )rd   environgetdefpathrS   rm   	sysconfigget_pathappendKeyErrorrN   rg   r   
is_symlinkrZ   realpathr   parentis_dirro   rp   insert)	path_listbindirrw   scripts       r   rH   rH      s    '52::<<RZZHI!##I.
 	 xx{mGGAJ""$rww''
34 (T&\(()< 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   rV   rM   r   r   AssertionError)r9   r   r   cwordsri   s        r   _evaluate_argcompleter      s    	

 ()c&kAofQi.B.B3.G ()M
 @C

   	s   ;A A A76A7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
       |D ]  }t        d/|z           , y|s5| jG                  t        jH                  0       t        j"                  d1       	 tK        |      }	 tQ        |g|d3d z          y# t        $ r d}Y Vw xY w# tL        $ rR}| jG                  t        jH                  0       |d2k(  rY d}~yt        j"                  tO        |             Y d}~}d}~ww xY w# tR        $ r%}t        j"                  d4|d5|        Y d}~yd}~ww xY w)6z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    )filez>
Please specify a subcommand or one of the optional arguments.r,      z Error executing Jupyter command z: )*r<   rN   rg   rd   rx   r   rV   rM   parse_known_argsr-   versionprintr
   
__import__r   jsonr	   rb   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   rn   r   rk   rK   )r9   rg   r-   r3   optspackager   modr   envrL   rZ   rj   commandes                  r   mainr      sI   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TF!*%! *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])rf   r   rg   r   r   r   )r-   r   r   r   )r9   r   r   r   r    ) r$   
__future__r   argparser\   r   rd   r   rN   r{   pathlibr   shutilr   
subprocessr   typingr    r	   r   r
   ArgumentParserr   r<   r   rk   rt   rH   r   r   r!   r   r   r   <module>r      s    #    	  
        H++ 4<>0(#L>qIh zF r   