1# Lint as: python3 2# Copyright 2018 The TensorFlow Authors. All Rights Reserved. 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15# ============================================================================== 16"""Opensource base_dir configuration for tensorflow doc-generator.""" 17from __future__ import absolute_import 18from __future__ import division 19from __future__ import print_function 20 21import distutils 22from os import path 23 24import keras_preprocessing 25import tensorboard 26import tensorflow as tf 27import tensorflow_estimator 28 29try: 30 import keras # pylint: disable=g-import-not-at-top 31except ImportError: 32 pass 33 34 35def get_base_dirs_and_prefixes(code_url_prefix): 36 """Returns the base_dirs and code_prefixes for OSS TensorFlow api gen.""" 37 base_dir = path.dirname(tf.__file__) 38 39 if distutils.version.LooseVersion(tf.__version__) >= "2.6": 40 base_dirs = [ 41 base_dir, 42 path.dirname(keras.__file__), 43 path.dirname(keras_preprocessing.__file__), 44 path.dirname(tensorboard.__file__), 45 path.dirname(tensorflow_estimator.__file__), 46 ] 47 elif distutils.version.LooseVersion(tf.__version__) >= "2.2": 48 base_dirs = [ 49 base_dir, 50 path.dirname(keras_preprocessing.__file__), 51 path.dirname(tensorboard.__file__), 52 path.dirname(tensorflow_estimator.__file__), 53 ] 54 else: 55 base_dirs = [ 56 path.normpath(path.join(base_dir, "../tensorflow_core")), 57 path.dirname(keras_preprocessing.__file__), 58 path.dirname(tensorboard.__file__), 59 path.dirname(tensorflow_estimator.__file__), 60 ] 61 62 if distutils.version.LooseVersion(tf.__version__) >= "2.6": 63 code_url_prefixes = ( 64 code_url_prefix, 65 "https://github.com/keras-team/keras/tree/master/keras", 66 "https://github.com/keras-team/keras-preprocessing/tree/master/keras_preprocessing", 67 "https://github.com/tensorflow/tensorboard/tree/master/tensorboard", 68 "https://github.com/tensorflow/estimator/tree/master/tensorflow_estimator", 69 ) 70 else: 71 code_url_prefixes = ( 72 code_url_prefix, 73 "https://github.com/keras-team/keras-preprocessing/tree/master/keras_preprocessing", 74 "https://github.com/tensorflow/tensorboard/tree/master/tensorboard", 75 "https://github.com/tensorflow/estimator/tree/master/tensorflow_estimator", 76 ) 77 78 return base_dirs, code_url_prefixes 79