
    j-                        d dl Zd dlmZmZ d dlmZ d dlZd dlm	Z	m
Z
mZmZmZmZmZmZ d dlmZ d dlmZ defdZd	ed
ej        e         defdZ	 	 	 ddedej        ej        eej        e         f                  dej        ej        ej        e                           dedej        eef         f
dZ	 ddej        dej        ej        e
                  dedej        fdZ  G d dej!                  Z!dS )    N)fieldsis_dataclass)gettext)CliChunkingConfig	CliConfigCliEmbeddingConfigCliPartitionConfigCliPermissionsConfigCliProcessorConfigCliReadConfigCliRetryStrategyConfig)
BaseConfig)loggeroptionsc                     |                                  D ],\  }}t          |t                    rt          |          | |<   -d S N)items
isinstancetuplelist)r   kvs      g/lsinfo/ai/hellotax_ai/base_platform/venv/lib/python3.11/site-packages/unstructured/ingest/cli/utils.pyconform_click_optionsr      sI     ! !1a 	!aGAJ! !    	flat_dataconfigreturnc                     dt           dt          j        t                   ffd | |          }|                    |d          S )ab  
    To be able to extract a nested dataclass from a flat dictionary (as in one coming
    from a click-based options input), the config class is dynamically looked through for
    nested dataclass fields and new nested dictionaries are created to conform to the
    shape the overall class expects whn parsing from a dict. During the process, this will create
    copies of the original dictionary to avoid pruning fields but this isn't a
    problem since the `from_dict()` method ignores unneeded values.

    Not handling more complex edge cases for now such as nested types i.e Union[List[List[...]]]
    inner_dinner_configc           	        
 dt           fd
|                                 }t          |          D ]}|j        }t	          j        |          t          j        u rt	          j        |          }d |D             }
fd|D             }d |D             }d |D             }|ss|r
|j        |v rt          |          dk    rAt          j        d                    |j        d	                    |                               |d
         }t	          j        |          }	|	r|	} 
|t                    r ||          ||j        <   |S )Nr   c                 F    	 t          | |          S # t          $ r Y dS w xY w)NF)
issubclass	Exception)instance
class_types     r   is_subclassz9extract_config.<locals>.conform_dict.<locals>.is_subclass+   s9    !(J777   uus    
  c                 |    g | ]9}t          j        |          t          u rt          j        |          d          n|:S )r   )t
get_originr   get_args).0us     r   
<listcomp>z8extract_config.<locals>.conform_dict.<locals>.<listcomp>8   sI          KLQ4(?(?AJqMM!$$Q     r   c                 F    g | ]} |t          d                     |S r   )type)r-   r   r(   s     r   r/   z8extract_config.<locals>.conform_dict.<locals>.<listcomp><   s5    (c(c(cqTUW[\`WaWaHbHb(c(c(c(cr   c                 0    g | ]}t          |          |S  r   r-   r   s     r   r/   z8extract_config.<locals>.conform_dict.<locals>.<listcomp>=   s$    )^)^)^l[\oo)^!)^)^)^r   c                 0    g | ]}t          |          |S r3   r4   r5   s     r   r/   z8extract_config.<locals>.conform_dict.<locals>.<listcomp>>   s3     . . .LOO.. . .r      zFmore than one dataclass type possible for field {}, not extracting: {}z, r   r    r!   )boolcopyr   r1   r*   r+   Unionr,   namelenr   warningformatjoinr   )r    r!   ddfieldf_typeunion_valuesconcrete_union_valuesdataclass_union_valuesnon_dataclass_union_valuesoriginr(   conform_dicts             @r   rI   z$extract_config.<locals>.conform_dict(   s   	 	 	 	 	 \\^^L)) !	O !	OEZF|F##qw.. z&11   P\      )d(c(c(cL(c(c(c%)^)^5J)^)^)^&. .4. . .* .  . %*2B2B-..22N--3VEJ		J`@a@a-b-b   /2\&))F  {6:.. O!-bv!N!N!N5:	r   r8   F)apply_name_overload)dictr*   Typer   	from_dict)r   r   adjusted_dictrI   s      @r   extract_configrO      sf    ,d ,!&2D , , , , , ,\ !LHHHMMuEEEr   Tdataextrasvalidateadd_defaultsc           
         |r|ng }|rt          | t                    t          | t                    t          | t                    t          | t                    t          | t
                    t          | t                    t          | t                    dni }|r_|                                D ]J\  }}	 t          | |          ||<   # t          $ r#}t          j        d|j                    |d}~ww xY w|D ]>}	 t          | |           # t          $ r}t          d|j                   |d}~ww xY w|S )z
    Extract all common configs used across CLI command and validate that any
    command-specific configs have all their needed information from the Click
    options that are passed in during invocation.
    )r   r   )read_configpartition_configembedding_configchunking_configprocessor_configpermissions_configretry_strategy_configzfailed to extract config from Nzfailed to validate config )rO   r   r	   r   r   r   r
   r   r   r%   r   error__name__)	rP   rQ   rR   rS   resr   confer   s	            r   extract_configsra   Z   s    $+xxH 
	)DOOO .FX Y Y Y .FX Y Y Y-EVWWW .FX Y Y Y"04H\"]"]"]%3dKa%b%b%b	
 	
 	
    ||~~ 	 	GAt'$tDDDA   MdmMMNNN  N N	NT!44444 	N 	N 	NEEEFFAM	N Js0   =C
C?C::C?D
E #D;;E cmdis_srcc                     |r,t           t          t          t          t          t
          t          gng }|                    |           |D ]E}	 |                    |            # t          $ r}t          d|j
         d|           d }~ww xY w| S )N)rb   zfailed to set configs from z: )r	   r   r   r   r   r
   r   extendadd_cli_options
ValueErrorr]   )rb   rQ   rc   configsr   r`   s         r   add_optionsri      s     
	 "	
 	
   MM' S S	S""s"++++ 	S 	S 	SQ6?QQaQQRRR	SJs   A""
B,BBc                   F     e Zd Z fdZdej        dej        ddfdZ xZS )Groupc                     	 t                                          ||          S # t          j        $ r; d|vr | j        D ]	}d|_        
t                                          ||          cY S w xY w)z
        This allows for subcommands to be called with the --help flag without breaking
        if parent command is missing any of its required parameters
        z--helpF)super
parse_argsclickMissingParameterparamsrequired)selfctxargsparam	__class__s       r   rn   zGroup.parse_args   s    		177%%c4000% 	1 	1 	1t##  ' '!&77%%c400000	1s   !% AA/.A/rt   	formatterr   Nc                 p   g }|                      |          D ]:}|                     ||          }||j        r#|                    ||f           ;t	          |          r|j        r%|j        dz
  t          d |D                       z
  }ndt          d |D                       z
  }g }|D ]1\  }}|                    |          }|                    ||f           2|rT|                    t          d                    5  |
                    |           ddd           dS # 1 swxY w Y   dS dS dS )z~
        Copy of the original click.Group format_commands() method but replacing
        'Commands' -> 'Destinations'
        N   c              3   @   K   | ]}t          |d                    V  dS r   Nr=   r-   rb   s     r   	<genexpr>z(Group.format_commands.<locals>.<genexpr>   s,      1R1R##c!f++1R1R1R1R1R1Rr   ic              3   @   K   | ]}t          |d                    V  dS r|   r}   r~   s     r   r   z(Group.format_commands.<locals>.<genexpr>   s,       A ASV A A A A A Ar   Destinations)list_commandsget_commandhiddenappendr=   widthmaxget_short_help_strsection_write_dl)	rs   rt   rx   commands
subcommandrb   limitrowshelps	            r   format_commandszGroup.format_commands   s   
 ,,S11 	/ 	/J""3
33C{z OOZ-.... x== 	- B!!+c1R1R1R1R1R.R.RRS A A A A AAAAD#+ 0 0
C--e44Z.//// -&&q'8'899 - -&&t,,,- - - - - - - - - - - - - - - - - -	- 	-- -s   D''D+.D+)	r]   
__module____qualname__rn   ro   ContextHelpFormatterr   __classcell__)rw   s   @r   rk   rk      sg        1 1 1 1 1"-5= -U=P -UY - - - - - - - -r   rk   )NNT)T)"typingr*   dataclassesr   r   r   r   ro   "unstructured.ingest.cli.interfacesr   r   r   r	   r
   r   r   r   unstructured.ingest.interfacesr   unstructured.ingest.loggerr   rK   r   rL   rO   OptionalDictstrListr9   ra   Commandri   rk   r3   r   r   <module>r      s6       , , , , , , , ,             	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 6 5 5 5 5 5 - - - - - -!4 ! ! ! !;Fd ;FAF:,> ;F: ;F ;F ;F ;F@ ;?7;	& &
&Jqvc16*#5567& jz 234& 	&
 VCO& & & &T KO 	 !qvi'8 9CG
]   40- 0- 0- 0- 0-EK 0- 0- 0- 0- 0-r   