cengal.modules_management.alternative_import.versions.v_0.alternative_import

 1#!/usr/bin/env python
 2# coding=utf-8
 3
 4# Copyright © 2012-2024 ButenkoMS. All rights reserved. Contacts: <gtalk@butenkoms.space>
 5# 
 6# Licensed under the Apache License, Version 2.0 (the "License");
 7# you may not use this file except in compliance with the License.
 8# You may obtain a copy of the License at
 9# 
10#     http://www.apache.org/licenses/LICENSE-2.0
11# 
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17
18from importlib import import_module
19from contextlib import contextmanager
20
21"""
22Module Docstring
23Docstrings: http://www.python.org/dev/peps/pep-0257/
24"""
25
26__author__ = "ButenkoMS <gtalk@butenkoms.space>"
27__copyright__ = "Copyright © 2012-2024 ButenkoMS. All rights reserved. Contacts: <gtalk@butenkoms.space>"
28__credits__ = ["ButenkoMS <gtalk@butenkoms.space>", ]
29__license__ = "Apache License, Version 2.0"
30__version__ = "4.4.1"
31__maintainer__ = "ButenkoMS <gtalk@butenkoms.space>"
32__email__ = "gtalk@butenkoms.space"
33# __status__ = "Prototype"
34__status__ = "Development"
35# __status__ = "Production"
36
37
38@contextmanager
39def alt_import(module_name, package=None):
40    module = None
41    try:
42        module = import_module(module_name, package)
43    except ImportError:
44        pass
45
46    try:
47        yield module
48    except ImportError as ex:
49        print('IMPORT ERROR: {}'.format(str(ex)))
@contextmanager
def alt_import(module_name, package=None):
39@contextmanager
40def alt_import(module_name, package=None):
41    module = None
42    try:
43        module = import_module(module_name, package)
44    except ImportError:
45        pass
46
47    try:
48        yield module
49    except ImportError as ex:
50        print('IMPORT ERROR: {}'.format(str(ex)))