diff --git a/tensorflow/python/BUILD b/tensorflow/python/BUILD index 21825e1bc23..5fec88726f5 100644 --- a/tensorflow/python/BUILD +++ b/tensorflow/python/BUILD @@ -71,6 +71,26 @@ tf_py_test( ], ) +tf_py_test( + name = "flags_test", + size = "small", + srcs = ["platform/flags_test.py"], + additional_deps = [ + ":platform", + ":platform_test", + ], +) + +tf_py_test( + name = "app_test", + size = "small", + srcs = ["platform/app_test.py"], + additional_deps = [ + ":platform", + ":platform_test", + ], +) + cc_library( name = "numpy_lib", srcs = ["lib/core/numpy.cc"], diff --git a/tensorflow/python/platform/app.py b/tensorflow/python/platform/app.py index ebca21e075a..7419d844ffd 100644 --- a/tensorflow/python/platform/app.py +++ b/tensorflow/python/platform/app.py @@ -25,6 +25,6 @@ from tensorflow.python.platform import flags def run(main=None): f = flags.FLAGS - f._parse_flags() + flags_passthrough = f._parse_flags() main = main or sys.modules['__main__'].main - sys.exit(main(sys.argv)) + sys.exit(main(sys.argv[:1] + flags_passthrough)) diff --git a/tensorflow/python/platform/app_test.py b/tensorflow/python/platform/app_test.py new file mode 100644 index 00000000000..b7a58dd9fb4 --- /dev/null +++ b/tensorflow/python/platform/app_test.py @@ -0,0 +1,45 @@ +# Copyright 2015 The TensorFlow Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# ============================================================================== + +"""Tests for our flags implementation.""" +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +import sys + +from tensorflow.python.platform import app +from tensorflow.python.platform import flags + +FLAGS = flags.FLAGS +flags.DEFINE_boolean('myflag', False, '') + +def main(argv): + if (len(argv) != 3): + print("Length of argv was not 3: ", argv) + sys.exit(-1) + + if argv[1] != "--passthrough": + print("--passthrough argument not in argv") + sys.exit(-1) + + if argv[2] != "extra": + print("'extra' argument not in argv") + sys.exit(-1) + + +if __name__ == '__main__': + sys.argv.extend(["--myflag", "--passthrough", "extra"]) + app.run() diff --git a/tensorflow/python/platform/flags.py b/tensorflow/python/platform/flags.py index 85f9e2cb860..645f8acecb0 100644 --- a/tensorflow/python/platform/flags.py +++ b/tensorflow/python/platform/flags.py @@ -30,10 +30,11 @@ class _FlagValues(object): self.__dict__['__parsed'] = False def _parse_flags(self): - result, _ = _global_parser.parse_known_args() + result, unparsed = _global_parser.parse_known_args() for flag_name, val in vars(result).items(): self.__dict__['__flags'][flag_name] = val self.__dict__['__parsed'] = True + return unparsed def __getattr__(self, name): """Retrieves the 'value' attribute of the flag --name."""