aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/python/platform/flags.py
diff options
context:
space:
mode:
Diffstat (limited to 'tensorflow/python/platform/flags.py')
-rw-r--r--tensorflow/python/platform/flags.py48
1 files changed, 48 insertions, 0 deletions
diff --git a/tensorflow/python/platform/flags.py b/tensorflow/python/platform/flags.py
index e9a36ae75d..abd6f3d855 100644
--- a/tensorflow/python/platform/flags.py
+++ b/tensorflow/python/platform/flags.py
@@ -18,5 +18,53 @@ from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
+import logging as _logging
+
# go/tf-wildcard-import
from absl.flags import * # pylint: disable=wildcard-import
+import six as _six
+
+from tensorflow.python.util import tf_decorator
+
+
+# Since we wrap absl.flags DEFINE functions, we need to declare this module
+# does not affect key flags.
+disclaim_key_flags() # pylint: disable=undefined-variable
+
+
+_RENAMED_ARGUMENTS = {
+ 'flag_name': 'name',
+ 'default_value': 'default',
+ 'docstring': 'help',
+}
+
+
+def _wrap_define_function(original_function):
+ """Wraps absl.flags's define functions so tf.flags accepts old names."""
+
+ def wrapper(*args, **kwargs):
+ """Wrapper function that turns old keyword names to new ones."""
+ has_old_names = False
+ for old_name, new_name in _six.iteritems(_RENAMED_ARGUMENTS):
+ if old_name in kwargs:
+ has_old_names = True
+ value = kwargs.pop(old_name)
+ kwargs[new_name] = value
+ if has_old_names:
+ _logging.warning(
+ 'Use of the keyword argument names (flag_name, default_value, '
+ 'docstring) is deprecated, please use (name, default, help) instead.')
+ return original_function(*args, **kwargs)
+
+ return tf_decorator.make_decorator(original_function, wrapper)
+
+
+# pylint: disable=invalid-name,used-before-assignment
+# absl.flags APIs use `default` as the name of the default value argument.
+# Allow the following functions continue to accept `default_value`.
+DEFINE_string = _wrap_define_function(DEFINE_string)
+DEFINE_boolean = _wrap_define_function(DEFINE_boolean)
+DEFINE_bool = DEFINE_boolean
+DEFINE_float = _wrap_define_function(DEFINE_float)
+DEFINE_integer = _wrap_define_function(DEFINE_integer)
+# pylint: enable=invalid-name,used-before-assignment