[OVC] Removed not needed checks of extension parameter. (#22790)
### Details: moc_front_end.add_extension(extension) has checks of filepath existence and creation of absolute path from relative path logic. It is not needed to have this logic in convert_model(). ### Tickets: - 132251
This commit is contained in:
parent
7c22a4905b
commit
8372ca75bf
|
|
@ -251,22 +251,6 @@ class CanonicalizePathCheckExistenceAction(argparse.Action):
|
|||
setattr(namespace, self.dest, list_of_paths)
|
||||
|
||||
|
||||
def readable_file_or_object(path: str):
|
||||
"""
|
||||
Check that specified path is a readable file.
|
||||
:param path: path to check
|
||||
:return: path if the file is readable
|
||||
"""
|
||||
if not isinstance(path, (str, pathlib.Path)):
|
||||
return path
|
||||
if not os.path.isfile(path):
|
||||
raise Error('The "{}" is not existing file'.format(path))
|
||||
elif not os.access(path, os.R_OK):
|
||||
raise Error('The "{}" is not readable'.format(path))
|
||||
else:
|
||||
return path
|
||||
|
||||
|
||||
def readable_file_or_dir_or_object(path: str):
|
||||
"""
|
||||
Check that specified path is a readable file or directory.
|
||||
|
|
@ -298,20 +282,6 @@ def readable_dirs_or_files_or_empty(paths: [str, list, tuple]):
|
|||
return paths_list[0] if isinstance(paths, (list, tuple)) and len(paths_list) == 1 else paths_list
|
||||
|
||||
|
||||
def readable_files_or_empty(paths: [str, list, tuple]):
|
||||
"""
|
||||
Checks that comma separated list of paths are readable directories, files or a provided path is empty.
|
||||
:param paths: comma separated list of paths.
|
||||
:return: comma separated list of paths.
|
||||
"""
|
||||
if isinstance(paths, (list, tuple)):
|
||||
return [readable_file_or_object(path) for path in paths]
|
||||
if isinstance(paths, (str, pathlib.Path)):
|
||||
paths_list = [readable_file_or_object(path) for path in str(paths).split(',')]
|
||||
return paths_list
|
||||
return paths
|
||||
|
||||
|
||||
def add_args_by_description(args_group, params_description):
|
||||
signature = inspect.signature(openvino.tools.ovc.convert_model) # pylint: disable=no-member
|
||||
filepath_args = get_params_with_paths_list()
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ try:
|
|||
except ImportError:
|
||||
import openvino.tools.ovc.telemetry_stub as tm
|
||||
|
||||
from openvino.tools.ovc.moc_frontend.check_config import new_extensions_used
|
||||
from openvino.tools.ovc.moc_frontend.check_config import any_extensions_used
|
||||
from openvino.tools.ovc.moc_frontend.pipeline import moc_pipeline
|
||||
from openvino.tools.ovc.moc_frontend.moc_emit_ir import moc_emit_ir
|
||||
from openvino.tools.ovc.convert_data_type import destination_type_to_np_data_type
|
||||
|
|
@ -171,7 +171,7 @@ def prepare_ir(argv: argparse.Namespace):
|
|||
argv.share_weights)
|
||||
t.send_event("ovc", "conversion_method", moc_front_end.get_name() + "_frontend")
|
||||
moc_front_end.add_extension(TelemetryExtension("ovc", t.send_event, t.send_error, t.send_stack_trace))
|
||||
if new_extensions_used(argv):
|
||||
if any_extensions_used(argv):
|
||||
for extension in argv.extension:
|
||||
moc_front_end.add_extension(extension)
|
||||
ov_model = moc_pipeline(argv, moc_front_end)
|
||||
|
|
|
|||
|
|
@ -2,8 +2,7 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
def get_convert_model_help_specifics():
|
||||
from openvino.tools.ovc.cli_parser import CanonicalizePathCheckExistenceAction, readable_dirs_or_files_or_empty, \
|
||||
readable_files_or_empty
|
||||
from openvino.tools.ovc.cli_parser import CanonicalizePathCheckExistenceAction, readable_dirs_or_files_or_empty
|
||||
from openvino.tools.ovc.version import VersionChecker
|
||||
return {
|
||||
'input_model':
|
||||
|
|
@ -38,9 +37,7 @@ def get_convert_model_help_specifics():
|
|||
'extension':
|
||||
{'description':
|
||||
'Paths or a comma-separated list of paths to libraries '
|
||||
'(.so or .dll) with extensions.',
|
||||
'action': CanonicalizePathCheckExistenceAction,
|
||||
'type': readable_files_or_empty},
|
||||
'(.so or .dll) with extensions.'},
|
||||
'version':
|
||||
{'action': 'version',
|
||||
# FIXME: Why the following is not accessible from arg parser?
|
||||
|
|
|
|||
|
|
@ -38,48 +38,6 @@ def any_extensions_used(argv: argparse.Namespace):
|
|||
raise Exception("Expected list of extensions, got {}.".format(type(argv.extension)))
|
||||
|
||||
|
||||
def legacy_extensions_used(argv: argparse.Namespace):
|
||||
if any_extensions_used(argv):
|
||||
extensions = argv.extension
|
||||
legacy_ext_counter = 0
|
||||
for extension in extensions:
|
||||
if not isinstance(extension, str):
|
||||
continue
|
||||
if extension == default_path():
|
||||
continue
|
||||
if not Path(extension).is_file():
|
||||
legacy_ext_counter += 1
|
||||
if legacy_ext_counter == len(extensions):
|
||||
return True # provided only legacy extensions
|
||||
elif legacy_ext_counter == 0:
|
||||
return False # provided only new extensions
|
||||
else:
|
||||
raise Error('Using new and legacy extensions in the same time is forbidden')
|
||||
return False
|
||||
|
||||
|
||||
def new_extensions_used(argv: argparse.Namespace):
|
||||
if any_extensions_used(argv):
|
||||
extensions = argv.extension
|
||||
if not isinstance(extensions, (list, tuple)):
|
||||
extensions = [extensions]
|
||||
new_ext_counter = 0
|
||||
for extension in extensions:
|
||||
if isinstance(extension, str):
|
||||
path = Path(extension)
|
||||
if path.is_file() and (path.suffix == '.so' or path.suffix == '.dll'):
|
||||
new_ext_counter += 1
|
||||
else:
|
||||
new_ext_counter += 1
|
||||
if new_ext_counter == len(extensions):
|
||||
return True # provided only new extensions
|
||||
elif new_ext_counter == 0:
|
||||
return False # provided only legacy extensions
|
||||
else:
|
||||
raise Error('Using new and legacy extensions in the same time is forbidden')
|
||||
return False
|
||||
|
||||
|
||||
def get_transformations_config_path(argv: argparse.Namespace) -> Path:
|
||||
if hasattr(argv, 'transformations_config') \
|
||||
and argv.transformations_config is not None and len(argv.transformations_config):
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ from openvino.runtime import PartialShape
|
|||
|
||||
from openvino.tools.ovc.cli_parser import _InputCutInfo
|
||||
from openvino.tools.ovc.cli_parser import input_to_input_cut_info, \
|
||||
readable_file_or_object, get_all_cli_parser, get_mo_convert_params, parse_inputs, get_model_name_from_args
|
||||
get_all_cli_parser, get_mo_convert_params, parse_inputs, get_model_name_from_args
|
||||
from openvino.tools.ovc.convert_impl import pack_params_to_args_namespace, arguments_post_parsing, args_to_argv
|
||||
from openvino.tools.ovc.error import Error
|
||||
from unit_tests.ovc.unit_test_with_mocked_telemetry import UnitTestWithMockedTelemetry
|
||||
|
|
@ -341,13 +341,6 @@ class PathCheckerFunctions(unittest.TestCase):
|
|||
if os.path.exists(__class__.EXISTING_FILE):
|
||||
os.remove(__class__.EXISTING_FILE)
|
||||
|
||||
def test_readable_file(self):
|
||||
self.assertEqual(__class__.EXISTING_FILE, readable_file_or_object(__class__.EXISTING_FILE))
|
||||
|
||||
def test_non_readable_file(self):
|
||||
with self.assertRaises(Error) as cm:
|
||||
readable_file_or_object(__class__.NOT_EXISTING_FILE)
|
||||
|
||||
|
||||
class TestPackParamsToArgsNamespace(unittest.TestCase):
|
||||
def test_mo_convert_params(self):
|
||||
|
|
|
|||
Loading…
Reference in New Issue