2 ''''export SCRIPT_PATH="$(cd "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")" && pwd)" # '''
3 ''''export PY_PATH=${SCRIPT_PATH}/venv/bin/python # '''
4 ''''test -f ${PY_PATH} && exec ${PY_PATH} "$0" "$@" # '''
5 ''''echo "Error: Virtual environment not found. Please run 'one-prepare-venv' command." # '''
8 # Copyright (c) 2020 Samsung Electronics Co., Ltd. All Rights Reserved
10 # Licensed under the Apache License, Version 2.0 (the "License");
11 # you may not use this file except in compliance with the License.
12 # You may obtain a copy of the License at
14 # http://www.apache.org/licenses/LICENSE-2.0
16 # Unless required by applicable law or agreed to in writing, software
17 # distributed under the License is distributed on an "AS IS" BASIS,
18 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 # See the License for the specific language governing permissions and
20 # limitations under the License.
28 import utils as _utils
30 # TODO Find better way to suppress trackback on error
31 # This suppression is applied only to `one-build`
32 sys.tracebacklimit = 0
36 parser = argparse.ArgumentParser(
37 description='command line tool to run ONE drivers in customized order')
39 _utils._add_default_arg(parser)
44 def _parse_arg(parser):
45 args = parser.parse_args()
48 _utils._print_version_and_exit(__file__)
53 def _verify_arg(parser, args):
54 """verify given arguments"""
55 # check if required arguments is given
56 if not _utils._is_valid_attr(args, 'config'):
57 parser.error('-C/--config argument is required')
60 def _get_driver_name(driver_name):
62 'one-import-bcq': 'one-import-bcq',
63 'one-import-tf': 'one-import-tf',
64 'one-import-tflite': 'one-import-tflite',
65 'one-import-onnx': 'one-import-onnx',
66 'one-optimize': 'one-optimize',
67 'one-quantize': 'one-quantize',
68 'one-pack': 'one-pack',
69 'one-codegen': 'one-codegen'
74 config = configparser.ConfigParser()
75 config.optionxform = str
76 parsed = config.read(os.path.expanduser(getattr(args, 'config')))
78 raise FileNotFoundError('Not found given configuration file')
82 def _is_available_driver(config, driver_name):
83 return config.has_option('one-build', driver_name) and config.getboolean(
84 'one-build', driver_name)
87 def _verify_cfg(driver_list, config):
88 if not config.has_section('one-build'):
89 raise ImportError('[one-build] section is required in configuraion file')
92 if _is_available_driver(config, 'one-import-tf'):
93 import_driver_cnt += 1
94 if _is_available_driver(config, 'one-import-tflite'):
95 import_driver_cnt += 1
96 if _is_available_driver(config, 'one-import-bcq'):
97 import_driver_cnt += 1
98 if _is_available_driver(config, 'one-import-onnx'):
99 import_driver_cnt += 1
100 if import_driver_cnt > 1:
101 raise AssertionError('Only one import-* driver can be executed')
106 # since the configuration file path is required first,
107 # parsing of the configuration file proceeds after this.
108 parser = _get_parser()
109 args = _parse_arg(parser)
112 _verify_arg(parser, args)
114 # parse configuration file
115 config = _parse_cfg(args)
117 # verify configuration file
119 'one-import-tf', 'one-import-tflite', 'one-import-bcq', 'one-import-onnx',
120 'one-optimize', 'one-quantize', 'one-pack', 'one-codegen'
122 _verify_cfg(drivers, config)
124 # get sections to run
127 if _is_available_driver(config, d):
128 section_to_run.append(d)
131 dir_path = os.path.dirname(os.path.realpath(__file__))
132 for section in section_to_run:
133 driver_path = os.path.join(dir_path, _get_driver_name(section))
134 cmd = [driver_path, '--config', getattr(args, 'config'), '--section', section]
138 if __name__ == '__main__':
139 _utils._safemain(main, __file__)