Welcome to mirror list, hosted at ThFree Co, Russian Federation.

addon_auto_imports.py « utils « power_sequencer - git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 47f430b90fce7c19a99f2a2a864d480a44932a71 (plain)
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# SPDX-License-Identifier: GPL-3.0-or-later
# Copyright 2016-2020 by Nathan Lovato, Daniel Oakey, Razvan Radulescu, and contributors

# This file is part of Power Sequencer.

import pkgutil
import importlib

reload_event = False


def setup_addon_modules(path, package_name, ignore_packages=[], ignore_modules=[]):
    """
    Imports and reloads all modules in this addon.

    path -- __path__ from __init__.py
    package_name -- __name__ from __init__.py
    ignore_packages -- list of packages to ignore,
    skips the package if the string is in the name
    ignore_modules -- list of module_names to ignore, strings
    skips the module if the string is in the name
    """

    def get_submodule_names(path=path[0], root=""):
        module_names = []
        for ignore in ignore_packages:
            if ignore in root:
                return []
        for importer, module_name, is_package in pkgutil.iter_modules([path]):
            skip_module = False
            for ignore in ignore_modules:
                if ignore in module_name:
                    skip_module = True
            if skip_module:
                continue
            if is_package:
                sub_path = path + "\\" + module_name
                sub_root = root + module_name + "."
                module_names.extend(get_submodule_names(sub_path, sub_root))
            else:
                module_names.append(root + module_name)
        return module_names

    def import_submodules(names):
        modules = []
        for name in names:
            modules.append(importlib.import_module("." + name, package_name))
        return modules

    def reload_modules(modules):
        for module in modules:
            importlib.reload(module)

    names = get_submodule_names()
    modules = import_submodules(names)
    if reload_event:
        reload_modules(modules)
    return modules


reload_event = True