[MO] Fix showing graceful error message when no ngraph case (#6379)
* [MO] Fix showing graceful error message when no ngraph case
Move frontend-related imports inside appropriate functions
And use try/except if import fails to show graceful error message
* Revert "[MO] Fix showing graceful error message when no ngraph case"
This reverts commit 72d52bd946
.
* Print error before running of subprocess if IE or nGraph Python API is not found
* Added pytest to requirements_dev.txt
* Fixed review comment
This commit is contained in:
parent
dd2ea02d3a
commit
ae624ea18a
@ -1,20 +1,37 @@
|
||||
# Copyright (C) 2021 Intel Corporation
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import logging as log
|
||||
import os
|
||||
import sys
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
from mo.utils.versions_checker import check_python_version # pylint: disable=no-name-in-module
|
||||
|
||||
|
||||
def log_ie_not_found():
|
||||
log.error("Could not find the Inference Engine or nGraph Python API.\n"
|
||||
"Consider building the Inference Engine and nGraph Python APIs"
|
||||
" from sources or try to install OpenVINO (TM) Toolkit using \"install_prerequisites.{}\""
|
||||
.format("bat" if sys.platform == "windows" else "sh"))
|
||||
|
||||
|
||||
def setup_env():
|
||||
ret_code = check_python_version()
|
||||
if ret_code:
|
||||
sys.exit(ret_code)
|
||||
|
||||
from mo.utils.find_ie_version import find_ie_version
|
||||
find_ie_version(silent=True)
|
||||
|
||||
ie_found = True
|
||||
try:
|
||||
ie_found = find_ie_version(silent=True)
|
||||
except Exception:
|
||||
ie_found = False
|
||||
|
||||
if not ie_found:
|
||||
log_ie_not_found()
|
||||
sys.exit(1)
|
||||
|
||||
mo_root_path = os.path.join(os.path.dirname(__file__), os.pardir)
|
||||
|
||||
@ -23,6 +40,7 @@ def setup_env():
|
||||
os.environ[python_path_key] = mo_root_path
|
||||
else:
|
||||
os.environ[python_path_key] = os.pathsep.join([os.environ[python_path_key], mo_root_path])
|
||||
return True
|
||||
|
||||
|
||||
def subprocess_main(framework=None):
|
||||
@ -45,4 +63,4 @@ def subprocess_main(framework=None):
|
||||
for arg in sys.argv[1:]:
|
||||
args.append(arg)
|
||||
status = subprocess.run(args, env=os.environ)
|
||||
sys.exit(status.returncode)
|
||||
sys.exit(status.returncode)
|
||||
|
@ -5,3 +5,4 @@ pyenchant==1.6.11
|
||||
test-generator==0.1.1
|
||||
defusedxml>=0.5.0
|
||||
requests>=2.20.0
|
||||
pytest>=6.2.4
|
||||
|
@ -1,11 +1,29 @@
|
||||
# Copyright (C) 2018-2021 Intel Corporation
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import logging as log
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
from mo.subprocess_main import setup_env, subprocess_main
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
class TestNoInferenceEngine(unittest.TestCase):
|
||||
@patch('mo.utils.find_ie_version.find_ie_version')
|
||||
def test_no_ie_ngraph(self, mock_find):
|
||||
mock_find.return_value = False
|
||||
with pytest.raises(SystemExit) as e, self.assertLogs(log.getLogger(), level="ERROR") as cm:
|
||||
subprocess_main()
|
||||
assert e.value.code == 1
|
||||
res = [i for i in cm.output if
|
||||
'Consider building the Inference Engine and nGraph Python APIs from sources' in i]
|
||||
assert res
|
||||
|
||||
from mo.subprocess_main import setup_env
|
||||
|
||||
def test_frontends():
|
||||
setup_env()
|
||||
|
Loading…
Reference in New Issue
Block a user