
    rh*.                        U 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 g Zee   ed	<   d
ee   fdZ e	de      dee   ded
efd       Z e	de      dedededeeeeef      fd       Z dee   de!e   d
e!e   fdZ"ded
efdZ#ded
efdZ$ded
ee%eee   f   e%eef   e!e   e%eee   f   f   fdZ&de!e   d
ee%eee   f   e%eef   e!e   e%eee   f   f   fd Z'd;ded!ed
ee   fd"Z(ded
ee   fd#Z)	 d<deeee   f   de!e   d$e!e   d%ed&e%eef   d'ed
ee   fd(Z*d)Z+eed*<   d+d,hZ,e!e   ed-<    e!       Z-e!e   ed.<   d/d/d0Z.e%eef   ed1<   d2Z/eed3<   d+d,hZ0e!e   ed4<    e!       Z1e!e   ed5<   d6d7iZ2e%eef   ed8<   d=d9Z3e4d:k(  r e3        yy# e$ r d dlZ ee      j#                         j$                  d   Zej(                  j+                  d  ee             d dl
mZ d dlmZ  eej(                        d kD  r%ej(                  d     ee      k(  rej(                  d = Y w xY w)>    N)defaultdict)Path)AnyUnion)
deprecated)format_function_signature)FileManager   __all__returnc                      g S N r       u/var/www/html/ai-insurance-compliance-backend/venv/lib/python3.12/site-packages/torch/utils/data/datapipes/gen_pyi.py__dir__r      s    Ir   zg`torch.utils.data.datapipes.gen_pyi.materialize_lines` is deprecated and will be removed in the future.)categorylinesindentationc                 ~    d}dd|z  z   }t        |       D ]$  \  }}|dk7  r||z  }||j                  d|      z  }& |S )N 
 r   )	enumeratereplace)r   r   outputnew_line_with_indentilines         r   materialize_linesr        s`    
 F#"33U# ;46**F$,,t%9::; Mr   zg`torch.utils.data.datapipes.gen_pyi.gen_from_template` is deprecated and will be removed in the future.dirtemplate_nameoutput_namereplacementsc           	         t         j                  j                  | |      }t         j                  j                  | |      }t        |d      5 }|j	                         }d d d        |D ]J  \  }}	}
t        |dd      5 }j                  |t        |	|
            }|j                  |       d d d        L y # 1 sw Y   YxY w# 1 sw Y   cxY w)Nutf-8encodingw)ospathjoinopenreadr   r    write)r!   r"   r#   r$   template_pathoutput_pathfcontentplaceholderr   r   s              r   gen_from_templater5   .   s     GGLLm4M'',,sK0K	mg	. !&&(+7 'UK+sW5 	oo.ukBG GGG		 	 	 	s   B7>.C7C C		dir_pathsfiles_to_excludec           
      B   t               }| D ]  }t        j                  |      }|D ch c]  }d|dd k(  s| }}|D ch c]	  }||vs| }}|j                  |D ch c]"  }t        j                  j                  ||      $ c}        |S c c}w c c}w c c}w )z
    When given a path to a directory, returns the paths to the relevant files within it.

    This function does NOT recursive traverse to subdirectories.
    z.pyN)setr*   listdirupdater+   r,   )r6   r7   pathsdir_path	all_filesfnamepython_filesfilter_filess           r   find_file_pathsrC   E   s     eE PJJx(	+4L%rs8KLL+
u<L/LE
 
 	Nbggll8U3NOP L M
 Os   BB	BB 'B
r   c                     d| v rd\  }}nd| v rd\  }}nt        d|        | j                  |      t        |      z   | j                  |      }}| || S )zXExtract method name from decorator in the form of "@functional_datapipe({method_name})".(")rE   z")(')rF   z')z4Unable to find appropriate method name within line:
)RuntimeErrorfindlenr   start_token	end_tokenstartends        r   extract_method_namerO   V   sn    t|!+Y	!+YCD6J
 	
 ;'#k*::DIIi<P3Ec?r   c                 p    d}d}| j                  |      t        |      z   | j                  |      }}| || S )zVExtract class name from class definition in the form of "class {CLASS_NAME}({Type}):".class ()rH   rI   rJ   s        r   extract_class_namerS   d   s=    KI;'#k*::DIIi<P3Ec?r   	file_pathc                    i i t               }}}t        t              }t        | d      5 }d}d\  }}}	d}
|D ]/  }|j	                  d      dz  dk(  r|
 }
|
sd|v r||   j                  |       9d	|v rt        |      }g ||<   N|rd
|v rt        |      }`|rDd|v sd|v r<d|v r|j                  |       |dz  }|j                  d      t        d      z   }||d }|dkD  s||j	                  d      z  }||j	                  d      z  }|dk(  r4|j                  d      }|	|d| z  }	t        |	      ||<   |||<   d\  }}}	|dk  rt        d      |	|j                         z  }	2 	 ddd       ||||fS # 1 sw Y   xY w)zfGiven a path to file, parses the file and returns a dictionary of method names to function signatures.r&   r'   r   )r   r   r   Fz"""      z@functional_datapiperQ   zdef __init__(zdef __new__(rR   N)z7open parenthesis count < 0. This shouldn't be possible.)r:   r   listr-   countappendrO   rS   addrH   rI   rfindprocess_signaturerG   strip)rT   method_to_signaturemethod_to_class_namespecial_output_typedoc_string_dictr2   open_paren_countmethod_name
class_name	signatureskipr   rM   rN   s                 r   parse_datapipe_fileri   l   s    FHSU/B-!$'O	i'	* %.a-7*Z !	.Dzz% 1$)xu},33D9%-1$7/1,x4//5
4 7>T;Q!T)'++K8 A% 		#S1EF|!# DJJsO3  DJJsO3 #q(**S/Cds+I7H7S'48B(59C6KY%)&Q  -IC!	.	%.N 		 M%. %.s   B8E:$BE::F
file_pathsc                     i }i }t               }i }| D ]V  }t        |      \  }}}}	|j                  |       |j                  |       |j                  |       |j                  |	       X ||||fS r   )r:   ri   r<   )
rj   methods_and_signaturesmethods_and_class_names!methods_with_special_output_typesmethods_and_doc_stringsr+   r`   ra   $methods_needing_special_output_typesrc   s
             r   parse_datapipe_filesrq      s       (+%  
8  %	
 0%%&9:&&';<)001UV&&7
8 	)	 r   	delimiterc                     d}d}g }| D ];  }|dk(  r|dz  }n)|dk(  r|dz  }n||k(  r|dk(  r|j                  |       d}7||z  }= |j                  |       |S )zRGiven a line of text, split it on comma unless the comma is within a bracket '[]'.r   r   [rW   ])r[   )r   rr   bracket_count
curr_tokenreschars         r   split_outside_bracketrz      s    MJ
C 	3;QMS[QMY=A#5JJz"Jd
	 JJzJr   c                 V   t        |       }t        |      D ]u  \  }}|j                  d      ||<   |dk(  rd||<   %|dkD  rd||dz
     k(  r||   d   dk7  rd||<   Fd|v sK|j                  d	      d   }|j                  d      d
z   ||<   w |D cg c]
  }|dk7  s	| }}|S c c}w )z
    Clean up a given raw function signature.

    This includes removing the self-referential datapipe argument, default
    arguments of input functions, newlines, and spaces.
    r   clsselfr   rW   *r   z
Callable ==z = ...)rz   r   r_   
rpartition)r   tokensr   tokenheadts         r   r^   r^      s     .d3Ff% 	35KK$q	E>F1IU&Q-/fQilc6IF1IU"##C(+D

3(2F1I	3  +A17a+F+M ,s   
B&B&deprecated_filesdefault_output_typemethod_to_special_output_typerootc                    |dk(  r0t        t        t              j                  j	                               }t        | t               r| gn| } | D cg c]"  }t        j                  j                  ||      $ } }t        | |j                  |            }t        |      \  }}	}
}|D ]  }||
vs|
j                  |        g }|j                         D ]|  \  }}|	|   }||
v r||   }n|}dj                  ||         }|dk(  rd}nd|z   }t        |||      }|j                  d| d|j!                  d      j#                         z   |z          ~ |j%                  d 	       |S c c}w )
a  
    #.pyi generation for functional DataPipes Process.

    # 1. Find files that we want to process (exclude the ones who don't)
    # 2. Parse method name and signature
    # 3. Remove first argument after self (unless it is "*datapipes"), default args, and spaces
    r   )r7   z ...r   z# Functional form of 'z'
z...c                 *    | j                  d      d   S )Nr   rW   )split)ss    r   <lambda>z(get_method_definitions.<locals>.<lambda>  s    aggdmA& r   )key)strr   __file__parentresolve
isinstancer*   r+   r,   rC   unionrq   r\   itemsr   r[   removesuffixrstripsort)rT   r7   r   r   r   r   r+   rj   rl   rm   methods_w_special_output_typesro   fn_namemethod_definitionsre   	argumentsrf   output_type
doc_string
definitions                       r   get_method_definitionsr      s    rz4>((0023))S9yI6?@ddD)@I@ $4$:$:;K$LJ 	Z(& 1 888*..w78 "8">">"@ 
Y,[9
887DK-KWW4[AB
J
*J.{I{S
!!$ZL4%%e,3356	

" &   K As   'E'iteriterDP_file_pathz__init__.pyzutils.pyiterDP_files_to_excludeiterDP_deprecated_fileszlist[IterDataPipe])demuxfork$iterDP_method_to_special_output_typemapmapDP_file_pathmapDP_files_to_excludemapDP_deprecated_filesshuffleIterDataPipe#mapDP_method_to_special_output_typec                     t        t        t        t        dt              t        t
        t        t        dt              t        t              j                         j                  } t        | | d      }|j                  ddfd       y)	a  
    # Inject file into template datapipe.pyi.in.

    TODO: The current implementation of this script only generates interfaces for built-in methods. To generate
          interface for user-defined DataPipes, consider changing `IterDataPipe.register_datapipe_as_function`.
    r   MapDataPipeF)install_dirtemplate_dirdry_runzdatapipe.pyizdatapipe.pyi.inc                       dS )N)IterDataPipeMethodsMapDataPipeMethodsr   )iter_method_definitionsmap_method_definitionss   r   r   zmain.<locals>.<lambda>H  s    #:"8
 r   N)r   r   r   r   r   r   r   r   r   r   r   absoluter   r	   write_with_template)r+   fmr   r   s     @@r   mainr   ,  s|     5, 4+ >""$++D	D%	HB	
r   __main__),)r   )r   N)5r*   collectionsr   pathlibr   typingr   r   typing_extensionsr   torchgen.api.pythonr   torchgen.utilsr	   ImportErrorsysr   r   parents	REPO_ROOTr+   insertr   rI   r   rY   __annotations__r   FutureWarningintr    tupler5   r:   rC   rO   rS   dictri   rq   rz   r^   r   r   r   r   r   r   r   r   r   r   __name__r   r   r   <module>r      s   	 #   (=9 c c  mT#Y S S 	 m	  uS#s]+,		&tCy CH S "c c S S 11
4T#Yc3hS4T#Y;OOP1hC
4T#Yc3hS4T#Y;OOP4  d3i &C DI 8 7S$s)^$7#h7 #h7 	7
 $(S>7 7 
#Y7v  # %2J$? S ?$'E S )! 8 $d38n 
  $1:#> C >#&5 C (7@.6Q #T#s(^ Q F zF G
  
X'')11!4IHHOOAs9~&=*
388}qSXXa[C	N:HHQK
s   F& &BH>=H>