o
    in*                     @   s  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mZmZmZmZmZmZmZmZ d dlZd dlZd dlmZ d dlmZ d dlmZmZmZ d d	lmZ d d
l m!Z! d dl"m#Z#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/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6 dZ7dZ8dZ9dZ:dZ;dZ<de9 dZ=dZ>dZ?dZ@ejAZBejCZDejEe;e<dZ&ejEde?dd ZFejEd!e>dd ZGejEd"e@dd ZHe&jIe'd#e=dd  e&IeG e&IeF e&IeH dSd%d&ZJe/jKfd'eeL d(eeL d$eeLef fd)d*ZMdTd'eeL d,eNd$eeLef fd-d.ZOd/ed$efd0d1ZPe	dUdd2ddd3d4eeeLe	f  d5eeL d6eLd7eeN d8eNf
d9d:ZQd;eee	eLf  d$dfd<d=ZR	>dVd?eLd$eeSeSf fd@dAZTedWd/eLdCe+d+ d$eeL fdDdEZUed/eLdCe+d d$eeS fdFdEZUdTd/eLdCeNd$eeeL eeS f fdGdEZUdUdHeSd$dfdIdJZVdUdKe	dLeeL d$ee	 fdMdNZWdXdOeeSeXf dPeSd$eLfdQdRZYdS )Y    N)InterpolationError)contextmanager)Path)	TYPE_CHECKINGAnyDictIterableListOptionalTupleUnionoverload)NoSuchOption)split_arg_string)ConfigConfigValidationErrorrequire_gpu)gpu_is_available)get_command)Printermsg)app   )about)Literal)validate)ENV_VARSSimpleFrozenDictimport_fileis_compatible_versionloggermake_tempdirregistryrun_commandz.tar.gzz-py3-none-any.whlzproject.ymlzpython -m spacyspacyz=spaCy Command-line Interface

DOCS: https://spacy.io/api/cli
zCommand-line interface for spaCy projects and templates.
You'd typically start by cloning a project template to a local directory and
fetching its assets like datasets etc. See the project's z for the
available commands.
zSuite of helpful commands for debugging and profiling. Includes
commands to check and validate your config files, training and evaluation data,
and custom model implementations.
z$Commands for benchmarking pipelines.z8Commands for initializing configs and pipeline packages.)namehelp	benchmarkT)r%   r&   no_args_is_helpdebuginitprojectreturnc                  C   s    t j  tt} | td d S )N)	prog_name)r"   cliget_allr   r   COMMAND)command r2   C/home/ubuntu/.local/lib/python3.10/site-packages/spacy/cli/_util.py	setup_cliR   s   
r4   argsenv_varc                    sp   |r	t j|dnd}tt| t| dd}|r( fdd|D }td|  r2tdt  i | S )a  Generate a dictionary of config overrides based on the extra arguments
    provided on the CLI, e.g. --training.batch_size to override
    "training.batch_size". Arguments without a "." are considered invalid,
    since the config only allows top-level sections to exist.

    env_vars (Optional[str]): Optional environment variable to read from.
    RETURNS (Dict[str, Any]): The parsed dict, keyed by nested config setting.
     T)is_clic                    s   g | ]}| vr|qS r2   r2   ).0kenv_overridesr2   r3   
<listcomp>i   s    z*parse_config_overrides.<locals>.<listcomp>zConfig overrides from CLI: %sz'Config overrides from env variables: %s)osenvironget_parse_overridesr   r    r)   list)r5   r6   
env_stringcli_overrideskeysr2   r;   r3   parse_config_overridesZ   s   rF   Fr8   c                 C   s   i }| rg|  d}d| d}|dr[|}|dd}d|vr0|r&t|tj| ddd	 d
|v rC|d
d\}}|dd}n| rL| d drOd}n|  d}t|||< n
tj| ddd	 | s|S )Nr   zInvalid config override ''z--r7   .z#: can't override top-level sections   exits=-_truez: name should start with --)pop
startswithreplacer   r   failsplit_parse_override)r5   r8   resultopterrorig_optvaluer2   r2   r3   rA   p   s*   


rA   rZ   c                 C   s(   zt | W S  ty   t|  Y S w N)srsly
json_loads
ValueErrorstr)rZ   r2   r2   r3   rU      s
   rU   r7   )titledescshow_config	hint_fill	file_pathr`   ra   rb   rc   c             
   c   s$   zdV  W dS  t yw } zd|dur|n|j}|jr)|s!|j n|j d| }|j|d||d}t| t|j  |rgd|j	v rg| durQt
| dkrQ| nd}tjdd	d
 tt d| d| d td W Y d}~dS d}~w ty } ztjd|dd W Y d}~dS d}~ww )a  Helper to show custom config validation errors on the CLI.

    file_path (str / Path): Optional file path of config file, used in hints.
    title (str): Override title of custom formatted error.
    desc (str): Override description of custom formatted error.
    show_config (bool): Whether to output the config the error refers to.
    hint_fill (bool): Show hint about filling config.
    Nz

r7   )r`   ra   rb   zvalue_error.missingrM   z
config.cfgz|If your config contains missing values, you can run the 'init fill-config' command to fill in all the defaults, if possible:T)spacedz init fill-config  z 
rI   zConfig validation errorrJ   )r   r`   ra   
from_errorr   rS   printtextstriperror_typesr_   r0   sysexitr   )rd   r`   ra   rb   rc   erX   config_pathr2   r2   r3   show_validation_error   s4   
rp   	code_pathc              
   C   sv   | dur9t |  stjd| dd ztd|  W dS  ty8 } ztjd|  |dd W Y d}~dS d}~ww dS )zHelper to import Python file provided in training commands / commands
    using the config. This makes custom registered functions available.
    NzPath to Python code not foundrI   rJ   python_codezCouldn't load Python code: )r   existsr   rS   r   	Exception)rq   rn   r2   r2   r3   import_code   s   $ru   NCould not run 'git'. Make sure it's installed and the executable is available.errorc                 C   sj   zt ddd}W n   t| |j }|r|dsdS |dd  d}t|d	 t|d
 fS )a   Get the version of git and raise an error if calling 'git --version' fails.
    error (str): The error message to show.
    RETURNS (Tuple[int, int]): The version as a (major, minor) tuple. Returns
        (0, 0) if the version couldn't be determined.
    zgit --versionT)capturezgit version)r   r      NrH   r   rI   )r#   RuntimeErrorstdoutrj   rQ   rT   int)rw   retr{   versionr2   r2   r3   get_git_version   s   
r   .intifyc                 C      d S r[   r2   rZ   r   r2   r2   r3   string_to_list      r   c                 C   r   r[   r2   r   r2   r2   r3   r      r   c                 C   s   | sg S |  dr| dr| dd } g }| dD ]5}| }| dr1|dr1|dd }| drA|drA|dd }| }|rKt|}|| q|S )aS  Parse a comma-separated string to a list and account for various
    formatting options. Mostly used to handle CLI arguments that take a list of
    comma-separated values.

    value (str): The value to parse.
    intify (bool): Whether to convert values to ints.
    RETURNS (Union[List[str], List[int]]): A list of strings or ints.
    []rI   ,rG   ")rQ   endswithrT   rj   r|   append)rZ   r   rV   pr2   r2   r3   r      s    	use_gpuc                 C   sd   |du rt  }nt || d}| dkr!|d|   t|  dS |d t r0|d dS dS )zConfigure the GPU and log info.N)no_printprettyr   zUsing GPU: z	Using CPUz.To switch to GPU 0, use the option: --gpu-id 0)r   infor   r   )r   silent	local_msgr2   r2   r3   	setup_gpu  s   
r   pathsuffixc                 C   s   |   s| gS | g}g }t }|D ]7} t| |v rq|t|  | jd dr*q|   r6||   q|durC| jd |sCq|	|  q|
  |S )a  Given a directory and a suffix, recursively find all files matching the suffix.
    Directories or files with names beginning with a . are ignored, but hidden flags on
    filesystems are not checked.
    When provided with a suffix `None`, there is no suffix-based filtering.r   rH   N)is_dirsetr_   addpartsrQ   extenditerdirr   r   sort)r   r   pathslocsseenr2   r2   r3   walk_directory  s$   r   numberndigitsc                 C   s"   t | tr| d| dS t| S )zFormats a number (float or int) rounding to `ndigits`, without truncating trailing 0s,
    as happens with `round(number, ndigits)`rH   f)
isinstancefloatr_   )r   r   r2   r2   r3   _format_number0  s   
r   )r,   N)Fr[   )rv   ).)r   )Zhashlibr>   shutilrl   configparserr   
contextlibr   pathlibr   typingr   r   r   r   r	   r
   r   r   r   r\   typerclickr   click.shell_completionr   	thinc.apir   r   r   
thinc.utilr   
typer.mainr   wasabir   r   weaselr   project_clir7   r   compatr   schemasr   utilr   r   r   r   r    r!   r"   r#   SDIST_SUFFIXWHEEL_SUFFIXPROJECT_FILEr0   NAMEHELPPROJECT_HELP
DEBUG_HELPBENCHMARK_HELP	INIT_HELPArgumentArgOptionOptTyperbenchmark_cli	debug_cliinit_cli	add_typerr4   CONFIG_OVERRIDESr_   rF   boolrA   rU   rp   ru   r|   r   r   r   r   r   r   r2   r2   r2   r3   <module>   s    ,(



	

$+

" ( $