1# Copyright 2019 The TensorFlow Authors. All Rights Reserved. 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14# ============================================================================== 15"""Upgrader for Python scripts from 1.* to 2.0 TensorFlow using SAFETY mode.""" 16 17from __future__ import absolute_import 18from __future__ import division 19from __future__ import print_function 20 21from tensorflow.tools.compatibility import all_renames_v2 22from tensorflow.tools.compatibility import ast_edits 23from tensorflow.tools.compatibility import module_deprecations_v2 24 25 26class TFAPIChangeSpec(ast_edits.APIChangeSpec): 27 """List of maps that describe what changed in the API.""" 28 29 def __init__(self): 30 self.function_keyword_renames = {} 31 self.symbol_renames = {} 32 self.change_to_function = {} 33 self.function_reorders = {} 34 self.function_warnings = {} 35 self.function_transformers = {} 36 self.module_deprecations = module_deprecations_v2.MODULE_DEPRECATIONS 37 38 ## Inform about the addons mappings 39 for symbol, replacement in all_renames_v2.addons_symbol_mappings.items(): 40 warning = ( 41 ast_edits.WARNING, ( 42 "(Manual edit required) `{}` has been migrated to `{}` in " 43 "TensorFlow Addons. The API spec may have changed during the " 44 "migration. Please see https://github.com/tensorflow/addons " 45 "for more info.").format(symbol, replacement)) 46 self.function_warnings[symbol] = warning 47 48 # List module renames. If changed, please update max_submodule_depth. 49 self.import_renames = { 50 "tensorflow": 51 ast_edits.ImportRename( 52 "tensorflow.compat.v1", 53 excluded_prefixes=[ 54 "tensorflow.contrib", "tensorflow.flags", 55 "tensorflow.compat", 56 "tensorflow.compat.v1", "tensorflow.compat.v2", 57 "tensorflow.google" 58 ], 59 ) 60 } 61 # Needs to be updated if self.import_renames is changed. 62 self.max_submodule_depth = 2 63