Change app.py() to pass through unparsed flags.
This commit is contained in:
parent
ce3572a08b
commit
4f9a3a4def
@ -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(
|
cc_library(
|
||||||
name = "numpy_lib",
|
name = "numpy_lib",
|
||||||
srcs = ["lib/core/numpy.cc"],
|
srcs = ["lib/core/numpy.cc"],
|
||||||
|
@ -25,6 +25,6 @@ from tensorflow.python.platform import flags
|
|||||||
|
|
||||||
def run(main=None):
|
def run(main=None):
|
||||||
f = flags.FLAGS
|
f = flags.FLAGS
|
||||||
f._parse_flags()
|
flags_passthrough = f._parse_flags()
|
||||||
main = main or sys.modules['__main__'].main
|
main = main or sys.modules['__main__'].main
|
||||||
sys.exit(main(sys.argv))
|
sys.exit(main(sys.argv[:1] + flags_passthrough))
|
||||||
|
45
tensorflow/python/platform/app_test.py
Normal file
45
tensorflow/python/platform/app_test.py
Normal file
@ -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()
|
@ -30,10 +30,11 @@ class _FlagValues(object):
|
|||||||
self.__dict__['__parsed'] = False
|
self.__dict__['__parsed'] = False
|
||||||
|
|
||||||
def _parse_flags(self):
|
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():
|
for flag_name, val in vars(result).items():
|
||||||
self.__dict__['__flags'][flag_name] = val
|
self.__dict__['__flags'][flag_name] = val
|
||||||
self.__dict__['__parsed'] = True
|
self.__dict__['__parsed'] = True
|
||||||
|
return unparsed
|
||||||
|
|
||||||
def __getattr__(self, name):
|
def __getattr__(self, name):
|
||||||
"""Retrieves the 'value' attribute of the flag --name."""
|
"""Retrieves the 'value' attribute of the flag --name."""
|
||||||
|
Loading…
Reference in New Issue
Block a user