Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/tensorflow_addons/utils/ensure_tf_install.py: 77%

13 statements  

« prev     ^ index     » next       coverage.py v7.4.0, created at 2024-01-03 07:57 +0000

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 

16 

17# Ensure the TensorFlow version is in the right range. This 

18# needs to happen before anything else, since the imports below will try to 

19# import TensorFlow, too. 

20 

21from packaging.version import Version 

22import warnings 

23 

24import tensorflow as tf 

25 

26from tensorflow_addons.version import INCLUSIVE_MIN_TF_VERSION, EXCLUSIVE_MAX_TF_VERSION 

27 

28 

29def _check_tf_version(): 

30 """Warn the user if the version of TensorFlow used is not supported. 

31 

32 This is not a check for custom ops compatibility. This check only ensure that 

33 we support this TensorFlow version if the user uses only Addons' Python code. 

34 """ 

35 

36 if "dev" in tf.__version__: 

37 warnings.warn( 

38 "You are currently using a nightly version of TensorFlow ({}). \n" 

39 "TensorFlow Addons offers no support for the nightly versions of " 

40 "TensorFlow. Some things might work, some other might not. \n" 

41 "If you encounter a bug, do not file an issue on GitHub." 

42 "".format(tf.__version__), 

43 UserWarning, 

44 ) 

45 return 

46 

47 min_version = Version(INCLUSIVE_MIN_TF_VERSION) 

48 max_version = Version(EXCLUSIVE_MAX_TF_VERSION) 

49 

50 if min_version <= Version(tf.__version__) < max_version: 

51 return 

52 

53 warnings.warn( 

54 "Tensorflow Addons supports using Python ops for all Tensorflow versions " 

55 "above or equal to {} and strictly below {} (nightly versions are not " 

56 "supported). \n " 

57 "The versions of TensorFlow you are currently using is {} and is not " 

58 "supported. \n" 

59 "Some things might work, some things might not.\n" 

60 "If you were to encounter a bug, do not file an issue.\n" 

61 "If you want to make sure you're using a tested and supported configuration, " 

62 "either change the TensorFlow version or the TensorFlow Addons's version. \n" 

63 "You can find the compatibility matrix in TensorFlow Addon's readme:\n" 

64 "https://github.com/tensorflow/addons".format( 

65 INCLUSIVE_MIN_TF_VERSION, EXCLUSIVE_MAX_TF_VERSION, tf.__version__ 

66 ), 

67 UserWarning, 

68 )