aboutsummaryrefslogtreecommitdiffstats
path: root/build/plugins/lib/nots/package_manager/base/timeit.py
blob: c0b25daee4df807feb4ff05547cbba86c5312b32 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import importlib


def import_optional_module(module_name):
    # Initialize the cache attribute if it does not exist
    if not hasattr(import_optional_module, 'cache'):
        import_optional_module.cache = {}

    # Check if the module is already in the cache
    if module_name in import_optional_module.cache:
        return import_optional_module.cache[module_name]

    # Attempt to import the module
    try:
        module = importlib.import_module(module_name)
    except ImportError:
        module = None

    # Cache the result
    import_optional_module.cache[module_name] = module
    return module


def timeit(func):
    logging = import_optional_module("devtools.frontend_build_platform.libraries.logging")
    if logging:
        return logging.timeit(func)
    else:
        return func