o
    i                     @   s  d dl mZ d dlmZmZmZmZm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mZ dd
lmZ ddlmZmZmZmZmZmZ ejdddddedddddeddddddedddddedddddfd ejd!ed"ee d#ed$ef
d%d&Z i ddd'd!ed(ee!ef d#ed$efd)d*Z"de
d+eee!eee!e#f  f  fd,d-Z$de
d+ee!ef fd.d/Z%dS )0    )Path)AnyDictListOptionalUnionN)Config)VARIABLE_RE)msgtable   )util)ConfigSchemaInitConfigSchemaTraining)registry   )ArgOpt	debug_cliimport_codeparse_config_overridesshow_validation_errorconfigT)allow_extra_argsignore_unknown_options)context_settings.zPath to config file)helpexists
allow_dashz--code-pathz--codez-czNPath to Python file with additional code (registered functions) to be imported)r   Fz--show-functionsz-FznShow an overview of all registered functions used in the config and where they come from (modules, files etc.)z--show-variablesz-VzShow an overview of all variables referenced in the config and their values. This will also reflect variables overwritten on the CLI.ctxconfig_path	code_path
show_funcs	show_varsc                 C   s&   t | j}t| t||||d dS )a  Debug a config file and show validation errors. The command will
    create all objects in the tree and validate them. Note that some config
    validation errors are blocking and will prevent the rest of the config from
    being resolved. This means that you may not see all validation errors at
    once and some issues are only shown once previous errors have been fixed.
    Similar as with the 'train' command, you can override settings from the config
    as command line options. For instance, --training.batch_size 128 overrides
    the value of "batch_size" in the block "[training]".

    DOCS: https://spacy.io/api/cli#debug-config
    	overridesr"   r#   N)r   argsr   debug_config)r   r    r!   r"   r#   r%    r(   J/home/ubuntu/.local/lib/python3.10/site-packages/spacy/cli/debug_config.pydebug_config_cli   s
   

r*   r$   r%   c                C   s  t d t|  tj| |d}t|}|j }W d    n1 s%w   Y  t d t|  tj	|d t
d}W d    n1 sGw   Y  t d t|  tj	|d td}|d |d	 g}t|| W d    n1 sww   Y  t d
 |rt|}t dt| d d}	t j||	dddd |rt|}
t dt|
 d |
D ]1}d|d  |d |d |d  d|d  dd}t d|d  d tt|  qd S d S )NzConfig validation)r%   z"Config validation for [initialize]
initialize)schemaz Config validation for [training]trainingtrain_corpus
dev_corpuszConfig is validzVariables ())VariableValueT))   "   r   )headerdividerwidthsspacingzRegistered functions (@r   namemodulefilez (line line_no)RegistryNameModuleFile[path])r
   r6   r   r   load_configload_model_from_configr   interpolater   resolver   r   resolve_dot_namesgoodget_variableslenr   get_registered_funcsinfoprintstrip)r    r%   r"   r#   r   nlpT	dot_names	variablesheadfuncsfunc	func_datar(   r(   r)   r'   5   sF   







r'   returnc                 C   sz   g }t | D ]3\}}|d dsq|d dd  }tt j|}d|d d }||}||||d| q|S )Nr9   r   .)r:   r   rC   )r   	walk_dict
startswithgetattrr   joinfindappend)r   resultkeyvaluereg_namer   rC   rN   r(   r(   r)   rM   ]   s   
rM   c                 C   sP   i }t tt|  D ]}|dd dd}t| |}t|||< q|S )Nr   rZ   :r[   )	sortedsetr	   findallto_strreplacer   dot_to_objectrepr)r   rb   variablerC   rd   r(   r(   r)   rK   k   s   rK   )&pathlibr   typingr   r   r   r   r   typer	thinc.apir   thinc.configr	   wasabir
   r    r   schemasr   r   r   _utilr   r   r   r   r   r   commandContextboolr*   strr'   intrM   rK   r(   r(   r(   r)   <module>   sV     


*(