
    i)                     n   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 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 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&m'Z'm(Z(m)Z)m*Z* dZ+dZ,dZ-dZ.dZ/dZ0de- dZ1dZ2dZ3dZ4ejj                  Z6ejn                  Z8 ejr                  e/e0d      Z! ejr                  de3d      Z: ejr                  de2d      Z; ejr                  d e4d      Z<e!j{                  e"d!e1d       e!j{                  e;       e!j{                  e:       e!j{                  e<       dDd#Z>e&j~                  fd$ee@   d%ee@   d"e
e@e	f   fd&ZAdEd$ee@   d(eBd"e
e@e	f   fd)ZCd*e	d"e	fd+ZDe	 dFdd,ddd-d.eee@ef      d/ee@   d0e@d1eeB   d2eBf
d3       ZEd4eeee@f      d"dfd5ZF	 dGd6e@d"eeGeGf   fd7ZHedHd*e@d8e$d'   d"ee@   fd9       ZIed*e@d8e$d   d"eeG   fd:       ZIdEd*e@d8eBd"eee@   eeG   f   fd;ZIdFd<eGd"dfd=ZJdFd>ed?ee@   d"ee   fd@ZKdIdAeeGeLf   dBeGd"e@fdCZMy)J    N)InterpolationError)contextmanager)Path)AnyDictListOptionalTupleUnionoverload)NoSuchOption)split_arg_string)ConfigValidationErrorrequire_gpu)gpu_is_available)get_command)Printermsg)app   )Literal)ENV_VARSimport_filelogger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rich_markup_mode	benchmarkT)r   r   no_args_is_helpdebuginitprojectreturnc                  x    t         j                  j                          t        t              }  | t
               y )N)	prog_name)r   cliget_allr   r   COMMAND)commands    `/var/www/vps2.regionflexible.com/Desarrollo/venv/lib/python3.12/site-packages/spacy/cli/_util.py	setup_clir.   I   s$    LL#Gg    argsenv_varc                 <   |r t         j                  j                  |d      nd}t        t	        |            }t        | d      }|r*|D cg c]	  }||vs| }}t        j                  d|       |rt        j                  dt        |             i ||S c c}w )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_clizConfig overrides from CLI: %sz'Config overrides from env variables: %s)osenvironget_parse_overridesr   r   r#   list)r0   r1   
env_stringenv_overridescli_overrideskkeyss          r-   parse_config_overridesr?   Q   s     18,RJ$%5j%ABM$T$7M(CaA],BCC4d;>]@ST-m-}--	 Ds   	BBFr4   c                    i }| r| j                  d      }d| d}|j                  d      r|}|j                  dd      }d|vr'|rt        |      t	        j
                  | dd	       d
|v r(|j                  d
d      \  }}|j                  dd      }n*| r| d   j                  d      rd}n| j                  d      }t        |      ||<   nt	        j
                  | dd	       | r|S )Nr   zInvalid config override ''z--r3   .z#: can't override top-level sections   exits=-_truez: name should start with --)pop
startswithreplacer   r   failsplit_parse_override)r0   r4   resultopterrorig_optvalues          r-   r8   r8   g   s    F
hhqk)#a0>>$H++dB'C#~&x00HHu$GHPQRcz YYsA.
Ukk#s+tAw11$7"E HHQKE)%0F3KHHu78B+ , Mr/   rT   c                 b    	 t        j                  |       S # t        $ r t        |       cY S w xY wN)srsly
json_loads
ValueErrorstr)rT   s    r-   rO   rO      s1    && 5zs    ..r3   )titledescshow_config	hint_fill	file_pathr[   r\   r]   r^   c          	   #   v  K   	 d y# t         $ r}||n|j                  }|j                  r |s|j                   n|j                   d| }|j                  |d||      }t	        j
                  |       t        |j                  j                                |rQd|j                  v rC| t        |       dk7  r| nd}t	        j                  dd	
       t        t         d| d| d       t        j                  d       Y d}~yd}~wt        $ r"}t	        j
                  d|d       Y d}~yd}~ww xY 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

r3   )r[   r\   r]   zvalue_error.missingrG   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 
rC   zConfig validation errorrD   )r   r[   r\   
from_errorr   rM   printtextstriperror_typesrZ   r+   sysexitr   )r_   r[   r\   r]   r^   erR   config_paths           r-   show_validation_errorrl      s    "8  *66&*affX166($tf0EDll1BT{lKchhnn.#//A (S^s-B ! 
 HHQ
 WI/}Ak]#NO 8*AQ778s=   D9	 D9	D6C1DD9D6D1,D91D66D9	code_pathc                     | ?t        |       j                         st        j                  d| d       	 t	        d|        yy# t
        $ r%}t        j                  d|  |d       Y d}~yd}~ww xY w)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 foundrC   rD   python_codezCouldn't load Python code: )r   existsr   rM   r   	Exception)rm   rj   s     r-   import_coderr      so     I%%'HH4iqI	Ly1	 
  	LHH29+>KK	Ls   A 	A1A,,A1errorc                    	 t        dd      }|j                  j                         }|r|j	                  d      sy|dd j                         j                  d      }t        |d	         t        |d
         fS #  t        |       xY w)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      NrB   r   rC   )r   RuntimeErrorstdoutrf   rK   rN   int)rs   retrx   versions       r-   get_git_versionr|      s    "/48 ZZF**=9RSk!'',Gwqz?C
O++"5!!s   A; ;Bintifyc                      y rV    rT   r}   s     r-   string_to_listr      s    KNr/   c                      y rV   r   r   s     r-   r   r      s    DGr/   c                    | sg S | j                  d      r| j                  d      r| dd } g }| j                  d      D ]  }|j                         }|j                  d      r|j                  d      r|dd }|j                  d      r|j                  d      r|dd }|j                         }|rt	        |      }|j                  |        |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.
    []rC   ,rA   ")rK   endswithrN   rf   ry   append)rT   r}   rP   ps       r-   r   r      s     	!4aF[[ 	GGI<<C!BA<<C!BAGGIAAa	 Mr/   use_gpuc                     |t               }nt        ||       }| dk\  r |j                  d|         t        |        y|j                  d       t               r|j                  d       yy)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_msgs      r-   	setup_gpur      sb    ~I	VJ?	!|WI./G{#NNKL r/   pathsuffixc                    | j                         s| gS | g}g }t               }|D ]  } t        |       |v r|j                  t        |              | j                  d   j                  d      rJ| j                         r |j                  | j                                z|| j                  d   j                  |      s|j                  |         |j                          |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   rB   )is_dirsetrZ   addpartsrK   extenditerdirr   r   sort)r   r   pathslocsseens        r-   walk_directoryr     s    
 ;;=vFED5D t9T::b>$$S)[[]LL(

2(?(?(GKK 	IIKKr/   numberndigitsc                 H    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)`rB   f)
isinstancefloatrZ   )r   r   s     r-   _format_numberr   '  s+     &% 7)1%&6{r/   )r&   N)FrV   )zNCould not run 'git'. Make sure it's installed and the executable is available.).)r   )Nr5   rh   configparserr   
contextlibr   pathlibr   typingr   r   r   r	   r
   r   r   rW   typerclickr   click.shell_completionr   	thinc.apir   r   
thinc.utilr   
typer.mainr   wasabir   r   weaselr   project_clicompatr   utilr   r   r   r   r   SDIST_SUFFIXWHEEL_SUFFIXPROJECT_FILEr+   NAMEHELPPROJECT_HELP
DEBUG_HELPBENCHMARK_HELP	INIT_HELPArgumentArgOptionOptTyperbenchmark_cli	debug_cliinit_cli	add_typerr.   CONFIG_OVERRIDESrZ   r?   boolr8   rO   rl   rr   ry   r|   r   r   r   r   r   r   r/   r-   <module>r      s9   	 
 + %       3 8 ' "  %   "
::F H

 <J	 nnllekkt$>>SWXEKKW:tL	5;;FDI k	d S i  m  h  /7.G.G.
s).&sm.	#s(^.,49 d tCH~ 6	3 	3 	 ,0(8  "&(8c4i()(8 C=(8 	(8
 $(8 (8 (8V
L8E$)$45 
L$ 
L b,,
38_,& 
 N# Nwu~ NS	 N 
 N 
 G# Gwt} Gc G 
 G# t d3ic>R8S 6Ms MD M x} T
 65e, s 3 r/   