
    ΅i.                        % S SK r S SKJr  S SKJr  S SKJr  S SKJr   S SK	J
r
  S SKJr  / r\\   \S	'   S
\\   4S jr\" S\S9S\\   S\S
\4S j5       r\" S\S9S\S\S\S\\\\\4      S
S4
S j5       rS\\   S\ \   S
\ \   4S jr!S\S
\4S jr"S\S
\4S jr#S\S
\\$\\\   4   \$\\4   \ \   \$\\\   4   4   4S jr%S\ \   S
\\$\\\   4   \$\\4   \ \   \$\\\   4   4   4S  jr&S;S\S!\S
\\   4S" jjr'S\S
\\   4S# jr( S<S\\\   -  S\ \   S$\ \   S%\S&\$\\4   S'\S
\\   4S( jjr)S)r*\\S*'   S+S,1r+\ \   \S-'   \ " 5       r,\ \   \S.'   S/S/S0.r-\$\\4   \S1'   S2r.\\S3'   S+S,1r/\ \   \S4'   \ " 5       r0\ \   \S5'   S6S70r1\$\\4   \S8'   S=S9 jr2\3S::X  a  \2" 5         gg! \ a    S SKr\" \5      R!                  5       R"                  S   r\R&                  R)                  S \" \5      5        S SK	J
r
  S SKJr  \" \R&                  5      S :  a&  \R&                  S    \" \5      :X  a  \R&                  S 	  GNf = f)>    N)defaultdict)Path)Any)
deprecated)format_function_signature)FileManager   __all__returnc                      / $ N r       \/home/james-whalen/.local/lib/python3.13/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                 ~    SnSSU-  -   n[        U 5       H#  u  pEUS:w  a  X#-  nX%R                  SU5      -  nM%     U$ )N 
 r   )	enumeratereplace)r   r   outputnew_line_with_indentilines         r   materialize_linesr       sT    
 F#"33U#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           	         [         R                  R                  X5      n[         R                  R                  X5      n[        USS9 nUR	                  5       nS S S 5        U HF  u  pn
[        USSS9 nWR                  U[        X5      5      nUR                  U5        S S S 5        MH     g ! , (       d  f       N[= f! , (       d  f       Mk  = f)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_templater4   .   s     GGLL4M'',,s0K	mg	.!&&( 
/+7'K+sW5oo.uBG GGG	 65 ,8 
/	. 65s   	B/5-C /
B= 
C		dir_pathsfiles_to_excludec           
      `   [        5       nU  H  n[        R                  " U5      nU Vs1 s H  nSUSS :X  d  M  UiM     nnU Vs1 s H  oUU;  d  M
  UiM     nnUR                  U Vs1 s H"  n[        R                  R                  X55      iM$     sn5        M     U$ s  snf s  snf s  snf )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+   )r5   r6   pathsdir_path	all_filesfnamepython_filesfilter_filess           r   find_file_pathsrB   E   s     eEJJx(	+4L9%rs8K9L+
+e<L/LE| 	 
 	Nbggll83NO  L M
 Os   B!B!	B&B&+)B+
r   c                     SU ;   a  Su  pOSU ;   a  Su  pO[        SU  35      eU R                  U5      [        U5      -   U R                  U5      pCXU $ )zXExtract method name from decorator in the form of "@functional_datapipe({method_name})".(")rD   z")(')rE   z')z4Unable to find appropriate method name within line:
)RuntimeErrorfindlenr   start_token	end_tokenstartends        r   extract_method_namerN   V   sj    t|!+Y	!+YCD6J
 	
 ;'#k*::DIIi<P3c?r   c                 l    SnSnU R                  U5      [        U5      -   U R                  U5      pCXU $ )zVExtract class name from class definition in the form of "class {CLASS_NAME}({Type}):".class ()rG   rH   rI   s        r   extract_class_namerR   d   s9    KI;'#k*::DIIi<P3c?r   	file_pathc                 J   0 0 [        5       p2n[        [        5      n[        U SS9 nSnSu  pxn	Sn
U GHN  nUR	                  S5      S-  S:X  a  U
(       + n
U
(       d  SU;   a  XG   R                  U5        ME  S	U;   a  [        U5      n/ XG'   M\  U(       a  S
U;   a  [        U5      nMv  U(       aI  SU;   d  SU;   a=  SU;   a  UR                  U5        US-  nUR                  S5      [        S5      -   nXS nUS:  d  M  XkR	                  S5      -  nXkR	                  S5      -  nUS:X  a1  UR                  S5      nXSU -  n	[        U	5      X'   XU'   Su  pxn	GM+  US:  a  [        S5      eXR                  5       -  n	GMQ     SSS5        UUUU4$ ! , (       d  f       N= f)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_datapiperP   zdef __init__(zdef __new__(rQ   N)z7open parenthesis count < 0. This shouldn't be possible.)r9   r   listr,   countappendrN   rR   addrG   rH   rfindprocess_signaturerF   strip)rS   method_to_signaturemethod_to_class_namespecial_output_typedoc_string_dictr1   open_paren_countmethod_name
class_name	signatureskipr   rL   rM   s                 r   parse_datapipe_filerh   l   s    FHSU/B!$'O	i'	*a-7*Dzz% 1$)xu},33D9%-1$7/1,x4//5
4 7>T;Q!T)'++K8 A% 		#S1F|!# JJsO3  JJsO3 #q(**S/Cds+I7H7S'48B59C6KY%)&Q  -IC 	 
+N 		 M 
+	*s   CFBF
F"
file_pathsc                     0 n0 n[        5       n0 nU  HW  n[        U5      u  nnnn	UR                  U5        UR                  U5        UR                  U5        UR                  U	5        MY     UUUU4$ r   )r9   rh   r;   )
ri   methods_and_signaturesmethods_and_class_names!methods_with_special_output_typesmethods_and_doc_stringsr*   r_   r`   $methods_needing_special_output_typesrb   s
             r   parse_datapipe_filesrp      s       (+%   %	
 0%%&9:&&';<)001UV&&7  	)	 r   	delimiterc                     SnSn/ nU  H?  nUS:X  a  US-  nO,US:X  a  US-  nO XQ:X  a  US:X  a  UR                  U5        SnM;  X5-  nMA     UR                  U5        U$ )zRGiven a line of text, split it on comma unless the comma is within a bracket '[]'.r   r   [rV   ])rZ   )r   rq   bracket_count
curr_tokenreschars         r   split_outside_bracketry      sy    MJ
C3;QMS[QM=A#5JJz"J
  JJzJr   c                 f   [        U 5      n[        U5       Hx  u  p#UR                  S5      X'   US:X  a  SX'   M$  US:  a  SXS-
     :X  a  X   S   S:w  a  SX'   MF  SU;   d  MN  UR                  S	5      S   nUR                  S5      S
-   X'   Mz     U Vs/ s H  oUS:w  d  M
  UPM     nnU$ s  snf )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   rV   *r   z
Callable ==z = ...)ry   r   r^   
rpartition)r   tokensr   tokenheadts         r   r]   r]      s     .d3Ff%KK$	E>FIU&Q-/filc6IFIU"##C(+D

3(2FI &  +A7aF+M ,s   	B.$B.deprecated_filesdefault_output_typemethod_to_special_output_typerootc                    US:X  a0  [        [        [        5      R                  R	                  5       5      n[        U [         5      (       a  U /OU n U  Vs/ s H"  n[        R                  R                  XV5      PM$     n n[        XR                  U5      S9n[        U5      u  nn	n
nU H  nX;  d  M
  U
R                  U5        M     / nUR                  5        Hz  u  pX   nX;   a  XN   nOUnSR                  X   5      nUS:X  a  SnOSU-   n[        XU5      nUR                  SU S3UR!                  S5      R#                  5       -   U-   5        M|     UR%                  S S	9  U$ s  snf )
z
#.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   )r6   z ...r   z# Functional form of 'z'
z...c                 *    U R                  S5      S   $ )Nr   rV   )split)ss    r   <lambda>(get_method_definitions.<locals>.<lambda>  s    aggdmA&r   )key)strr   __file__parentresolve
isinstancer)   r*   r+   rB   unionrp   r[   itemsr   rZ   removesuffixrstripsort)rS   r6   r   r   r   r   r*   ri   rk   rl   methods_w_special_output_typesrn   fn_namemethod_definitionsrd   	argumentsre   output_type
doc_string
definitions                       r   get_method_definitionsr      s    rz4>((0023))S99yI6?@idd)iI@ $:$:;K$LJ 	Z(& 18*..w7 1 "8">">"@,9
87DK-KWW4AB
J
*J.{{S
!!$ZL4%%e,3356	
 #A" &   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                    ^^ [        [        [        [        S[        5      m[        [
        [        [        S[        5      m[        [        5      R                  5       R                  n [        X SS9nUR                  SSUU4S j5        g)	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                     > T TS.$ )N)IterDataPipeMethodsMapDataPipeMethodsr   )iter_method_definitionsmap_method_definitionss   r   r   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   ,  sz     5, 4+ >""$++D	%	HB	
r   __main__),)r   )r   N)4r)   collectionsr   pathlibr   typingr   typing_extensionsr   torchgen.api.pythonr   torchgen.utilsr   ImportErrorsysr   r   parents	REPO_ROOTr*   insertr   rH   r
   rX   __annotations__r   FutureWarningintr   tupler4   r9   rB   rN   rR   dictrh   rp   ry   r]   r   r   r   r   r   r   r   r   r   r   __name__r   r   r   <module>r      s   	 #   (=* 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T#Y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II