
    BVh\                     r    d 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 dZdZd	Z	d
 Z
d Zedk(  r e        yy)zBUpgrader for Python scripts from 1.x TensorFlow to 2.0 TensorFlow.    N)	ast_edits)ipynb)tf_upgrade_v2)tf_upgrade_v2_safetyDEFAULTSAFETYFc                     | j                  d      r|j                  | |      \  }}}n8| j                  d      rt        j                  | ||      \  }}}nt        d      |||fS )z)Process a file of type `.py` or `.ipynb`.z.pyz.ipynbz1Currently converter only supports python or ipynb)endswithprocess_filer   NotImplementedError)in_filenameout_filenameupgraderfiles_processedreport_texterrorss         a/home/dcms/DCMS/lib/python3.12/site-packages/tensorflow/tools/compatibility/tf_upgrade_v2_main.pyr   r   #   sy     % K6 )O[&H%lH= )O[& ;= = 
+v	--    c            
      	   t        j                  t         j                  d      } | j                  ddd       | j                  ddd	       | j                  d
dd       | j                  ddd       | j                  dddt        d       | j                  dddd       | j                  dddd       | j                  dddd       | j                  d d!d"d#$       | j                  d%d&t
        t        gd't
        d(t        d)t
        *       | j                  d+d,d-d       | j                         }|j                  t        k(  rt        j                         }nU|j                  r#t        j                  d.|j                   /      }n&t        j                  t        |j                   /      }t        j                   |      }d }|j"                  }d0}|j$                  r|j&                  s|j(                  st+        d1      |j&                  r|j(                  rt+        d2      |j&                  r|j$                  n|j(                  }t-        |j$                  ||      \  }}}|j$                  |i}d3}n|j.                  r|j&                  s|j0                  st+        d4      |j&                  r|j0                  rt+        d5      |j&                  r|j.                  n|j0                  }	|j3                  |j.                  |	|j4                        \  }}}n| j7                          |r@d0}
g }D ]u  }||   s	|
t9        ||         z  }
|j;                  d6       |j;                  d7|z         |j;                  d6       |j;                  d8j=                  ||         d8z          w d9|z  d:|
z  z   d8z   d;z   d8z   d<j=                  |      z   }d=}|d>z  }|d=z  }t?        |d?      5 }|jA                  |       |jA                  |       |jA                  |       d d d        |jB                  r"tE        |       tE        |       tE        |       ntE        |       tE        d@|z         y y # 1 sw Y   RxY w)ANzConvert a TensorFlow Python file from 1.x to 2.0

Simple usage:
  tf_upgrade_v2.py --infile foo.py --outfile bar.py
  tf_upgrade_v2.py --infile foo.ipynb --outfile bar.ipynb
  tf_upgrade_v2.py --intree ~/code/old --outtree ~/code/new
)formatter_classdescriptionz--infile
input_filez<If converting a single file, the name of the file to convert)desthelpz	--outfileoutput_filez1If converting a single file, the output filename.z--intree
input_treezWIf converting a whole tree of files, the directory to read from (relative or absolute).z	--outtreeoutput_treezQIf converting a whole tree of files, the output directory (relative or absolute).z--copyotherfilescopy_other_fileszEIf converting a whole tree of files, whether to copy the other files.T)r   r   typedefaultz	--inplacein_placezaIf converting a set of files, whether to allow the conversion to be performed on the input files.
store_true)r   r   actionz--no_import_renameno_import_renamez-Not to rename import to compat.v2 explicitly.z--no_upgrade_compat_v1_importno_upgrade_compat_v1_importzIf specified, don't upgrade explicit imports of `tensorflow.compat.v1 as tf` to the v2 APIs. Otherwise, explicit imports of  the form `tensorflow.compat.v1 as tf` will be upgraded.z--reportfilereport_filenamezJThe name of the file where the report log is stored.(default: %(default)s)z
report.txt)r   r   r    z--modemodez&Upgrade script mode. Supported modes:
zp: Perform only straightforward conversions to upgrade to 2.0. In more difficult cases, switch to use compat.v1.
z3: Keep 1.* code intact and import compat.v1 module.)r   choicesr   r    z--print_all	print_allz8Print full log to stdout instead of just printing errorsF)import_renameupgrade_compat_v1_importr   zK--outfile=<output file> argument is required when converting a single file.z6--outfile argument is invalid when converting in place   zN--outtree=<output directory> argument is required when converting a file tree.z6--outtree argument is invalid when converting in placezQ--------------------------------------------------------------------------------
z	File: %s

zOTensorFlow 2.0 Upgrade Script
-----------------------------
Converted %d files
z)Detected %d issues that require attentionzP-------------------------------------------------------------------------------- zQ================================================================================
zDetailed log follows:

wz'
Make sure to read the detailed log %r
)#argparseArgumentParserRawDescriptionHelpFormatteradd_argumentbool_DEFAULT_MODE_SAFETY_MODE
parse_argsr'   r   TFAPIChangeSpecr$   r   r%   _IMPORT_RENAME_DEFAULTr   ASTCodeUpgraderr&   r   r!   r   
ValueErrorr   r   r   process_treer   
print_helplenappendjoinopenwriter)   print)parserargschange_specupgrader   r&   r   r   r   r   
num_errorsreportfdetailed_report_headerreport_files                  r   mainrM   3   s   ""::& 	  
 	>  @ 	-  .
 	*  +
 	$   	    	;	  
 	%(    	%    	l+ L*   
 	E	  
 
			$	YY,&668K!11'+'G'G#GIk "11.'+'G'G#GIk %%k2'+((//	__==!1!1  }}))OPP%)]]$//8H8HK+7g,/(O[&oov&FO==!1!1  }}))OPP%)]]$//8H8HK+2+?+?d&;&;,=(O[& JF 3	c&)n$
o&lQ&'o&diiq	*T123%'67 :JFG JNN 	 	 "$	1F
 -99o-	os	# %{./$%
 ~~Fm"#KFm	
5
GH? (% %s   14Q66Q?__main__)__doc__r0   tensorflow.tools.compatibilityr   r   r   r   r5   r6   r9   r   rM   __name__ r   r   <module>rS      sQ    I  4 0 8 ?    . XIt z& r   