common.py 440 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#  SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
#  SPDX-License-Identifier: Apache-2.0

import importlib


def check_module_available(module_name: str) -> bool:
    """For tests / pre-commit"""
    if importlib.util.find_spec(module_name) is None:
        return False
    try:
        importlib.import_module(module_name)
        return True
    except ImportError:
        return False