o
    ZhS=                     @  s   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 dejZd$ddZd%ddZd&ddZd'ddZd%ddZd(dd Zd)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                   @  s8   e Zd ZdZedddZejdd	dZdd
dZdS )JupyterParserzA Jupyter argument parser.return
str | Nonec                 C  s   dd t  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)self r   K/var/www/html/lang_env/lib/python3.10/site-packages/jupyter_core/command.pyepilog   s   zJupyterParser.epilogxr   Nonec                 C  s   dS )z$Ignore epilog set in Parser.__init__Nr   )r   r   r   r   r   r   &   s    c                 C  s.   zddl }||  W dS  ty   Y dS w )z#Trigger auto-completion, if enabledr   N)argcompleteautocompleteImportError)r   r   r   r   r   r   *   s   zJupyterParser.argcompleteN)r   r   )r   r   r   r   r   r   )__name__
__module____qualname____doc__propertyr   setterr   r   r   r   r   r
      s    r
   r   c                  C  s   t dd} | jdd}|jdddd |jd	td
dd}dd |_|jdddd |jdddd |jdddd |jdddd | jdddd | j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                  _  s   t  S N)r   )argskwargsr   r   r   <lambda>B   s    z jupyter_parser.<locals>.<lambda>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strZ	completer)parsergroupZsubcommand_actionr   r   r   jupyter_parser4   s,   
r2   	list[str]c               	     s   t  t D ]9} zt| }W n	 ty   Y qw |D ]#}|dr>tjdr0tj	|d }
t|ddd  qqt  }D ] t fddtdt D s`|
d  qEt|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  s     | ]} d | v V  qd S r)   r   ).0iZsub_tupZsubcommand_tuplesr   r   	<genexpr>k   s    z#list_subcommands.<locals>.<genexpr>)set_path_with_selfoslistdirOSError
startswithsysplatformpathsplitextaddtuplesplitanyrangelenr   sorted)dnamesnamesubcommandsr   r9   r   r   R   s(   

"r   cmdr/   argvr   c                 C  s   t jdr9t| }|du rtd|  tjt|g|dd  }ddl}||j	|j
 |  t |j dS t| | dS )zexecvp, except on Windows where it uses Popen

    Python provides execvp on Windows, but its behavior is problematic (Python bug#9148).
    r5   Nz%r not foundr   r   )rA   rB   r@   r   r?   errnoENOENTr   signalSIGINTSIG_IGNwaitexit
returncoder=   execvp)rP   rQ   Zcmd_pathprT   r   r   r   _execvpp   s   r\   r%   c                 C  sf   t jt }d|  }t||d}|du r d| d}t|t |t js1d| d}t||S )z^This method get the abspath of a specified jupyter-subcommand with no
    changes on ENV.
    r4   )rC   Nz
Jupyter command `z` not found.z` is not executable.)r=   pathsepr   r<   r   	ExceptionaccessX_OK)r%   search_pathZjupyter_subcommandabs_pathmsgr   r   r   _jupyter_abspath   s   
rd   c                  C  s   t jdpt jt j} ztd}W n	 ty   Y nw | 	| t
jd g}t|d  r<|	t j|d  |D ]}tt|j}t| rZt |t jrZ| d| q>| 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   )r=   environgetdefpathrG   r]   	sysconfigget_pathKeyErrorappendrA   rQ   r   
is_symlinkrC   realpathr/   parentis_dirr_   r`   insert)	path_listZbindirrf   scriptr   r   r   r<      s    	
r<   r0   c                 C  st   z&ddl m}m} | }|r!t|dkr!|d ds!|  |W S |   W n ty3   |   Y n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   r6   z3Control flow should not reach end of autocomplete())Z#traitlets.config.argcomplete_configru   rv   rJ   r@   r   r   AssertionError)r0   ru   rv   cwordsrc   r   r   r   _evaluate_argcomplete   s   ry   c               
   C  s0  t  } tj}d}dtjv rt| }|d }nt|dkr*|d ds*|d }n||  \}}|j	}|j
rftd dD ]'}z|dkrFt}nt|}|j}W n tyY   d}Y nw t|d	d
| q<dS |jrq|jsqtd |jr||js|td |jr|jrtd |jrtt  dS |jrtt  dS |jrtt  dS |jri }t g|d< t |d< t |d< |jrtt| dS |jrtj}	t rtd ntd t rtd ntd |	drtd ntd |	drtd|	d d ntd |	dr$td|	d d ntd tj r7td t!  d! n
td"t!  d! |	d#rStd$|	d# d% ntd& |	d'ritd(|	d' d) ntd* |	d+rtd,|	d+ d- ntd. t  t"|D ]}
||
 }td/|
  |D ]	}td0|  qqdS |s| j#tj$d1 td2 zt%|}W n- t&y } z | j#tj$d1 |d3krW Y d}~dS tt'| W Y d}~nd}~ww zt(||g|d4d   W dS  t)y } ztd5|d6|  W Y d}~dS d}~ww )7zThe command entry point.NZ_ARGCOMPLETEr   r6   z!Selected Jupyter core packages...)ZIPythonZ	ipykernel
ipywidgetsZjupyter_clientjupyter_coreZjupyter_serverZ
jupyterlabZnbclientZ	nbconvertZnbformatnotebookZ	qtconsoleZ	traitletsr{   znot installedz<17:z --json is only used with --pathsz!--debug is only used with --pathsz"--debug cannot be used with --jsonZ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 configZ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 configZ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 pathsZ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 'Z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 pathsZ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 directoryZ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: )*r2   rA   rQ   r=   rg   ry   rJ   r@   parse_known_argsr%   versionprintr	   
__import__r   jsonr   rX   debugZ
config_dirZjupyter_config_dirdata_dirZjupyter_data_dirZruntime_dirZjupyter_runtime_dirZjupyter_config_pathZjupyter_pathdumpsZuse_platform_dirsZprefer_environment_over_userrh   siteENABLE_USER_SITEgetuserbaserK   
print_helpstderrrd   r^   r/   r\   r?   )r0   rQ   r%   r*   optspackager   modr   envrN   rC   r[   commander   r   r   main   s  



`


$r   __main__)r   r
   )r   r3   )rP   r/   rQ   r3   r   r   )r%   r/   r   r/   )r0   r
   r   r3   r   ) r   
__future__r   argparserR   r   r=   r   rA   rj   pathlibr   shutilr   
subprocessr   typingr    r   r   r	   ArgumentParserr
   r2   r   r\   rd   r<   ry   r   r   r   r   r   r   <module>   s6   





&
 5
