o
    !wi=                     @  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strc                 C  s   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subcommands r   Q/home/ubuntu/sommelier/.venv/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>C   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_argumentr   	completer)parsergroupsubcommand_actionr   r   r   jupyter_parser5   s,   
r4   	list[str]c               	     s   t  t D ]:} z
tt|  }W n	 ty   Y qw |D ]!}|j}|dr?tj	dr1|j
}t|ddd  qqt  }D ] t fddtdt D sa|d  qFt|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  s     | ]} d | v V  qd S r*   r   ).0isub_tupsubcommand_tuplesr   r   	<genexpr>m   s    z#list_subcommands.<locals>.<genexpr>)set_path_with_selflistr   iterdirOSErrorname
startswithsysplatformstemaddtuplesplitanyrangelenr   sorted)d	bin_pathspathrD   r   r   r;   r   r   S   s*   

"r   cmdr   argvr   c                 C  s   t jdr<t| }|du r| d}t|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).
    r7   Nz
 not foundr   r   )rF   rG   rE   r   rC   errnoENOENTr   signalSIGINTSIG_IGNwaitexit
returncodeosexecvp)rS   rT   cmd_pathmsgprW   r   r   r   _execvpr   s   
rb   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.
    r6   )rR   Nz
Jupyter command `z` not found.z` is not executable.)r]   pathsepr   r@   r   	ExceptionaccessX_OK)r&   search_pathjupyter_subcommandabs_pathr`   r   r   r   _jupyter_abspath   s   
rj   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defpathrK   rc   	sysconfigget_pathKeyErrorappendrF   rT   r   
is_symlinkrR   realpathr   parentis_dirre   rf   insert)	path_listbindirrl   scriptr   r   r   r@      s    	
r@   r1   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   r8   z3Control flow should not reach end of autocomplete())#traitlets.config.argcomplete_configr|   r}   rN   rE   r   r   AssertionError)r1   r|   r}   cwordsr`   r   r   r   _evaluate_argcomplete   s   r   c               
   C  s2  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d/|  qqdS |s| j#tj$d0 td1 zt%|}W n- t&y } z | j#tj$d0 |d2krW Y d}~dS tt'| W Y d}~nd}~ww zt(||g|d3d  W dS  t)y } ztd4|d5|  W Y d}~dS d}~ww )6zThe command entry point.N_ARGCOMPLETEr   r8   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: )*r4   rF   rT   r]   rm   r   rN   rE   parse_known_argsr&   versionprintr	   
__import__r   jsonr   r[   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_userrn   siteENABLE_USER_SITEgetuserbaserO   
print_helpstderrrj   rd   r   rb   rC   )r1   rT   r&   r+   _optspackager   modr   envrD   rR   ra   commander   r   r   main   s  



`


$r   __main__)r   r
   )r   r5   )rS   r   rT   r5   r   r   )r&   r   r   r   )r1   r
   r   r5   r   ) r   
__future__r   argparserU   r   r]   r   rF   rp   pathlibr   shutilr   
subprocessr   typingr    r   r   r	   ArgumentParserr
   r4   r   rb   rj   r@   r   r   r   r   r   r   r   <module>   s6   





&
 5
