o
    i<                     @   s   d 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
 d
ejZdefddZdee fddZdd Zdd Zdd Zdedee fddZdddZedkrze  dS dS )zgThe root `jupyter` command.

This does nothing other than dispatch to subcommands or output path info.
    N)which)Popen)List   )paths)__version__c                   @   s2   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.c                 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   O/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/jupyter_core/command.pyepilog   s   zJupyterParser.epilogc                 C   s   dS )z$Ignore epilog set in Parser.__init__Nr   )r   xr   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)__name__
__module____qualname____doc__propertyr   setterr   r   r   r   r   r      s    

r   returnc                  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>A   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str	completer)parsergroupsubcommand_actionr   r   r   jupyter_parser3   s,   
r/   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sub_tupsubcommand_tuplesr   r   	<genexpr>j   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   r5   r   r   Q   s(   

"r   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).
    r1   Nz%r not foundr   r   )r?   r@   r>   r   r=   errnoENOENTr   signalSIGINTSIG_IGNwaitexit
returncoder;   execvp)cmdargvcmd_pathprP   r   r   r   _execvpo   s   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.
    r0   )rA   Nz
Jupyter command `z` not found.z` is not executable.)r;   pathsepr
   r:   r   	ExceptionaccessX_OK)r    search_path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 j|d r<|	t j|d  |D ]}t j|}t j|rYt |t jrY| 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defpathrE   r\   	sysconfigget_pathKeyErrorappendr?   rX   rA   islinkrealpathdirnameisdirr^   r_   insert)	path_listbindirrf   scriptr   r   r   r:      s    	
r:   r,   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   r2   z3Control flow should not reach end of autocomplete())#traitlets.config.argcomplete_configrv   rw   rH   r>   r   r   AssertionError)r,   rv   rw   cwordsrc   r   r   r   _evaluate_argcomplete   s   r{   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.N_ARGCOMPLETEr   r2   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/   r?   rX   r;   rg   r{   rH   r>   parse_known_argsr    versionprintr   
__import__r   jsonr   rT   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_userrh   siteENABLE_USER_SITEgetuserbaserI   
print_helpstderrrd   r]   r*   r[   r=   )r,   rX   r    r%   optspackager   modr   envrL   rA   rZ   commander   r   r   main   s  



`


$r   __main__)r   N)r   argparserN   r   r;   r   r?   rj   shutilr   
subprocessr   typingr    r   r   r   ArgumentParserr   r/   r*   r   r[   rd   r:   r{   r   r   r   r   r   r   <module>   s2   &
  5
